-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for writing maps into .maps ELF section in aya-bpf #351
Comments
We have some updates and a bit of progress here. Discord thread for anyone interested LLVM fix@dave-tucker submitted this LLVM fix https://reviews.llvm.org/D134533 - the only thing missing to get it merged is writing some LLVM IR test for that, which Dave is working on. Building LLVM with this patch and then building bpf-linker with it makes it possible to build eBPF programs with debug_info and BTF. 🎉 Actual BTF map support in AyaI crated this repo where I'm trying to make a small aya-bpf program with a BTF map: https://github.com/aya-rs/aya-btf-maps It's using libbpf 1.0 in the userspace and Aya in the eBPF crate.
These are examples of BTF map definitions preprocessed by clang: struct {
int (*type)[BPF_MAP_TYPE_ARRAY];
typeof(u32) *key;
typeof(u32) *value;
int (*max_entries)[256];
} array1 struct {
int (*type)[BPF_MAP_TYPE_SK_STORAGE];
int (*map_flags)[BPF_F_NO_PREALLOC];
typeof(int) *key;
typeof(int) *value;
} sk_stg_map I managed to build such a struct with this macro: libbpf is fine with how the
We need to compare Loading the same program with Aya (in userspace) works. Please note that this example is just defining a map as a struct directly in the eBPF program crate. And we use bindings to BPF helpers directly. Once we get it working, we still need to figure out how we design a proper API for BTF maps in Aya. If anyone wants to try our or/and help, I added instructions to README how to prepare patched LLVM, bpf-linker, build the project and what's done there. |
Currently we are doing a following fixup in Aya (userspace, when loading programs): Lines 393 to 401 in 66b4f79
PTR looks like that in BTF (produced by clang):
PTRs in Rust BTF have names corresponding to the type of a pointer:
DWARF (produced by clang):
(notice the lack of We need to move it to bpf-linker. And all the other differences in debug_info between eBPF objects commpiled with C and Rust - also have to be handled in bpf-linker. At least for now (we might consider proper fixes in rustc/LLVM/kernel when we know everything and get stuff working). Probably the best place for fixup would be somewhere around here: On this stage, we have already one big LLVM module after linking, we just need to find a way to find the debug info of that module and be able to iterate over it. Quotes from Discord:
There was also an idea of modifying DI by writing an LLVM pass, but
|
I need this for a project I'm working on, so I've started implementing doing the fixups in bpf-linker |
At the moment generating BTF debug info by default is not enabled. Once LLVM fixes are in and this is merged in bpf-linker, we'll need to teach aya-bpf to support writing maps into .maps section.
Adding this as an issue, so that I don't forget to tackle it once the above 2 things are done. cc @vadorovsky
The text was updated successfully, but these errors were encountered: