diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1401,7 +1401,7 @@ // Symbols in the dynsym could be address-significant in other executables // or DSOs, so we conservatively mark them as address-significant. for (Symbol *S : Symtab->getSymbols()) - if (S->includeInDynsym()) + if (!S->isPlaceholder() && S->includeInDynsym()) markAddrsig(S); // Visit the address-significance table in each object file and mark each @@ -1575,7 +1575,7 @@ // Handle --trace-symbol. for (auto *Arg : Args.filtered(OPT_trace_symbol)) - Symtab->trace(Arg->getValue()); + Symtab->insert(Arg->getValue())->Traced = true; // Add all files to the symbol table. This will add almost all // symbols that we need to the symbol table. This process might diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -143,6 +143,8 @@ // Initialize UsedStartStop. for (Symbol *Sym : Symtab->getSymbols()) { + if (Sym->isPlaceholder()) + continue; StringRef S = Sym->getName(); for (StringRef Prefix : {"__start_", "__stop_"}) if (S.startswith(Prefix)) diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -214,7 +214,7 @@ // Preserve externally-visible symbols if the symbols defined by this // file can interrupt other ELF file's symbols at runtime. for (Symbol *S : Symtab->getSymbols()) - if (S->includeInDynsym()) + if (!S->isPlaceholder() && S->includeInDynsym()) markSymbol(S); // Preserve special sections and those which are specified in linker diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -43,8 +43,6 @@ Symbol *find(StringRef Name); - void trace(StringRef Name); - void handleDynamicList(); // Set of .so files to not link the same shared object file more than once. diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -32,12 +32,6 @@ SymbolTable *elf::Symtab; -// Set a flag for --trace-symbol so that we can print out a log message -// if a new symbol with the same name is inserted into the symbol table. -void SymbolTable::trace(StringRef Name) { - SymMap.insert({CachedHashStringRef(Name), -1}); -} - void SymbolTable::wrap(Symbol *Sym, Symbol *Real, Symbol *Wrap) { // Swap symbols as instructed by -wrap. int &Idx1 = SymMap[CachedHashStringRef(Sym->getName())]; @@ -70,13 +64,6 @@ auto P = SymMap.insert({CachedHashStringRef(Name), (int)SymVector.size()}); int &SymIndex = P.first->second; bool IsNew = P.second; - bool Traced = false; - - if (SymIndex == -1) { - SymIndex = SymVector.size(); - IsNew = true; - Traced = true; - } if (!IsNew) return SymVector[SymIndex]; @@ -91,7 +78,6 @@ Sym->IsUsedInRegularObj = false; Sym->ExportDynamic = false; Sym->CanInline = true; - Sym->Traced = Traced; Sym->ScriptDefined = false; return Sym; } @@ -106,9 +92,10 @@ auto It = SymMap.find(CachedHashStringRef(Name)); if (It == SymMap.end()) return nullptr; - if (It->second == -1) + Symbol *Sym = SymVector[It->second]; + if (Sym->isPlaceholder()) return nullptr; - return SymVector[It->second]; + return Sym; } // Initialize DemangledSyms with a map from demangled symbols to symbol diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1170,7 +1170,7 @@ // We want both global and local symbols. We get the global ones from the // symbol table and iterate the object files for the local ones. for (Symbol *Sym : Symtab->getSymbols()) - if (!Sym->isLazy()) + if (!Sym->isPlaceholder() && !Sym->isLazy()) AddSym(*Sym); for (InputFile *File : ObjectFiles) for (Symbol *Sym : File->getSymbols()) @@ -1610,7 +1610,7 @@ finalizeSynthetic(In.EhFrame); for (Symbol *S : Symtab->getSymbols()) - if (!S->IsPreemptible) + if (!S->isPlaceholder() && !S->IsPreemptible) S->IsPreemptible = computeIsPreemptible(*S); // Scan relocations. This must be done after every symbol is declared so that @@ -1648,8 +1648,11 @@ // Now that we have defined all possible global symbols including linker- // synthesized ones. Visit all symbols to give the finishing touches. for (Symbol *Sym : Symtab->getSymbols()) { + if (Sym->isPlaceholder()) + continue; if (!includeInSymtab(*Sym)) continue; + if (In.SymTab) In.SymTab->addSymbol(Sym);