Re: bpftool gen object doesn't handle GCC built BPF ELF files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/6/22 10:20 AM, Andrii Nakryiko wrote:
On Wed, Jul 6, 2022 at 10:13 AM James Hilliard
<james.hilliard1@xxxxxxxxx> wrote:

Note I'm testing with the following patches:
https://lore.kernel.org/bpf/20220706111839.1247911-1-james.hilliard1@xxxxxxxxx/
https://lore.kernel.org/bpf/20220706140623.2917858-1-james.hilliard1@xxxxxxxxx/

It would appear there's some compatibility issues with bpftool gen and
GCC, not sure what side though is wrong here:
/home/buildroot/buildroot/output/per-package/systemd/host/sbin/bpftool
gen object src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.o
src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.unstripped.o
libbpf: failed to find BTF info for global/extern symbol 'sd_restrictif_i'
Error: failed to link
'src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.unstripped.o':
Unknown error -2 (-2)

Relevant difference seems to be this:
GCC:
[55] FUNC 'sd_restrictif_i' type_id=47 linkage=static
Clang:
[27] FUNC 'sd_restrictif_i' type_id=26 linkage=global


GCC is wrong, clearly. This function is global ([0]) and libbpf
expects it to be marked as such in BTF.

https://github.com/systemd/systemd/blob/main/src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.c#L42-L50


How about updating the BTF format documentation in btf.rst to reflect the specification for BTF_KIND_FUNC ?

Thanks

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index f49aeef62d0c..b3a9d5ac882c 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -369,7 +369,7 @@ No additional type data follow ``btf_type``.
   * ``name_off``: offset to a valid C identifier
   * ``info.kind_flag``: 0
   * ``info.kind``: BTF_KIND_FUNC
-  * ``info.vlen``: 0
+  * ``info.vlen``: linkage information (static=0, global=1)
   * ``type``: a BTF_KIND_FUNC_PROTO type

 No additional type data follow ``btf_type``.


GCC:

[1] INT 'signed char' size=1 bits_offset=0 nr_bits=8 encoding=UNKN
[2] INT 'unsigned char' size=1 bits_offset=0 nr_bits=8 encoding=CHAR
[3] TYPEDEF '__u8' type_id=2
[4] CONST '(anon)' type_id=3

[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux