Skip to content

Commit 3f4c673

Browse files
committed
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
1 parent bf28a8f commit 3f4c673

File tree

7 files changed

+5
-47
lines changed

7 files changed

+5
-47
lines changed

lld/ELF/Driver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
10851085
// They also might be exported if referenced by DSOs.
10861086
Script->declareSymbols();
10871087

1088-
// Handle undefined symbols in DSOs.
1089-
if (!Config->Shared)
1090-
Symtab->scanShlibUndefined<ELFT>();
1091-
10921088
// Handle the -exclude-libs option.
10931089
if (Args.hasArg(OPT_exclude_libs))
10941090
excludeLibs<ELFT>(Args);

lld/ELF/InputFiles.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,10 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
851851

852852
StringRef Name = CHECK(Sym.getName(this->StringTable), this);
853853
if (Sym.isUndefined()) {
854-
this->Undefs.insert(Name);
854+
Symbol *S = Symtab->addUndefined<ELFT>(Name, Sym.getBinding(),
855+
Sym.st_other, Sym.getType(),
856+
/*CanOmitFromDynSym=*/false, this);
857+
S->ExportDynamic = true;
855858
continue;
856859
}
857860

lld/ELF/InputFiles.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ class InputFile {
9393
return Symbols;
9494
}
9595

96-
// Returns undefined symbols of a shared library.
97-
// It is a runtime error to call this function on files of other types.
98-
const llvm::DenseSet<StringRef> &getUndefinedSymbols() {
99-
assert(FileKind == SharedKind);
100-
return Undefs;
101-
}
102-
10396
// Filename of .a which contained this file. If this file was
10497
// not in an archive file, it is the empty string. We use this
10598
// string for creating error messages.
@@ -121,7 +114,6 @@ class InputFile {
121114
InputFile(Kind K, MemoryBufferRef M);
122115
std::vector<InputSectionBase *> Sections;
123116
std::vector<Symbol *> Symbols;
124-
llvm::DenseSet<StringRef> Undefs;
125117

126118
private:
127119
const Kind FileKind;

lld/ELF/LinkerScript.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ static bool shouldDefineSym(SymbolAssignment *Cmd) {
129129
Symbol *B = Symtab->find(Cmd->Name);
130130
if (B && !B->isDefined())
131131
return true;
132-
// It might also be referenced by a DSO.
133-
for (InputFile *F : SharedFiles)
134-
if (F->getUndefinedSymbols().count(Cmd->Name))
135-
return true;
136132
return false;
137133
}
138134

lld/ELF/SymbolTable.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -588,29 +588,6 @@ template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
588588
}
589589
}
590590

591-
// This function takes care of the case in which shared libraries depend on
592-
// the user program (not the other way, which is usual). Shared libraries
593-
// may have undefined symbols, expecting that the user program provides
594-
// the definitions for them. An example is BSD's __progname symbol.
595-
// We need to put such symbols to the main program's .dynsym so that
596-
// shared libraries can find them.
597-
// Except this, we ignore undefined symbols in DSOs.
598-
template <class ELFT> void SymbolTable::scanShlibUndefined() {
599-
for (InputFile *F : SharedFiles) {
600-
for (StringRef U : F->getUndefinedSymbols()) {
601-
Symbol *Sym = find(U);
602-
if (!Sym)
603-
continue;
604-
if (auto *L = dyn_cast<Lazy>(Sym))
605-
if (InputFile *File = L->fetch())
606-
addFile<ELFT>(File);
607-
608-
if (Sym->isDefined())
609-
Sym->ExportDynamic = true;
610-
}
611-
}
612-
}
613-
614591
// Initialize DemangledSyms with a map from demangled symbols to symbol
615592
// objects. Used to handle "extern C++" directive in version scripts.
616593
//
@@ -836,8 +813,3 @@ template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
836813
template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
837814
template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
838815
template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
839-
840-
template void SymbolTable::scanShlibUndefined<ELF32LE>();
841-
template void SymbolTable::scanShlibUndefined<ELF32BE>();
842-
template void SymbolTable::scanShlibUndefined<ELF64LE>();
843-
template void SymbolTable::scanShlibUndefined<ELF64BE>();

lld/ELF/SymbolTable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class SymbolTable {
7878
InputFile *File);
7979

8080
template <class ELFT> void fetchIfLazy(StringRef Name);
81-
template <class ELFT> void scanShlibUndefined();
8281
void scanVersionScript();
8382

8483
Symbol *find(StringRef Name);

lld/test/ELF/trace-symbols.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
# RUN: ld.lld -y foo -y bar %t %t1.so %t2.so -o %t3 | \
7171
# RUN: FileCheck -check-prefix=SHLIBRBAR %s
72-
# SHLIBRBAR-NOT: trace-symbols.s.tmp1.so: reference to bar
72+
# SHLIBRBAR: trace-symbols.s.tmp1.so: reference to bar
7373

7474
# RUN: ld.lld -y foo -y bar %t -u bar --start-lib %t1 %t2 --end-lib -o %t3 | \
7575
# RUN: FileCheck -check-prefix=STARTLIB %s

0 commit comments

Comments
 (0)