[llvm] [BPF] Support for `DW_TAG_variant_part` in BTF generation (PR #155783)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 12 13:23:36 PDT 2025
eddyz87 wrote:
> Wouldn't it be more correct to represent the variant part as a struct with two members - discriminant and union (which then contains the variants as elements)?
This makes sense, but will require adjusting member offsets, compared to what LLVM describes in DI. I'd avoid such complication at the moment, but you can give it a try if you want. Note that it will have to be done in a generic way, meaning that we can't hard code that discriminant is always 4 bytes and at offset 0, this info would have to be extracted from DI.
Also note, that similar reconstruction will heed to happen in [pahole](https://git.kernel.org/pub/scm/devel/pahole/pahole.git/), eventually, when BTF generated for rust kernel code would become important. Pahole generates BTF from DWARF.
> Another option would be extending BTF to actually represent the variant part in a similar way to either LLVM DI or DWARF, showing the discriminant and variants explicitly.
Given that there are alternative options: a union with additional member for discriminator, or a struct with discriminator and a union, I don't think kernel upstream would be happy to extend BTF.
https://github.com/llvm/llvm-project/pull/155783
More information about the llvm-commits
mailing list