tw4452852 / zbpf

Writing eBPF in Zig
https://tw4452852.github.io/zbpf/
GNU General Public License v3.0
108 stars 6 forks source link

Invalid generated BTF with zig toolchain #9

Closed tw4452852 closed 2 months ago

tw4452852 commented 2 months ago
% zig build test -Dtest=panic && sudo ./zig-out/bin/test 
1/2 root.test_0...OK
2/2 panic.test.panic...libbpf: BTF loading error: -22
libbpf: -- BEGIN BTF LOAD LOG ---
magic: 0xeb9f
version: 1
flags: 0x0
hdr_len: 24
type_off: 0
type_len: 464
str_off: 464
str_len: 1099
btf_total_size: 1587
[1] FUNC_PROTO (anon) return=2 args=(3 (anon))
[2] INT c_long size=8 bits_offset=0 nr_bits=64 encoding=SIGNED
[3] INT bool size=1 bits_offset=0 nr_bits=8 encoding=BOOL
[4] FUNC test_panic type_id=1
[5] FUNC_PROTO (anon) return=6 args=(7 (anon), 11 (anon), 15 (anon))
[6] INT void size=0 bits_offset=0 nr_bits=0 encoding=SIGNED
[7] STRUCT __u_ size=16 vlen=2
    ptr type_id=8 bits_offset=0
    len type_id=10 bits_offset=64
[8] PTR (anon) type_id=9
[9] INT u8 size=1 bits_offset=0 nr_bits=8 encoding=(none)
[10] INT usize size=8 bits_offset=0 nr_bits=64 encoding=(none)
[11] PTR (anon) type_id=12
[12] STRUCT builtin_StackTrace size=24 vlen=2
    index type_id=10 bits_offset=0
    instruction_addresses type_id=13 bits_offset=64
[13] STRUCT __usize size=16 vlen=2
    ptr type_id=14 bits_offset=0
    len type_id=10 bits_offset=64
[14] PTR (anon) type_id=10
[15] PTR (anon) type_id=16
[16] STRUCT _usize size=16 vlen=2
    data type_id=10 bits_offset=0
    some type_id=9 bits_offset=64
[17] FUNC panic type_id=5
[18] FUNC_PROTO (anon) return=10 args=(10 (anon))
[19] FUNC getauxvalImpl type_id=18
[20] ARRAY (anon) type_id=9 index_type_id=21 nr_elems=3
[21] INT __ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none)
[22] VAR _license type_id=20 linkage=1
[23] DATASEC license size=4 vlen=1
     type_id=22 offset=0 size=4
[4] FUNC test_panic type_id=1 Invalid arg#1

-- END BTF LOAD LOG --
libbpf: Error loading .BTF into kernel: -22. BTF is optional, ignoring.
OK
All 2 tests passed.

This issue should be related to https://github.com/ziglang/zig/issues/19782

tw4452852 commented 2 months ago

https://github.com/tw4452852/zbpf/commit/866d83cdf57316f63f6c20ee5fbc0880575a0213 introduces a BTF sanitizer. It will just work around this issue by fixing up the invalid BTF generated by Zig.