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.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 102156f322b6..e8088f8214d1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -110,6 +110,11 @@ struct bpf_object {
110 Elf *elf; 110 Elf *elf;
111 GElf_Ehdr ehdr; 111 GElf_Ehdr ehdr;
112 Elf_Data *symbols; 112 Elf_Data *symbols;
113 struct {
114 GElf_Shdr shdr;
115 Elf_Data *data;
116 } *reloc;
117 int nr_reloc;
113 } efile; 118 } efile;
114 char path[]; 119 char path[];
115}; 120};
@@ -231,6 +236,9 @@ static void bpf_object__elf_finish(struct bpf_object *obj)
231 obj->efile.elf = NULL; 236 obj->efile.elf = NULL;
232 } 237 }
233 obj->efile.symbols = NULL; 238 obj->efile.symbols = NULL;
239
240 zfree(&obj->efile.reloc);
241 obj->efile.nr_reloc = 0;
234 zclose(obj->efile.fd); 242 zclose(obj->efile.fd);
235 obj->efile.obj_buf = NULL; 243 obj->efile.obj_buf = NULL;
236 obj->efile.obj_buf_sz = 0; 244 obj->efile.obj_buf_sz = 0;
@@ -447,6 +455,24 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
447 pr_warning("failed to alloc program %s (%s): %s", 455 pr_warning("failed to alloc program %s (%s): %s",
448 name, obj->path, errmsg); 456 name, obj->path, errmsg);
449 } 457 }
458 } else if (sh.sh_type == SHT_REL) {
459 void *reloc = obj->efile.reloc;
460 int nr_reloc = obj->efile.nr_reloc + 1;
461
462 reloc = realloc(reloc,
463 sizeof(*obj->efile.reloc) * nr_reloc);
464 if (!reloc) {
465 pr_warning("realloc failed\n");
466 err = -ENOMEM;
467 } else {
468 int n = nr_reloc - 1;
469
470 obj->efile.reloc = reloc;
471 obj->efile.nr_reloc = nr_reloc;
472
473 obj->efile.reloc[n].shdr = sh;
474 obj->efile.reloc[n].data = data;
475 }
450 } 476 }
451 if (err) 477 if (err)
452 goto out; 478 goto out;