Skip to content

Commit f2a3e4e

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: provide more helpful message on uninitialized global var
When BPF program defines uninitialized global variable, it's put into a special COMMON section. Libbpf will reject such programs, but will provide very unhelpful message with garbage-looking section index. This patch detects special section cases and gives more explicit error message. Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Song Liu <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3e3bb69 commit f2a3e4e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,15 +1760,22 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
17601760
(long long) sym.st_value, sym.st_name, name);
17611761

17621762
shdr_idx = sym.st_shndx;
1763+
insn_idx = rel.r_offset / sizeof(struct bpf_insn);
1764+
pr_debug("relocation: insn_idx=%u, shdr_idx=%u\n",
1765+
insn_idx, shdr_idx);
1766+
1767+
if (shdr_idx >= SHN_LORESERVE) {
1768+
pr_warning("relocation: not yet supported relo for non-static global \'%s\' variable in special section (0x%x) found in insns[%d].code 0x%x\n",
1769+
name, shdr_idx, insn_idx,
1770+
insns[insn_idx].code);
1771+
return -LIBBPF_ERRNO__RELOC;
1772+
}
17631773
if (!bpf_object__relo_in_known_section(obj, shdr_idx)) {
17641774
pr_warning("Program '%s' contains unrecognized relo data pointing to section %u\n",
17651775
prog->section_name, shdr_idx);
17661776
return -LIBBPF_ERRNO__RELOC;
17671777
}
17681778

1769-
insn_idx = rel.r_offset / sizeof(struct bpf_insn);
1770-
pr_debug("relocation: insn_idx=%u\n", insn_idx);
1771-
17721779
if (insns[insn_idx].code == (BPF_JMP | BPF_CALL)) {
17731780
if (insns[insn_idx].src_reg != BPF_PSEUDO_CALL) {
17741781
pr_warning("incorrect bpf_call opcode\n");

0 commit comments

Comments
 (0)