Put undefined symbols from shared libraries in the symbol table.

With the recent fixes these symbols have more in common than not with
regular undefined symbols.

llvm-svn: 326242
This commit is contained in:
Rafael Espindola 2018-02-27 20:31:22 +00:00
parent bf28a8fc01
commit 3f4c673d38
7 changed files with 5 additions and 47 deletions

View File

@ -1085,10 +1085,6 @@ template <class ELFT> 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<ELFT>();
// Handle the -exclude-libs option.
if (Args.hasArg(OPT_exclude_libs))
excludeLibs<ELFT>(Args);

View File

@ -851,7 +851,10 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
StringRef Name = CHECK(Sym.getName(this->StringTable), this);
if (Sym.isUndefined()) {
this->Undefs.insert(Name);
Symbol *S = Symtab->addUndefined<ELFT>(Name, Sym.getBinding(),
Sym.st_other, Sym.getType(),
/*CanOmitFromDynSym=*/false, this);
S->ExportDynamic = true;
continue;
}

View File

@ -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<StringRef> &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<InputSectionBase *> Sections;
std::vector<Symbol *> Symbols;
llvm::DenseSet<StringRef> Undefs;
private:
const Kind FileKind;

View File

@ -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;
}

View File

@ -588,29 +588,6 @@ template <class ELFT> 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 <class ELFT> void SymbolTable::scanShlibUndefined() {
for (InputFile *F : SharedFiles) {
for (StringRef U : F->getUndefinedSymbols()) {
Symbol *Sym = find(U);
if (!Sym)
continue;
if (auto *L = dyn_cast<Lazy>(Sym))
if (InputFile *File = L->fetch())
addFile<ELFT>(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<ELF32LE>(StringRef);
template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
template void SymbolTable::scanShlibUndefined<ELF32LE>();
template void SymbolTable::scanShlibUndefined<ELF32BE>();
template void SymbolTable::scanShlibUndefined<ELF64LE>();
template void SymbolTable::scanShlibUndefined<ELF64BE>();

View File

@ -78,7 +78,6 @@ public:
InputFile *File);
template <class ELFT> void fetchIfLazy(StringRef Name);
template <class ELFT> void scanShlibUndefined();
void scanVersionScript();
Symbol *find(StringRef Name);

View File

@ -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