libbpf: Avoid joining .BTF.ext data with BPF programs by section name
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 26 Apr 2022 00:45:05 +0000 (17:45 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 26 Apr 2022 22:41:46 +0000 (15:41 -0700)
commit11d5daa89254ba2233d422777d52dbf24666b280
tree6638f5f9c8ebb217f2e207e7b1a8bebced80afd5
parent966a7509325395c51c5f6d89e7352b0585e4804b
libbpf: Avoid joining .BTF.ext data with BPF programs by section name

Instead of using ELF section names as a joining key between .BTF.ext and
corresponding BPF programs, pre-build .BTF.ext section number to ELF
section index mapping during bpf_object__open() and use it later for
matching .BTF.ext information (func/line info or CO-RE relocations) to
their respective BPF programs and subprograms.

This simplifies corresponding joining logic and let's libbpf do
manipulations with BPF program's ELF sections like dropping leading '?'
character for non-autoloaded programs. Original joining logic in
bpf_object__relocate_core() (see relevant comment that's now removed)
was never elegant, so it's a good improvement regardless. But it also
avoids unnecessary internal assumptions about preserving original ELF
section name as BPF program's section name (which was broken when
SEC("?abc") support was added).

Fixes: a3820c481112 ("libbpf: Support opting out from autoloading BPF programs declaratively")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220426004511.2691730-5-andrii@kernel.org
tools/lib/bpf/btf.c
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h