[lld] [LLD][COFF] Add S_THUNK32 PDB records for all ARM64EC import thunks (PR #115310)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 05:06:37 PST 2024


================
@@ -1562,53 +1562,61 @@ void PDBLinker::addImportFilesToPDB() {
       mod->setObjFileName(libPath);
     }
 
-    DefinedImportThunk *thunk = cast<DefinedImportThunk>(file->thunkSym);
-    Chunk *thunkChunk = thunk->getChunk();
-    OutputSection *thunkOS = ctx.getOutputSection(thunkChunk);
-
     ObjNameSym ons(SymbolRecordKind::ObjNameSym);
     Compile3Sym cs(SymbolRecordKind::Compile3Sym);
-    Thunk32Sym ts(SymbolRecordKind::Thunk32Sym);
-    ScopeEndSym es(SymbolRecordKind::ScopeEndSym);
 
     ons.Name = file->dllName;
     ons.Signature = 0;
 
     fillLinkerVerRecord(cs, ctx.config.machine);
 
-    ts.Name = thunk->getName();
-    ts.Parent = 0;
-    ts.End = 0;
-    ts.Next = 0;
-    ts.Thunk = ThunkOrdinal::Standard;
-    ts.Length = thunkChunk->getSize();
-    ts.Segment = thunkOS->sectionIndex;
-    ts.Offset = thunkChunk->getRVA() - thunkOS->getRVA();
-
     llvm::BumpPtrAllocator &bAlloc = lld::bAlloc();
     mod->addSymbol(codeview::SymbolSerializer::writeOneSymbol(
         ons, bAlloc, CodeViewContainer::Pdb));
     mod->addSymbol(codeview::SymbolSerializer::writeOneSymbol(
         cs, bAlloc, CodeViewContainer::Pdb));
 
-    CVSymbol newSym = codeview::SymbolSerializer::writeOneSymbol(
-        ts, bAlloc, CodeViewContainer::Pdb);
+    auto addThunk = [&](Symbol *sym, Chunk *chunk) {
+      OutputSection *thunkOS = ctx.getOutputSection(chunk);
+
+      Thunk32Sym ts(SymbolRecordKind::Thunk32Sym);
+      ScopeEndSym es(SymbolRecordKind::ScopeEndSym);
+
+      ts.Name = sym->getName();
+      ts.Parent = 0;
+      ts.End = 0;
+      ts.Next = 0;
+      ts.Thunk = ThunkOrdinal::Standard;
+      ts.Length = chunk->getSize();
+      ts.Segment = thunkOS->sectionIndex;
+      ts.Offset = chunk->getRVA() - thunkOS->getRVA();
 
-    // Write ptrEnd for the S_THUNK32.
-    ScopeRecord *thunkSymScope =
-        getSymbolScopeFields(const_cast<uint8_t *>(newSym.data().data()));
+      CVSymbol newSym = codeview::SymbolSerializer::writeOneSymbol(
+          ts, bAlloc, CodeViewContainer::Pdb);
 
-    mod->addSymbol(newSym);
+      // Write ptrEnd for the S_THUNK32.
+      ScopeRecord *thunkSymScope =
+          getSymbolScopeFields(const_cast<uint8_t *>(newSym.data().data()));
 
-    newSym = codeview::SymbolSerializer::writeOneSymbol(es, bAlloc,
-                                                        CodeViewContainer::Pdb);
-    thunkSymScope->ptrEnd = mod->getNextSymbolOffset();
+      mod->addSymbol(newSym);
 
-    mod->addSymbol(newSym);
+      newSym = codeview::SymbolSerializer::writeOneSymbol(
----------------
mstorsjo wrote:

Wow, this diff surely is actively hard to follow; switching the diff to ignore whitespace doesn't seem to help...

https://github.com/llvm/llvm-project/pull/115310


More information about the llvm-commits mailing list