[lld] [llvm] [lld][DebugInfo/BTF] Add BTF section merging and deduplication (PR #183915)
Can H. Tartanoglu via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 15 13:43:39 PDT 2026
caniko wrote:
> 1. Could you give an end-to-end example (from source to the final binary with BTF)? It looked at the patch and having the test BTFBuilderTest.cpp and BTFDedupTest.cpp, but I didn't find the llvm code which actually generates BTF. Is is done by rust compiler part? How about C parts?
The BTF generation from DWARF happens in a companion PR, #183929 (`-gbtf`). That PR adds a target-independent pass in Clang/LLVM that converts DWARF debug info to `.BTF` sections at compile time, per object file. So the flow is: `clang -gbtf -c foo.c` produces `foo.o` with a `.BTF` section, then `ld.lld --btf-merge foo.o bar.o -o out` merges and deduplicates those sections. GCC already has the equivalent with its own `-gbtf` flag. This PR only covers the linker side (merge + dedup).
> 2. You mentioned it is a moving part for rust to generate some debuginfo. I am not sure how much rust may change their debuginfo for the *same* construct. But I think hopefully pahole can learn it. I am not familiar with rust. but for each file, the dwarf will have its own cu. So I do not understand how one cu can have both rust and C. Could you give an example for this?
With LTO, the linker performs cross-module inlining and merging before emitting DWARF. When you have a mixed C + Rust kernel build with LTO enabled, the linker can inline a Rust function into a C function (or vice versa), and the resulting DWARF ends up in a single CU that contains types from both languages. Pahole's `PAHOLE_HAS_LANG_EXCLUDE` filters entire CUs by `DW_AT_language`, so it can't selectively remove just the Rust types from a mixed CU. That's the fundamental problem. With the approach in this PR, each compiler emits `.BTF` directly before linking, so there's no post-link DWARF interpretation needed, and the Rust/C mixing issue goes away entirely.
> 3. Please take a look at pahole. pahole generates BTF based on dwarf types but also based on some other vmlinux.o sections (e.g., .BTF_ids, .data..percpu, etc.) and also did some analysis. Also, in pahole, there are some efforts to recover the true signature for some static functions based on locations, where those functions have been optimized. But these are kernel/pahole specific stuff, llvm probably do not like it. Although later kernel/bpf can correct it but it may need to adjust the compiler generated btf. We will need to check how it works and how complex it is.
Yes, pahole handles things beyond type conversion: `.BTF_ids`, `.data..percpu`, and the static function signature recovery work. This PR doesn't aim to replace all of pahole right away. The immediate goal is just the type conversion and dedup part, which is the piece that breaks with LTO + Rust. The kernel-specific post-processing (percpu annotations, BTF_ids, signature recovery) can still be done by pahole on top of the linker-generated `.BTF`, or could be moved into the linker incrementally later. We'll need to work through those cases, but they're separable from the core type merging problem this PR solves.
https://github.com/llvm/llvm-project/pull/183915
More information about the llvm-commits
mailing list