Add BTF relocation builtins - #161107
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred to constck cc @fee1-dead
cc @Amanieu, @folkertdev, @sayantn This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to the CTFE machinery Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer
cc @bjorn3 Some changes occurred in match checking cc @Nadrieril Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer Some changes occurred in cc @BoxyUwU The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
Sorry, I will trim this PR only to the builtins. They can be still tested with minicore and a macro embedded in test. And I'm going to leave the core_arch change for later. |
7de4ec2 to
869a54b
Compare
This comment has been minimized.
This comment has been minimized.
|
Now CI fails on |
Register the unstable `btf_relocations` feature and add the `#[btf_relocatable]` built-in attribute for structs and unions, that can be used only on BPF architecture. Preserve the attribute in crate metadata, add UI coverage for feature gating and attribute target validation.
Reject field projection and `offset_off!` usage on `#[btf_relocatable]` types.
Add builtin macros for requesting BTF field information from the Rust compiler's frontend perspective: * `btf_field_byte_offset` * `btf_field_byte_size` * `btf_field_exists` Parse them as `BtfFieldInfo` expressions, that carry the kind of requested information (offset, size, exists), base type and the field path. This mechanism supports nested field accesses in one query. Compile these expressions to `BtfFieldInfo` RValue. Add `btf_field_info` method to the `BuilderMethods` trait in codegen SSA, and use it for lowering the `BtfFieldInfo` RValue. Backends without BTF relocation support report an error. Support in backends will be added in follow-up changes. This change does not expose the functionality to the users. A user-facing API will also be added in a follow-up change.
Expose wrappers for the `llvm.preserve.struct.access.index` and
`llvm.preserve.union.access.index` intrinsics.
Lower backend-neutral BTF field paths by mapping Rust field indices to
LLVM aggregate indices and emitting the corresponding intrinsic calls
(`llvm.preserve.{struct,union}.access.index`). Pass the resulting field
pointer to `llvm.bpf.preserve.field.info`.
Test the `btf_field_exists`, `btf_field_byte_offset` and `btf_field_byte_size` builtins and make sure they emit correct LLVM intrinsic calls.
869a54b to
b42b869
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Add experimental Rust support for Compile Once, Run Everywhere (CO-RE) relocations based on the BPF Type Format (BTF). The entire feature is specific to the BPF architecture and cannot be used elsewhere. The feature introduces a
#[btf_relocatable]attribute for structs and unions whose field layout must be queried through BTF-aware operations, and adds BTF-aware bultins:btf_field_existsbtf_field_byte_offsetbtf_field_byte_sizeThis PR does not yet expose these builtins to the users, the
core_archAPI will be added as a follow-up change.The user-facing feature is gated by
#![feature(btf_relocations)].See individual commits for details.
Created with the help of an LLM, initially used to analyze the existing MIR, codegen SSA and LLVM backend code, to help identifying which parts of code need modification. Afterwards, the code and commit messages were written by hand, then reviewed by an LLM.
Tracking issue: #160616
RFC: rust-lang/rfcs#3966
r? @traviscross @nagisa