Re: [PATCH] rust: Disallow BTF generation with Rust + LTO

vadorovsky
2025-01-10T16:41:28Z

On Friday, January 10th, 2025 at 5:22 PM, Dave Tucker <dave@dtucker.co.uk> wrote:

> > On 9 Jan 2025, at 22:39, Arnaldo Carvalho de Melo acme@kernel.org wrote:
> > And sure this will be refused by the kernel, lots of stuff that have
> > invalid names, probably need to turn those into void as well as a
> > continuation of this hack, then prune, maybe that is it, we'll see.
>
>
> Rather than voiding the names you can do something like this [0] to
> coerce them into a format that the kernel is happy with. We initally
> voided names but the resulting BTF was unusable since you couldn’t
> lookup types by name.

Regarding the names, I would recommend to do exactly what we're doing in bpf-linker[0], which is converting each character not supported by C to `_[hex_representation]_`. This way, we make sure that two different types can't produce the same names in BTF.

An another important fixup we do is ignoring data-carrying enums[1], I think pahole could that do for now as well. That said, I think a long-term solution would be teaching the kernel to accept them.

Cheers,
Michal

[0] https://github.com/aya-rs/bpf-linker/blob/v0.9.13/src/llvm/di.rs#L34-L60
[1] https://github.com/aya-rs/bpf-linker/blob/v0.9.13/src/llvm/di.rs#L129-L132