[lld] r326242 - Put undefined symbols from shared libraries in the symbol table.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 12:31:22 PST 2018


Author: rafael
Date: Tue Feb 27 12:31:22 2018
New Revision: 326242

URL: http://llvm.org/viewvc/llvm-project?rev=326242&view=rev
Log:
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.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/test/ELF/trace-symbols.s

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Feb 27 12:31:22 2018
@@ -1085,10 +1085,6 @@ template <class ELFT> void LinkerDriver:
   // 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);

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Feb 27 12:31:22 2018
@@ -851,7 +851,10 @@ template <class ELFT> void SharedFile<EL
 
     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;
     }
 

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Feb 27 12:31:22 2018
@@ -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;

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Feb 27 12:31:22 2018
@@ -129,10 +129,6 @@ static bool shouldDefineSym(SymbolAssign
   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;
 }
 

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Feb 27 12:31:22 2018
@@ -588,29 +588,6 @@ template <class ELFT> void SymbolTable::
   }
 }
 
-// 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<E
 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>();

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Feb 27 12:31:22 2018
@@ -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);

Modified: lld/trunk/test/ELF/trace-symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/trace-symbols.s?rev=326242&r1=326241&r2=326242&view=diff
==============================================================================
--- lld/trunk/test/ELF/trace-symbols.s (original)
+++ lld/trunk/test/ELF/trace-symbols.s Tue Feb 27 12:31:22 2018
@@ -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




More information about the llvm-commits mailing list