[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
Thu Oct 8 02:31:36 PDT 2026
================
@@ -3676,6 +3678,53 @@ void GdbIndexSection::writeTo(uint8_t *buf) {
bool GdbIndexSection::isNeeded() const { return !chunks.empty(); }
+BtfSection::BtfSection(Ctx &ctx)
+ : SyntheticSection(ctx, ".BTF", SHT_PROGBITS, 0, 1) {}
+
+template <class ELFT>
+std::unique_ptr<BtfSection> BtfSection::create(Ctx &ctx) {
+ llvm::TimeTraceScope timeScope("Merge BTF");
+
+ const bool isLE = ELFT::Endianness == llvm::endianness::little;
+ llvm::BTFBuilder builder;
+
+ // Collect all .BTF input sections and merge them.
+ // Mark originals dead so they don't appear in the output.
+ for (InputSectionBase *s : ctx.inputSections) {
+ if (s->name != ".BTF" || !s->isLive())
----------------
caniko wrote:
The test now gives the two COMDAT copies different BTF types (`int` and `long`) and checks type/string lengths of 16 and 5 bytes. That catches inclusion of the discarded copy even if the BTF magic remains valid. The fixture also covers `-r` and `--gc-sections`. Exact-current-source lld execution is still pending, so I'm leaving this thread open until that check runs.
https://github.com/llvm/llvm-project/pull/183915
More information about the llvm-commits
mailing list