Disable some rustc/LLVM optimizations for build efficiency
Developers can run into problems with the BPF verifier like invalid size of register spill despite having what might not seem (to them) like a very large or complex eBPF program.
One way Aya itself can help with these situations (as per @alessandrod's recommendation) is to disable some of the non-necessary optimizations we currently have enabled in rustc and LLVM which generate extra, complex code.
The purpose of this task is to strategize and implement such optimizations to help improve the development experience.
(originally discussed in https://github.com/aya-rs/aya/discussions/505, and recommended by @alessandrod)
One way Aya itself can help with these situations
I don't think it can be done in Aya, it's a task to do in rustc (and LLVM if we want to go hardcore). Rust enables these LLVM passes and currently there is no way to disable/enable them from command line:
https://github.com/rust-lang/rust/blob/6a28fb42a8b8f1f67fe854c2206148171e434d73/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp#L62-L76
The first thing which I would do is:
- Prepare small eBPF programs which reproduce verifier errors.
- Comment all the passes (or all the suspected passes, at least) in
PassWrapper.cpp, build custom rustc. - Try to load the same programs, but built with
cargo +stage1 build. - If it works, uncomment a pass, repeat 2-4. If it doesn't, we probably know the breaking pass.
After nailing down which pass triggers the issue, the next things to do would be:
- Proposing some mechanism of disabling that pass in Rust for BPF target. I think that some kind of per-target blocklist of passes would work.
- Bonus points for actually fixing that pass in LLVM.
I don't think it can be done in Aya, it's a task to do in rustc (and LLVM if we want to go hardcore)
We should be fixing LLVM issues as part of what we do on the regular. Nobody is going to fix issues for us, this should become part of our normal workflow.
Rust enables these LLVM passes and currently there is no way to disable/enable them from command line:
Rust does have a way to do that:
https://doc.rust-lang.org/rustc/codegen-options/index.html#no-prepopulate-passes https://doc.rust-lang.org/rustc/codegen-options/index.html#passes