[lld] r292429 - Port r291944.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 12:00:59 PST 2017


Author: rafael
Date: Wed Jan 18 14:00:59 2017
New Revision: 292429

URL: http://llvm.org/viewvc/llvm-project?rev=292429&view=rev
Log:
Port r291944.

Don't add DT_INIT/DT_FINI for undef and shared symbols.

The freebsd dynamic linker doesn't check if the value is null (and it
is reasonable for it to do that). That means that producing a .so with
a null DT_INIT/DT_FINI causes the base address to be called.

This should fix the libreoffice build.

Modified:
    lld/branches/release_40/ELF/SymbolTable.cpp
    lld/branches/release_40/ELF/SymbolTable.h
    lld/branches/release_40/ELF/SyntheticSections.cpp
    lld/branches/release_40/test/ELF/init-fini.s

Modified: lld/branches/release_40/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/SymbolTable.cpp?rev=292429&r1=292428&r2=292429&view=diff
==============================================================================
--- lld/branches/release_40/ELF/SymbolTable.cpp (original)
+++ lld/branches/release_40/ELF/SymbolTable.cpp Wed Jan 18 14:00:59 2017
@@ -464,6 +464,14 @@ template <class ELFT> SymbolBody *Symbol
 }
 
 template <class ELFT>
+SymbolBody *SymbolTable<ELFT>::findDefined(StringRef Name) {
+  if (SymbolBody *S = find(Name))
+    if (S->isDefined() && !S->isShared())
+      return S;
+  return nullptr;
+}
+
+template <class ELFT>
 void SymbolTable<ELFT>::addLazyArchive(ArchiveFile *F,
                                        const object::Archive::Symbol Sym) {
   Symbol *S;

Modified: lld/branches/release_40/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/SymbolTable.h?rev=292429&r1=292428&r2=292429&view=diff
==============================================================================
--- lld/branches/release_40/ELF/SymbolTable.h (original)
+++ lld/branches/release_40/ELF/SymbolTable.h Wed Jan 18 14:00:59 2017
@@ -82,6 +82,7 @@ public:
   void scanVersionScript();
 
   SymbolBody *find(StringRef Name);
+  SymbolBody *findDefined(StringRef Name);
 
   void trace(StringRef Name);
   void wrap(StringRef Name);

Modified: lld/branches/release_40/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/SyntheticSections.cpp?rev=292429&r1=292428&r2=292429&view=diff
==============================================================================
--- lld/branches/release_40/ELF/SyntheticSections.cpp (original)
+++ lld/branches/release_40/ELF/SyntheticSections.cpp Wed Jan 18 14:00:59 2017
@@ -883,9 +883,9 @@ template <class ELFT> void DynamicSectio
     add({DT_FINI_ARRAYSZ, Out<ELFT>::FiniArray, Entry::SecSize});
   }
 
-  if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Init))
+  if (SymbolBody *B = Symtab<ELFT>::X->findDefined(Config->Init))
     add({DT_INIT, B});
-  if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Fini))
+  if (SymbolBody *B = Symtab<ELFT>::X->findDefined(Config->Fini))
     add({DT_FINI, B});
 
   bool HasVerNeed = In<ELFT>::VerNeed->getNeedNum() != 0;

Modified: lld/branches/release_40/test/ELF/init-fini.s
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/test/ELF/init-fini.s?rev=292429&r1=292428&r2=292429&view=diff
==============================================================================
--- lld/branches/release_40/test/ELF/init-fini.s (original)
+++ lld/branches/release_40/test/ELF/init-fini.s Wed Jan 18 14:00:59 2017
@@ -17,11 +17,22 @@
 // RUN: ld.lld -shared %t -o %t2 -init=_foo -fini=_bar
 // RUN: llvm-readobj -dynamic-table %t2 | FileCheck --check-prefix=OVR %s
 
-// Should add a dynamic table entry even if a given symbol stay undefined
+// Don't add an entry for undef. The freebsd dynamic linker doesn't
+// check if the value is null. If it is, it will just call the
+// load address.
 // RUN: ld.lld -shared %t -o %t2 -init=_undef -fini=_undef
 // RUN: llvm-readobj -dynamic-table %t2 | FileCheck --check-prefix=UNDEF %s
-// UNDEF: INIT 0x0
-// UNDEF: FINI 0x0
+// UNDEF-NOT: INIT
+// UNDEF-NOT: FINI
+
+// Don't add an entry for shared. For the same reason as undef.
+// RUN: ld.lld -shared %t -o %t.so
+// RUN: echo > %t.s
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t2.o
+// RUN: ld.lld -shared %t2.o %t.so -o %t2
+// RUN: llvm-readobj -dynamic-table %t2 | FileCheck --check-prefix=SHARED %s
+// SHARED-NOT: INIT
+// SHARED-NOT: FINI
 
 // Should not add new entries to the symbol table
 // and should not require given symbols to be resolved




More information about the llvm-commits mailing list