[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 Oct 4 13:19:52 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())
+ continue;
+ s->markDead();
+ ArrayRef<uint8_t> data = s->content();
+ StringRef raw(reinterpret_cast<const char *>(data.data()), data.size());
+ Expected<uint32_t> idBase = builder.merge(raw, isLE);
+ if (!idBase) {
+ Warn(ctx) << s << ": failed to parse .BTF section: "
+ << toString(idBase.takeError());
+ continue;
+ }
+ }
+
+ auto ret = std::make_unique<BtfSection>(ctx);
+
+ if (builder.typesCount() == 0)
+ return ret;
+
+ // Deduplicate merged types.
+ if (Error e = llvm::btfDedup(builder)) {
----------------
caniko wrote:
`dedup` is declared in `llvm::BTF` and the linker calls `llvm::BTF::dedup(builder)`.
Source: https://github.com/llvm/llvm-project/blob/3362413f61ac2e1718fd8ecdb9ef46b4dcc452ee/llvm/include/llvm/DebugInfo/BTF/BTFDedup.h. These file blobs are identical to tested head `ba019710f5de8180761c40fa1e90dff5f578ecfd`: [premerge checks](https://github.com/llvm/llvm-project/actions/runs/23135916624) and [formatter](https://github.com/llvm/llvm-project/actions/runs/23135916579) passed there. Head `3362413f61ac2e1718fd8ecdb9ef46b4dcc452ee` only strengthens a separate COMDAT assertion; its new test qualification and the end-to-end kernel receipts remain pending.
https://github.com/llvm/llvm-project/pull/183915
More information about the llvm-commits
mailing list