aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 176cf5523728..bd71efcc53be 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -562,8 +562,9 @@ static int compare_bpf_map(const void *_a, const void *_b)
562} 562}
563 563
564static int 564static int
565bpf_object__init_maps(struct bpf_object *obj) 565bpf_object__init_maps(struct bpf_object *obj, int flags)
566{ 566{
567 bool strict = !(flags & MAPS_RELAX_COMPAT);
567 int i, map_idx, map_def_sz, nr_maps = 0; 568 int i, map_idx, map_def_sz, nr_maps = 0;
568 Elf_Scn *scn; 569 Elf_Scn *scn;
569 Elf_Data *data; 570 Elf_Data *data;
@@ -685,7 +686,8 @@ bpf_object__init_maps(struct bpf_object *obj)
685 "has unrecognized, non-zero " 686 "has unrecognized, non-zero "
686 "options\n", 687 "options\n",
687 obj->path, map_name); 688 obj->path, map_name);
688 return -EINVAL; 689 if (strict)
690 return -EINVAL;
689 } 691 }
690 } 692 }
691 memcpy(&obj->maps[map_idx].def, def, 693 memcpy(&obj->maps[map_idx].def, def,
@@ -716,7 +718,7 @@ static bool section_have_execinstr(struct bpf_object *obj, int idx)
716 return false; 718 return false;
717} 719}
718 720
719static int bpf_object__elf_collect(struct bpf_object *obj) 721static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
720{ 722{
721 Elf *elf = obj->efile.elf; 723 Elf *elf = obj->efile.elf;
722 GElf_Ehdr *ep = &obj->efile.ehdr; 724 GElf_Ehdr *ep = &obj->efile.ehdr;
@@ -843,7 +845,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
843 return LIBBPF_ERRNO__FORMAT; 845 return LIBBPF_ERRNO__FORMAT;
844 } 846 }
845 if (obj->efile.maps_shndx >= 0) { 847 if (obj->efile.maps_shndx >= 0) {
846 err = bpf_object__init_maps(obj); 848 err = bpf_object__init_maps(obj, flags);
847 if (err) 849 if (err)
848 goto out; 850 goto out;
849 } 851 }
@@ -1515,7 +1517,7 @@ static int bpf_object__validate(struct bpf_object *obj, bool needs_kver)
1515 1517
1516static struct bpf_object * 1518static struct bpf_object *
1517__bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz, 1519__bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz,
1518 bool needs_kver) 1520 bool needs_kver, int flags)
1519{ 1521{
1520 struct bpf_object *obj; 1522 struct bpf_object *obj;
1521 int err; 1523 int err;
@@ -1531,7 +1533,7 @@ __bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz,
1531 1533
1532 CHECK_ERR(bpf_object__elf_init(obj), err, out); 1534 CHECK_ERR(bpf_object__elf_init(obj), err, out);
1533 CHECK_ERR(bpf_object__check_endianness(obj), err, out); 1535 CHECK_ERR(bpf_object__check_endianness(obj), err, out);
1534 CHECK_ERR(bpf_object__elf_collect(obj), err, out); 1536 CHECK_ERR(bpf_object__elf_collect(obj, flags), err, out);
1535 CHECK_ERR(bpf_object__collect_reloc(obj), err, out); 1537 CHECK_ERR(bpf_object__collect_reloc(obj), err, out);
1536 CHECK_ERR(bpf_object__validate(obj, needs_kver), err, out); 1538 CHECK_ERR(bpf_object__validate(obj, needs_kver), err, out);
1537 1539
@@ -1542,7 +1544,8 @@ out:
1542 return ERR_PTR(err); 1544 return ERR_PTR(err);
1543} 1545}
1544 1546
1545struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr) 1547struct bpf_object *__bpf_object__open_xattr(struct bpf_object_open_attr *attr,
1548 int flags)
1546{ 1549{
1547 /* param validation */ 1550 /* param validation */
1548 if (!attr->file) 1551 if (!attr->file)
@@ -1551,7 +1554,13 @@ struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr)
1551 pr_debug("loading %s\n", attr->file); 1554 pr_debug("loading %s\n", attr->file);
1552 1555
1553 return __bpf_object__open(attr->file, NULL, 0, 1556 return __bpf_object__open(attr->file, NULL, 0,
1554 bpf_prog_type__needs_kver(attr->prog_type)); 1557 bpf_prog_type__needs_kver(attr->prog_type),
1558 flags);
1559}
1560
1561struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr)
1562{
1563 return __bpf_object__open_xattr(attr, 0);
1555} 1564}
1556 1565
1557struct bpf_object *bpf_object__open(const char *path) 1566struct bpf_object *bpf_object__open(const char *path)
@@ -1584,7 +1593,7 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
1584 pr_debug("loading object '%s' from buffer\n", 1593 pr_debug("loading object '%s' from buffer\n",
1585 name); 1594 name);
1586 1595
1587 return __bpf_object__open(name, obj_buf, obj_buf_sz, true); 1596 return __bpf_object__open(name, obj_buf, obj_buf_sz, true, true);
1588} 1597}
1589 1598
1590int bpf_object__unload(struct bpf_object *obj) 1599int bpf_object__unload(struct bpf_object *obj)