[lld] r286941 - [ELF] - Do not create reserved symbols in case of relocatable output.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 00:19:03 PST 2016


Author: grimar
Date: Tue Nov 15 02:19:02 2016
New Revision: 286941

URL: http://llvm.org/viewvc/llvm-project?rev=286941&view=rev
Log:
[ELF] - Do not create reserved symbols in case of relocatable output.

This patch stops creating symbols like __ehdr_start, 
_end/_etext_edata,__tls_get_addr when using -r.

This fixes PR30984.

Differential revision: https://reviews.llvm.org/D26600

Added:
    lld/trunk/test/ELF/Inputs/relocatable-tls.s
    lld/trunk/test/ELF/relocatable-tls.s
Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/edata-etext.s
    lld/trunk/test/ELF/ehdr_start.s
    lld/trunk/test/ELF/end.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=286941&r1=286940&r2=286941&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Nov 15 02:19:02 2016
@@ -134,7 +134,9 @@ template <class ELFT> void elf::writeRes
 // The main function of the writer.
 template <class ELFT> void Writer<ELFT>::run() {
   createSyntheticSections();
-  addReservedSymbols();
+
+  if (!Config->Relocatable)
+    addReservedSymbols();
 
   if (Target->NeedsThunks)
     forEachRelSec(createThunks<ELFT>);
@@ -604,7 +606,7 @@ template <class ELFT> void Writer<ELFT>:
 // The linker is expected to define some symbols depending on
 // the linking result. This function defines such symbols.
 template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
-  if (Config->EMachine == EM_MIPS && !Config->Relocatable) {
+  if (Config->EMachine == EM_MIPS) {
     // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer
     // so that it points to an absolute address which is relative to GOT.
     // See "Global Data Symbols" in Chapter 6 in the following document:
@@ -636,8 +638,7 @@ template <class ELFT> void Writer<ELFT>:
   // an undefined symbol in the .o files.
   // Given that the symbol is effectively unused, we just create a dummy
   // hidden one to avoid the undefined symbol error.
-  if (!Config->Relocatable)
-    Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
+  Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
 
   // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
   // static linking the linker is required to optimize away any references to

Added: lld/trunk/test/ELF/Inputs/relocatable-tls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/relocatable-tls.s?rev=286941&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/relocatable-tls.s (added)
+++ lld/trunk/test/ELF/Inputs/relocatable-tls.s Tue Nov 15 02:19:02 2016
@@ -0,0 +1 @@
+callq __tls_get_addr at PLT

Modified: lld/trunk/test/ELF/edata-etext.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/edata-etext.s?rev=286941&r1=286940&r2=286941&view=diff
==============================================================================
--- lld/trunk/test/ELF/edata-etext.s (original)
+++ lld/trunk/test/ELF/edata-etext.s Tue Nov 15 02:19:02 2016
@@ -23,6 +23,12 @@
 # CHECK-NEXT:  0000000000011001         *ABS* 00000000 _etext
 # CHECK-NEXT:  0000000000011000         .text 00000000 _start
 
+# RUN: ld.lld -r %t.o -o %t2
+# RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE
+# RELOCATABLE:       0000000000000000 *UND* 00000000 _edata
+# RELOCATABLE-NEXT:  0000000000000000 *UND* 00000000 _end
+# RELOCATABLE-NEXT:  0000000000000000 *UND* 00000000 _etext
+
 .global _start,_end,_etext,_edata
 .text
 _start:

Modified: lld/trunk/test/ELF/ehdr_start.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ehdr_start.s?rev=286941&r1=286940&r2=286941&view=diff
==============================================================================
--- lld/trunk/test/ELF/ehdr_start.s (original)
+++ lld/trunk/test/ELF/ehdr_start.s Tue Nov 15 02:19:02 2016
@@ -9,3 +9,8 @@
 .global _start, __ehdr_start
 _start:
   .quad __ehdr_start
+
+# RUN: ld.lld -r %t.o -o %t.r
+# RUN: llvm-objdump -t %t.r | FileCheck %s --check-prefix=RELOCATABLE
+
+# RELOCATABLE: 0000000000000000 *UND* 00000000 __ehdr_start

Modified: lld/trunk/test/ELF/end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/end.s?rev=286941&r1=286940&r2=286941&view=diff
==============================================================================
--- lld/trunk/test/ELF/end.s (original)
+++ lld/trunk/test/ELF/end.s Tue Nov 15 02:19:02 2016
@@ -23,6 +23,10 @@
 // DEFAULT-NEXT:     Value: 0x12008
 // DEFAULT: ]
 
+// RUN: ld.lld -r %t.o -o %t2
+// RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE
+// RELOCATABLE: 0000000000000000 *UND* 00000000 _end
+
 .global _start,_end
 .text
 _start:

Added: lld/trunk/test/ELF/relocatable-tls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-tls.s?rev=286941&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-tls.s (added)
+++ lld/trunk/test/ELF/relocatable-tls.s Tue Nov 15 02:19:02 2016
@@ -0,0 +1,15 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
+# RUN:   %S/Inputs/relocatable-tls.s -o %t2.o
+
+# RUN: ld.lld -r %t2.o -o %t3.r
+# RUN: llvm-objdump -t %t3.r | FileCheck --check-prefix=RELOCATABLE %s
+# RELOCATABLE: SYMBOL TABLE:
+# RELOCATABLE: 0000000000000000 *UND* 00000000 __tls_get_addr
+
+# RUN: ld.lld -shared %t2.o %t3.r -o %t4.out
+# RUN: llvm-objdump -t %t4.out | FileCheck --check-prefix=DSO %s
+# DSO: SYMBOL TABLE:
+# DSO: 0000000000000000 *UND* 00000000 __tls_get_addr
+
+callq __tls_get_addr at PLT




More information about the llvm-commits mailing list