Skip to content

Commit 3a06ec0

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: Allow WEAK and GLOBAL bindings during BTF fixup
During BTF fix up for global variables, global variable can be global weak and will have STB_WEAK binding in ELF. Support such global variables in addition to non-weak ones. This is not the problem when using BPF static linking, as BPF static linker "fixes up" BTF during generation so that libbpf doesn't have to do it anymore during bpf_object__open(), which led to this not being noticed for a while, along with a pretty rare (currently) use of __weak variables and maps. Reported-by: Hengqi Chen <hengqi.chen@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220407230446.3980075-2-andrii@kernel.org
1 parent 3c0dfe6 commit 3a06ec0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,11 @@ static int find_elf_var_offset(const struct bpf_object *obj, const char *name, _
14011401
for (si = 0; si < symbols->d_size / sizeof(Elf64_Sym); si++) {
14021402
Elf64_Sym *sym = elf_sym_by_idx(obj, si);
14031403

1404-
if (ELF64_ST_BIND(sym->st_info) != STB_GLOBAL ||
1405-
ELF64_ST_TYPE(sym->st_info) != STT_OBJECT)
1404+
if (ELF64_ST_TYPE(sym->st_info) != STT_OBJECT)
1405+
continue;
1406+
1407+
if (ELF64_ST_BIND(sym->st_info) != STB_GLOBAL &&
1408+
ELF64_ST_BIND(sym->st_info) != STB_WEAK)
14061409
continue;
14071410

14081411
sname = elf_sym_str(obj, sym->st_name);

0 commit comments

Comments
 (0)