[lld] r263594 - [ELF] Ignore _GLOBAL_OFFSET_TABLE_ symbol in shared libs.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 15 15:24:59 PDT 2016


Author: davide
Date: Tue Mar 15 17:24:58 2016
New Revision: 263594

URL: http://llvm.org/viewvc/llvm-project?rev=263594&view=rev
Log:
[ELF] Ignore _GLOBAL_OFFSET_TABLE_ symbol in shared libs.

This fixes PR26705.

Differential Revision:  http://reviews.llvm.org/D18166

Added:
    lld/trunk/test/ELF/global_offset_table_shared.s
Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=263594&r1=263593&r2=263594&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Mar 15 17:24:58 2016
@@ -343,14 +343,15 @@ template <class ELFT> void LinkerDriver:
 
   Config->Rela = ELFT::Is64Bits;
 
-  if (!Config->Shared && !Config->Relocatable) {
+  if (Config->Entry.empty() && !Config->Shared && !Config->Relocatable &&
+      Config->EMachine != EM_AMDGPU)
     // Add entry symbol.
     //
     // There is no entry symbol for AMDGPU binaries, so skip adding one to avoid
     // having and undefined symbol.
-    if (Config->Entry.empty() && Config->EMachine != EM_AMDGPU)
-      Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
+    Config->Entry = Config->EMachine == EM_MIPS ? "__start" : "_start";
 
+  if (!Config->Relocatable)
     // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
     // is magical and is used to produce a R_386_GOTPC relocation.
     // The R_386_GOTPC relocation value doesn't actually depend on the
@@ -364,7 +365,6 @@ template <class ELFT> void LinkerDriver:
     // Given that the symbol is effectively unused, we just create a dummy
     // hidden one to avoid the undefined symbol error.
     Symtab.addIgnored("_GLOBAL_OFFSET_TABLE_");
-  }
 
   if (!Config->Entry.empty()) {
     // Set either EntryAddr (if S is a number) or EntrySym (otherwise).

Added: lld/trunk/test/ELF/global_offset_table_shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/global_offset_table_shared.s?rev=263594&view=auto
==============================================================================
--- lld/trunk/test/ELF/global_offset_table_shared.s (added)
+++ lld/trunk/test/ELF/global_offset_table_shared.s Tue Mar 15 17:24:58 2016
@@ -0,0 +1,6 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: ld.lld -shared %t -o %t2
+// RUN: llvm-readobj -t %t2 | Filecheck %s
+.long _GLOBAL_OFFSET_TABLE_
+
+// CHECK-NOT: Name: _GLOBAL_OFFSET_TABLE_




More information about the llvm-commits mailing list