Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1085,10 +1085,6 @@ // They also might be exported if referenced by DSOs. Script->declareSymbols(); - // Handle undefined symbols in DSOs. - if (!Config->Shared) - Symtab->scanShlibUndefined(); - // Handle the -exclude-libs option. if (Args.hasArg(OPT_exclude_libs)) excludeLibs(Args); Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -93,13 +93,6 @@ return Symbols; } - // Returns undefined symbols of a shared library. - // It is a runtime error to call this function on files of other types. - const llvm::DenseSet &getUndefinedSymbols() { - assert(FileKind == SharedKind); - return Undefs; - } - // Filename of .a which contained this file. If this file was // not in an archive file, it is the empty string. We use this // string for creating error messages. @@ -121,7 +114,6 @@ InputFile(Kind K, MemoryBufferRef M); std::vector Sections; std::vector Symbols; - llvm::DenseSet Undefs; private: const Kind FileKind; Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -851,7 +851,9 @@ StringRef Name = CHECK(Sym.getName(this->StringTable), this); if (Sym.isUndefined()) { - this->Undefs.insert(Name); + Symtab->addUndefined(Name, Sym.getBinding(), Sym.st_other, + Sym.getType(), + /*CanOmitFromDynSym=*/false, this); continue; } Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -129,10 +129,6 @@ Symbol *B = Symtab->find(Cmd->Name); if (B && !B->isDefined()) return true; - // It might also be referenced by a DSO. - for (InputFile *F : SharedFiles) - if (F->getUndefinedSymbols().count(Cmd->Name)) - return true; return false; } Index: ELF/SymbolTable.h =================================================================== --- ELF/SymbolTable.h +++ ELF/SymbolTable.h @@ -78,7 +78,6 @@ InputFile *File); template void fetchIfLazy(StringRef Name); - template void scanShlibUndefined(); void scanVersionScript(); Symbol *find(StringRef Name); Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -294,6 +294,8 @@ uint8_t Visibility = getVisibility(StOther); std::tie(S, WasInserted) = insert(Name, Type, Visibility, CanOmitFromDynSym, File); + if (File && File->kind() == InputFile::SharedKind) + S->ExportDynamic = true; // An undefined symbol with non default visibility must be satisfied // in the same DSO. if (WasInserted || (isa(S) && Visibility != STV_DEFAULT)) { @@ -588,29 +590,6 @@ } } -// This function takes care of the case in which shared libraries depend on -// the user program (not the other way, which is usual). Shared libraries -// may have undefined symbols, expecting that the user program provides -// the definitions for them. An example is BSD's __progname symbol. -// We need to put such symbols to the main program's .dynsym so that -// shared libraries can find them. -// Except this, we ignore undefined symbols in DSOs. -template void SymbolTable::scanShlibUndefined() { - for (InputFile *F : SharedFiles) { - for (StringRef U : F->getUndefinedSymbols()) { - Symbol *Sym = find(U); - if (!Sym) - continue; - if (auto *L = dyn_cast(Sym)) - if (InputFile *File = L->fetch()) - addFile(File); - - if (Sym->isDefined()) - Sym->ExportDynamic = true; - } - } -} - // Initialize DemangledSyms with a map from demangled symbols to symbol // objects. Used to handle "extern C++" directive in version scripts. // @@ -836,8 +815,3 @@ template void SymbolTable::fetchIfLazy(StringRef); template void SymbolTable::fetchIfLazy(StringRef); template void SymbolTable::fetchIfLazy(StringRef); - -template void SymbolTable::scanShlibUndefined(); -template void SymbolTable::scanShlibUndefined(); -template void SymbolTable::scanShlibUndefined(); -template void SymbolTable::scanShlibUndefined(); Index: test/ELF/trace-symbols.s =================================================================== --- test/ELF/trace-symbols.s +++ test/ELF/trace-symbols.s @@ -69,7 +69,7 @@ # RUN: ld.lld -y foo -y bar %t %t1.so %t2.so -o %t3 | \ # RUN: FileCheck -check-prefix=SHLIBRBAR %s -# SHLIBRBAR-NOT: trace-symbols.s.tmp1.so: reference to bar +# SHLIBRBAR: trace-symbols.s.tmp1.so: reference to bar # RUN: ld.lld -y foo -y bar %t -u bar --start-lib %t1 %t2 --end-lib -o %t3 | \ # RUN: FileCheck -check-prefix=STARTLIB %s