@@ -1537,7 +1537,7 @@ void PDBLinker::addImportFilesToPDB() {
15371537 if (!file->thunkSym )
15381538 continue ;
15391539
1540- if (!file->thunkSym ->isLive ())
1540+ if (!file->thunkSym ->isLive () && !file-> impchkThunk )
15411541 continue ;
15421542
15431543 std::string dll = StringRef (file->dllName ).lower ();
@@ -1562,53 +1562,61 @@ void PDBLinker::addImportFilesToPDB() {
15621562 mod->setObjFileName (libPath);
15631563 }
15641564
1565- DefinedImportThunk *thunk = cast<DefinedImportThunk>(file->thunkSym );
1566- Chunk *thunkChunk = thunk->getChunk ();
1567- OutputSection *thunkOS = ctx.getOutputSection (thunkChunk);
1568-
15691565 ObjNameSym ons (SymbolRecordKind::ObjNameSym);
15701566 Compile3Sym cs (SymbolRecordKind::Compile3Sym);
1571- Thunk32Sym ts (SymbolRecordKind::Thunk32Sym);
1572- ScopeEndSym es (SymbolRecordKind::ScopeEndSym);
15731567
15741568 ons.Name = file->dllName ;
15751569 ons.Signature = 0 ;
15761570
15771571 fillLinkerVerRecord (cs, ctx.config .machine );
15781572
1579- ts.Name = thunk->getName ();
1580- ts.Parent = 0 ;
1581- ts.End = 0 ;
1582- ts.Next = 0 ;
1583- ts.Thunk = ThunkOrdinal::Standard;
1584- ts.Length = thunkChunk->getSize ();
1585- ts.Segment = thunkOS->sectionIndex ;
1586- ts.Offset = thunkChunk->getRVA () - thunkOS->getRVA ();
1587-
15881573 llvm::BumpPtrAllocator &bAlloc = lld::bAlloc ();
15891574 mod->addSymbol (codeview::SymbolSerializer::writeOneSymbol (
15901575 ons, bAlloc, CodeViewContainer::Pdb));
15911576 mod->addSymbol (codeview::SymbolSerializer::writeOneSymbol (
15921577 cs, bAlloc, CodeViewContainer::Pdb));
15931578
1594- CVSymbol newSym = codeview::SymbolSerializer::writeOneSymbol (
1595- ts, bAlloc, CodeViewContainer::Pdb);
1579+ auto addThunk = [&](Symbol *sym, Chunk *chunk) {
1580+ OutputSection *thunkOS = ctx.getOutputSection (chunk);
1581+
1582+ Thunk32Sym ts (SymbolRecordKind::Thunk32Sym);
1583+ ScopeEndSym es (SymbolRecordKind::ScopeEndSym);
1584+
1585+ ts.Name = sym->getName ();
1586+ ts.Parent = 0 ;
1587+ ts.End = 0 ;
1588+ ts.Next = 0 ;
1589+ ts.Thunk = ThunkOrdinal::Standard;
1590+ ts.Length = chunk->getSize ();
1591+ ts.Segment = thunkOS->sectionIndex ;
1592+ ts.Offset = chunk->getRVA () - thunkOS->getRVA ();
15961593
1597- // Write ptrEnd for the S_THUNK32.
1598- ScopeRecord *thunkSymScope =
1599- getSymbolScopeFields (const_cast <uint8_t *>(newSym.data ().data ()));
1594+ CVSymbol newSym = codeview::SymbolSerializer::writeOneSymbol (
1595+ ts, bAlloc, CodeViewContainer::Pdb);
16001596
1601- mod->addSymbol (newSym);
1597+ // Write ptrEnd for the S_THUNK32.
1598+ ScopeRecord *thunkSymScope =
1599+ getSymbolScopeFields (const_cast <uint8_t *>(newSym.data ().data ()));
16021600
1603- newSym = codeview::SymbolSerializer::writeOneSymbol (es, bAlloc,
1604- CodeViewContainer::Pdb);
1605- thunkSymScope->ptrEnd = mod->getNextSymbolOffset ();
1601+ mod->addSymbol (newSym);
16061602
1607- mod->addSymbol (newSym);
1603+ newSym = codeview::SymbolSerializer::writeOneSymbol (
1604+ es, bAlloc, CodeViewContainer::Pdb);
1605+ thunkSymScope->ptrEnd = mod->getNextSymbolOffset ();
1606+
1607+ mod->addSymbol (newSym);
1608+
1609+ pdb::SectionContrib sc =
1610+ createSectionContrib (ctx, chunk, mod->getModuleIndex ());
1611+ mod->setFirstSectionContrib (sc);
1612+ };
16081613
1609- pdb::SectionContrib sc =
1610- createSectionContrib (ctx, thunk->getChunk (), mod->getModuleIndex ());
1611- mod->setFirstSectionContrib (sc);
1614+ if (file->auxThunkSym && file->auxThunkSym ->isLive ())
1615+ addThunk (file->thunkSym , file->auxThunkSym ->getChunk ());
1616+ if (file->impchkThunk )
1617+ addThunk (file->impchkThunk ->sym , file->impchkThunk );
1618+ if (file->thunkSym ->isLive ())
1619+ addThunk (file->thunkSym , file->thunkSym ->getChunk ());
16121620 }
16131621}
16141622
0 commit comments