[Pre-RFC] BTF relocations
anakryiko:
re: "relocatable". I would definitely not call it "bpf_relocatable" (target specific), but between "relocatable" and "btf_relocatable", BTF is the means through which relocation information is captured (BTF types/fields) and expressed (.BTF.ext section), so btf_ prefix seems appropriate. For this Swift use case you were talking about, would relocation information be expressed differently somehow?
After giving it more thought, I think that btf_ prefix definitely makes sense for intrinsics. I don't expect intrinsics to be shared between different types of field relocations (e.g. BTF, Swift).
So the intrinsics I proposed above could be called:
pub fn btf_field_byte_offset<T: PointeeSized>(variant: usize, field: usize) -> usize
pub fn btf_field_byte_size<T: PointeeSized>(variant: usize, field: usize) -> usize
pub fn btf_field_exists<T: PointeeSized>(variant: usize, field: usize) -> bool
Field projection is where a more unified design could make more sense though.
vad:
With BTF-relocatable types, we are not sure whether a field exists during a runtime. Therefore, a field access does not provide any guarantees of soundess. That goes against Rust's guarantees of safety.
I take this point back - BPF verifier will always reject programs with field accesses to non-existing fields, so the field projection is still safe. That said, I think it makes sense to start only with intrinsics now, and leave the field projection topic for future.
Given that there are no objections to the feature itself, I went ahead and submitted an RFC, trimmed down only to intrinsics, on GitHub:
github.com/rust-lang/rfcs
BTF relocations (#3966)
master ← vadorovsky:btf-relocations
opened 08:16AM - 31 May 26 UTC
vadorovsky
+379 -0
The RFC proposes the btf_relocatable_types feature gate, that provides a #[re…pr(btf)] representation and low-level field-info intrinsics that emit [BTF (BPF TypeFormat)][btf] [CO-RE (Compile Once, Run Everywhere)][co-re] relocations. It also documents the relationship to offset_of!, ordinary field projection and LLVM BPF lowering. This feature was originally proposed as [pre-RFC][pre-rfc]. [btf]: https://docs.kernel.org/bpf/btf.html [co-re]: https://nakryiko.com/posts/bpf-portability-and-co-re/ [pre-rfc]: https://internals.rust-lang.org/t/pre-rfc-btf-relocations/24161/25 Rendered
Discussion in the ATmosphere