[lld] [llvm] [dyndbg][LLD][ELF] Initial LLD support for dynamic debugging (PR #214188)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 19:09:10 PDT 2026
================
@@ -1246,6 +1257,71 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
sym->isUsedInRegularObj = true;
sym->referenced = true;
}
+
+ if (dynDbgSec)
+ initDynDbgSymbols();
+}
+
+// Add the undefined symbols of the embedded unoptimized dynamic debugging
+// object so that the outer link resolves the inner link's dependencies. Tag
+// those reached by an inner relocation against a SHT_PROGBITS SHF_ALLOC
+// section with `isDynDbgRef`; the rest are only needed by debug sections.
+template <class ELFT> void ObjFile<ELFT>::initDynDbgSymbols() {
+ MemoryBufferRef dbgMb(toStringRef(dynDbgSec->content()),
+ mb.getBufferIdentifier());
+ std::unique_ptr<ELFFileBase> efb = createObjFile(ctx, dbgMb);
+ // Compare ekind (note ObjFile<ELFT>::classof only tests InputFile::kind()).
+ if (efb->ekind != ekind) {
+ Err(ctx) << this << ": " << dynDbgSecName
+ << " contains an incompatible ELF type";
+ return;
+ }
+ auto &dbgObj = cast<ObjFile<ELFT>>(*efb);
+ const object::ELFFile<ELFT> obj = dbgObj.getObj();
+
+ ArrayRef<Elf_Sym> dbgSyms = dbgObj.template getGlobalELFSyms<ELFT>();
+ SmallVector<bool, 0> globalUsed(dbgSyms.size());
+ auto setSymUsed = [&, firstGlobal = dbgObj.firstGlobal](uint32_t symIdx) {
+ if (symIdx >= firstGlobal)
+ globalUsed[symIdx - firstGlobal] = true;
+ };
+
+ for (const Elf_Shdr &sh : dbgObj.template getELFShdrs<ELFT>()) {
+ if (!isStaticRelSecType(sh.sh_type))
+ continue;
+ const Elf_Shdr &target = *CHECK2(obj.getSection(sh.sh_info), &dbgObj);
+ if (target.sh_type != SHT_PROGBITS || !(target.sh_flags & SHF_ALLOC))
----------------
MaskRay wrote:
Why `target.sh_type != SHT_PROGBITS`? If the inner object's `.init_array` references the external symbol, is it ignored?
https://github.com/llvm/llvm-project/pull/214188
More information about the llvm-commits
mailing list