aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorJesper Dangaard Brouer <brouer@redhat.com>2018-02-08 06:48:17 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-02-08 18:24:38 -0500
commit077c066a6c5445423147496e6c9b9a2c2d2ee762 (patch)
tree9e1fbf72eea030e467249b7d4ff385b8bf476f2c /tools/lib/bpf
parent8c88181ed452707f3815827225517b1964463b95 (diff)
tools/libbpf: improve the pr_debug statements to contain section numbers
While debugging a bpf ELF loading issue, I needed to correlate the ELF section number with the failed relocation section reference. Thus, add section numbers/index to the pr_debug. In debug mode, also print section that were skipped. This helped me identify that a section (.eh_frame) was skipped, and this was the reason the relocation section (.rel.eh_frame) could not find that section number. The section numbers corresponds to the readelf tools Section Headers [Nr]. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/libbpf.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index c64840365433..0c794f7fc050 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -319,8 +319,8 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx,
319 319
320 prog->section_name = strdup(section_name); 320 prog->section_name = strdup(section_name);
321 if (!prog->section_name) { 321 if (!prog->section_name) {
322 pr_warning("failed to alloc name for prog under section %s\n", 322 pr_warning("failed to alloc name for prog under section(%d) %s\n",
323 section_name); 323 idx, section_name);
324 goto errout; 324 goto errout;
325 } 325 }
326 326
@@ -763,29 +763,29 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
763 763
764 idx++; 764 idx++;
765 if (gelf_getshdr(scn, &sh) != &sh) { 765 if (gelf_getshdr(scn, &sh) != &sh) {
766 pr_warning("failed to get section header from %s\n", 766 pr_warning("failed to get section(%d) header from %s\n",
767 obj->path); 767 idx, obj->path);
768 err = -LIBBPF_ERRNO__FORMAT; 768 err = -LIBBPF_ERRNO__FORMAT;
769 goto out; 769 goto out;
770 } 770 }
771 771
772 name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name); 772 name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name);
773 if (!name) { 773 if (!name) {
774 pr_warning("failed to get section name from %s\n", 774 pr_warning("failed to get section(%d) name from %s\n",
775 obj->path); 775 idx, obj->path);
776 err = -LIBBPF_ERRNO__FORMAT; 776 err = -LIBBPF_ERRNO__FORMAT;
777 goto out; 777 goto out;
778 } 778 }
779 779
780 data = elf_getdata(scn, 0); 780 data = elf_getdata(scn, 0);
781 if (!data) { 781 if (!data) {
782 pr_warning("failed to get section data from %s(%s)\n", 782 pr_warning("failed to get section(%d) data from %s(%s)\n",
783 name, obj->path); 783 idx, name, obj->path);
784 err = -LIBBPF_ERRNO__FORMAT; 784 err = -LIBBPF_ERRNO__FORMAT;
785 goto out; 785 goto out;
786 } 786 }
787 pr_debug("section %s, size %ld, link %d, flags %lx, type=%d\n", 787 pr_debug("section(%d) %s, size %ld, link %d, flags %lx, type=%d\n",
788 name, (unsigned long)data->d_size, 788 idx, name, (unsigned long)data->d_size,
789 (int)sh.sh_link, (unsigned long)sh.sh_flags, 789 (int)sh.sh_link, (unsigned long)sh.sh_flags,
790 (int)sh.sh_type); 790 (int)sh.sh_type);
791 791
@@ -840,6 +840,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
840 obj->efile.reloc[n].shdr = sh; 840 obj->efile.reloc[n].shdr = sh;
841 obj->efile.reloc[n].data = data; 841 obj->efile.reloc[n].data = data;
842 } 842 }
843 } else {
844 pr_debug("skip section(%d) %s\n", idx, name);
843 } 845 }
844 if (err) 846 if (err)
845 goto out; 847 goto out;
@@ -1119,8 +1121,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
1119 1121
1120 prog = bpf_object__find_prog_by_idx(obj, idx); 1122 prog = bpf_object__find_prog_by_idx(obj, idx);
1121 if (!prog) { 1123 if (!prog) {
1122 pr_warning("relocation failed: no %d section\n", 1124 pr_warning("relocation failed: no section(%d)\n", idx);
1123 idx);
1124 return -LIBBPF_ERRNO__RELOC; 1125 return -LIBBPF_ERRNO__RELOC;
1125 } 1126 }
1126 1127