[clang] [llvm] [Clang][CodeGen] Add -gbtf: target-independent BTF emission for ELF targets (PR #183929)
Can H. Tartanoglu via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 6 03:36:04 PST 2026
caniko wrote:
@4ast @efriedma-quic @yonghong-song @eddyz87 Pushed the reworked 3-commit series (`27bacf58eadb`..`36f59c9f1331`), rebased onto `main` (`5ea3312c9ec5`):
1. **NFC split (`27bacf58eadb`):** Moves `BTFDebug` into `CodeGen/AsmPrinter` and keeps BPF CO-RE, `.maps`, `DW_CC_nocall` register recovery, and `.BTF.ext` in `BPFBTFDebug` (including the recent `EnumValueImm32Attr` lowering from #246702).
2. **BTF format limits & pruning policy (`7f18d31c6d40`):** Zero `isBPF` checks in `BTFDebug.{h,cpp}`. Format representability (`INT <= 128`, `ENUM <= 64`, complex float sizes, C++ static member/virtual-base filtering) is enforced unconditionally in shared code as a property of the BTF format rather than the target triple. Pointee pruning is an explicit policy (`shouldPruneBTF()`, defaulting to pruned on BPF and unpruned on non-BPF ELF), using deterministic `MapVector` fixups resolved by `DIType`/ODR identity.
3. **Driver & `AsmPrinter` wiring (`36f59c9f1331`):** Matches GCC 15.2's `-gbtf` / `-gprune-btf` / `-gno-prune-btf` semantics — `-gbtf` alone emits `.BTF` without DWARF (`-g -gbtf` emits both), and non-BPF targets do not emit `.BTF.ext`.
Verified locally:
- 254/254 lit tests pass across `CodeGen/BPF/BTF`, `CodeGen/BPF/CORE`, `CodeGen/X86/BTF`, `clang/test/Driver/gbtf.c`, and `clang/test/CodeGen/btf-module-flag.c` (plus 6/6 Clang debug driver tests including `debug-options.c`).
- Single-TU `bpf-next` x86-64 compiles (`drivers/ata/libahci.o`, `drivers/net/ethernet/intel/e1000/e1000_hw.o`, `drivers/virtio/virtio_ring.o`, `kernel/bpf/btf.o`) with `-gbtf` emit `.BTF` with no `.debug_info` or `.BTF.ext`, and emit full `STRUCT` definitions for `ahci_cmd_hdr`, `e1000_shadow_ram`, and `vring_used` (previously `FWD`-only under BPF pruning).
Non-BPF `DW_CC_nocall` ABI filtering and the cross-compiler `ET_REL` `DATASEC` relocation encoding remain deferred pending the `bpf at vger.kernel.org` thread (https://lore.kernel.org/bpf/87fqwmspyg.fsf@gnu.org/).
Assisted-by: Antigravity (Gemini 4 Neon)
https://github.com/llvm/llvm-project/pull/183929
More information about the cfe-commits
mailing list