diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 244e8e1f8a89..938fd3e982a5 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1085,10 +1085,6 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // 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); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index daba3bce45c2..0bff0350e6b2 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -851,7 +851,10 @@ template void SharedFile::parseRest() { StringRef Name = CHECK(Sym.getName(this->StringTable), this); if (Sym.isUndefined()) { - this->Undefs.insert(Name); + Symbol *S = Symtab->addUndefined(Name, Sym.getBinding(), + Sym.st_other, Sym.getType(), + /*CanOmitFromDynSym=*/false, this); + S->ExportDynamic = true; continue; } diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 7a4004657a15..5b9e9d79eba3 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -93,13 +93,6 @@ public: 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 @@ protected: InputFile(Kind K, MemoryBufferRef M); std::vector Sections; std::vector Symbols; - llvm::DenseSet Undefs; private: const Kind FileKind; diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index c0c2b8434ccc..85fef2d47bb3 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -129,10 +129,6 @@ static bool shouldDefineSym(SymbolAssignment *Cmd) { 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; } diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 54febf59a256..358f7b699f97 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -588,29 +588,6 @@ template void SymbolTable::fetchIfLazy(StringRef Name) { } } -// 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 +813,3 @@ template void SymbolTable::fetchIfLazy(StringRef); 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(); diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index 0113cc775b45..e36b52e2195d 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -78,7 +78,6 @@ public: InputFile *File); template void fetchIfLazy(StringRef Name); - template void scanShlibUndefined(); void scanVersionScript(); Symbol *find(StringRef Name); diff --git a/lld/test/ELF/trace-symbols.s b/lld/test/ELF/trace-symbols.s index c8ba9b21bcdb..2018f31e3b18 100644 --- a/lld/test/ELF/trace-symbols.s +++ b/lld/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