diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index 240a67aa1f14..560010b63a43 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -80,7 +80,7 @@ protected: friend SymbolTable; explicit SymbolBody(Kind K, StringRef N = "") : SymbolKind(K), IsExternal(true), IsCOMDAT(false), - IsReplaceable(false), Name(N) {} + IsReplaceable(false), WrittenToSymtab(false), Name(N) {} const unsigned SymbolKind : 8; unsigned IsExternal : 1; @@ -91,6 +91,11 @@ protected: // This bit is used by the \c DefinedBitcode subclass. unsigned IsReplaceable : 1; +public: + // This bit is used by Writer::createSymbolAndStringTable(). + unsigned WrittenToSymtab : 1; + +protected: StringRef Name; }; diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 13d95c6ea778..98fd6c4470cd 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -533,13 +533,14 @@ void Writer::createSymbolAndStringTable() { Sec->setStringTableOff(addEntryToStringTable(Name)); } - std::set SeenSymbols; for (lld::coff::ObjectFile *File : Symtab->ObjectFiles) for (SymbolBody *B : File->getSymbols()) if (auto *D = dyn_cast(B)) - if (SeenSymbols.insert(D).second) + if (!D->WrittenToSymtab) { + D->WrittenToSymtab = true; if (Optional Sym = createSymbol(D)) OutputSymtab.push_back(*Sym); + } OutputSection *LastSection = OutputSections.back(); // We position the symbol table to be adjacent to the end of the last section.