tw4452852 / zbpf

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

tools/trace: build failure due to bit struct fields #8

Open tw4452852 opened 9 months ago

tw4452852 commented 9 months ago

For example:

% zig build trace -Dkprobe=vfs_read
zig build-exe trace Debug native: error: the following command failed with 1 compilation errors:
/home/tw/code/zig/stage3/bin/zig build-exe /home/tw/code/zbpf/src/trace.zig /home/tw/code/zbpf/zig-cache/o/78a2ee489f9462b6ce60737103daa98e/liblibbpf.a /home/tw/code/zbpf/zig-cache/o/b4e27ee35a32d0daa776bdc75f0b1169/libz.a /home/tw/code/zbpf/zig-cache/o/fb7daa1e59d9fb6436cf07669dc20b1b/libelf.a -lc --cache-dir /home/tw/code/zbpf/zig-cache --global-cache-dir /tmp/.cache/zig --name trace --mod build_options::/home/tw/code/zbpf/zig-cache/c/925bf4c46dd69484c28635252dd91084/options.zig --mod @bpf_prog::/home/tw/code/zbpf/zig-cache/o/95875c2998e8e85004bdc060eb9c14a1/trace.bpf.o --mod bpf:vmlinux:/home/tw/code/zbpf/src/bpf/root.zig --mod vmlinux::/tmp/.cache/zig/o/f298ed85aa7bcf30c9873cb00a270490/vmlinux.zig --deps @bpf_prog,bpf,vmlinux,build_options -I /home/tw/code/zbpf/external/libbpf/src --listen=- 
Build Summary: 12/15 steps succeeded; 1 failed (disable with --summary none)
trace transitive failure
+- install trace transitive failure
   +- zig build-exe trace Debug native 1 errors
/tmp/.cache/zig/o/f298ed85aa7bcf30c9873cb00a270490/vmlinux.zig:6420:16: error: opaque types have unknown size and therefore cannot be directly embedded in unions
/tmp/.cache/zig/o/f298ed85aa7bcf30c9873cb00a270490/vmlinux.zig:6417:28: note: opaque declared here

related to zig translate-c doesn't support bitfields, see https://github.com/ziglang/zig/issues/1499

ekzhang commented 3 months ago

Hello! I found this repository to be a really useful resource. Did you find a workaround for the Zig bitfield translation issue? I was able to compile your trace tool on Linux 5.18

zig build trace -Dkprobe=vfs_read

To get it to compile, I went into the generated vmlinux.zig to find&replace 752 instances of opaque {} with extern struct {}. I was curious if you had a better solution.

tw4452852 commented 2 months ago

@ekzhang Not yet, I'm afraid.