-
Notifications
You must be signed in to change notification settings - Fork 741
bpf2go: support multiple source files #1758
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
Comments
Thanks for the PR! What's the reason for the move to Rust, if I may ask? I've pulled in a few reviewers explicitly to get things moving. Ack on the decision to require bpf2go manage the compilation of all objects, that will keep overall internal complexity and API surface down. If users want more control over the compilation process, we can always cater to specific use cases and add more knobs later on. This looks good as a first approach. On the question of weak symbols, that's not an issue about bpf2go specifically, but rather of the library as a whole. The way bpf2go handles compilation and linking has little impact on this. However, including the feature in bpf2go may give a user the false impression that linked objects are fully supported in the lib, which may not be the case. It would be ideal if someone (you 🙂) could dogfood the implementation so the overall support gets iterated on quickly as issues pop up. |
The move to Rust was due to parquet libraries; we needed good object store support, and wanted to have control over the amount of buffer memory, and the arrow+parquet implementation in Rust provided an easy pathway. On weak symbols, I did not deliberately use weak symbols, and this patch worked in our repository. I'll keep an eye out for any issues in future dealings with bpf2go. Thank you for the PR comments! I'll try and get to those today. |
@yonch Thanks for elaborating! Let us know when you've got something ready. |
Hi folks I've been pretty swamped and haven't gotten around to these. Still on my plate but it is taking a back burner. If you find someone who wants to pick up where I left off I have no objection. |
Background and Motivation
Currently, the bpf2go tool only supports compiling a single source file at a time. This limits our ability to create modular eBPF programs composed of multiple source files. Supporting multiple source files would enable better code organization, reusability, and testability for eBPF programs -- improving the developer experience.
Use Cases
Concrete Example - RMID Allocation in Unvariance Collector
In the Unvariance Collector project, we need to allocate Resource Monitoring IDs (RMIDs) to processes. These RMIDs come from a limited space (typically 0 to ~460 on certain processors). We want to:
Ideally, we would:
unvariance/collector#109 for more info
Proposed Implementation
After examining the codebase (particularly in cmd/bpf2go), I suggest the following changes:
Modify the
b2g
struct in main.go to accept multiple source files:SourceFile string
toSourceFiles []string
Refactor the convert() function:
convert
function intocompileOne
Add a linking step when multiple source files are provided:
Link
) similar to existingCompile
bpftool gen object
to combine multiple object files into oneHandle dependencies correctly when multiple files are used:
Backward Compatibility
When only one source file is provided, the tool should behave exactly as it does now. This ensures backward compatibility with existing workflows.
Related Issues and Discussions
[Discussion #1142](bpf2go should be able to generate Go code from object files built out-of-band #1142): This discussion considered generating Go code from a given object file, which would support this use case by allowing users to create multiple object files out-of-band and use bpftool to link them together. However, as mentioned in that discussion, this approach would require users to understand internal plumbing and handle target-specific details manually. Our proposal solves this by using bpf2go to build all object files automatically without exposing internal complexity.
[Issue #466](elf: support bpf object linking (
bpftool gen object
) #466): This issue calls for support of BPF object linking and explicitly mentions bpftool gen object, which we intend to use. However, it focuses specifically on handling weak symbols. While this remains an open issue, users who don't use weak symbols shouldn't encounter these problems with our proposed multi-file support.I'd be happy to work on implementing this feature. Looking forward to your feedback!
The text was updated successfully, but these errors were encountered: