External Publication
Visit Post

[Pre-RFC] BTF relocations

Rust Internals [Unofficial] May 1, 2026
Source

I think the current implementation in LLVM makes it quite hard to implement with anything else than real structs:

Using @llvm.preserve.*.access.index intrinsics instead of getelementptr in LLVM has two effects:

  • It ensures the offset stays literally in the code and is not transformed by optimization passes,
  • and it allows debuginfo metadata with type information to be attached to the access.

The BPF codegen backend then writes the used type names and field names into a symbol table and generates BTF relocations that connect each such offset in the code with the symbolic names of the accessed type and field and type layout information.

With a macro or intrinsic function, the compiler would still need to generate type debug metadata, so that the BPF codegen backend can find the names and check the types for compatibility. It's probably way easier to reuse the infrastructure that already generates debuginfo metadata for Rust types than to reimplement part of it just for BPF.

Discussion in the ATmosphere

Loading comments...