Index: lld/trunk/COFF/Config.h =================================================================== --- lld/trunk/COFF/Config.h +++ lld/trunk/COFF/Config.h @@ -94,7 +94,7 @@ std::vector Argv; // Symbols in this set are considered as live by the garbage collector. - std::set GCRoot; + std::vector GCRoot; std::set NoDefaultLibs; bool NoDefaultLibAll = false; Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -355,7 +355,10 @@ Symbol *LinkerDriver::addUndefined(StringRef Name) { Symbol *B = Symtab->addUndefined(Name); - Config->GCRoot.insert(B); + if (!B->IsGCRoot) { + B->IsGCRoot = true; + Config->GCRoot.push_back(B); + } return B; } Index: lld/trunk/COFF/Symbols.h =================================================================== --- lld/trunk/COFF/Symbols.h +++ lld/trunk/COFF/Symbols.h @@ -77,7 +77,8 @@ friend SymbolTable; explicit Symbol(Kind K, StringRef N = "") : SymbolKind(K), IsExternal(true), IsCOMDAT(false), - WrittenToSymtab(false), Name(N) {} + WrittenToSymtab(false), PendingArchiveLoad(false), IsGCRoot(false), + Name(N) {} const unsigned SymbolKind : 8; unsigned IsExternal : 1; @@ -98,6 +99,9 @@ // not load any more archive members to resolve the same symbol. unsigned PendingArchiveLoad : 1; + /// True if we've already added this symbol to the list of GC roots. + unsigned IsGCRoot : 1; + protected: StringRef Name; };