[lld] r285279 - [ELF] Synthetic symbol definitions for ARM static linking

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 03:28:53 PDT 2016


Author: psmith
Date: Thu Oct 27 05:28:53 2016
New Revision: 285279

URL: http://llvm.org/viewvc/llvm-project?rev=285279&view=rev
Log:
[ELF] Synthetic symbol definitions for ARM static linking
    
When static linking in ARM (like Mips) __tls_get_addr is defined by
the library so we should not define it as a synthetic.
    
We also need to add __exidx_start and __exidx_end for the .ARM.exidx
section as the static libc library startup code is expecting them to
be defined by the default linker script for static linking on ARM.

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


Added:
    lld/trunk/test/ELF/arm-static-defines.s   (with props)
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=285279&r1=285278&r2=285279&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 27 05:28:53 2016
@@ -632,10 +632,11 @@ template <class ELFT> void Writer<ELFT>:
   // __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
   // __tls_get_addr, so it's not defined anywhere. Create a hidden definition
-  // to avoid the undefined symbol error. As usual as special case is MIPS -
-  // MIPS libc defines __tls_get_addr itself because there are no TLS
-  // optimizations for this target.
-  if (!Out<ELFT>::DynSymTab && Config->EMachine != EM_MIPS)
+  // to avoid the undefined symbol error. As usual special cases are ARM and
+  // MIPS - the libc for these targets defines __tls_get_addr itself because
+  // there are no TLS optimizations for these targets.
+  if (!Out<ELFT>::DynSymTab &&
+      (Config->EMachine != EM_MIPS && Config->EMachine != EM_ARM))
     Symtab<ELFT>::X->addIgnored("__tls_get_addr");
 
   // If linker script do layout we do not need to create any standart symbols.
@@ -967,6 +968,9 @@ template <class ELFT> void Writer<ELFT>:
          Out<ELFT>::PreinitArray);
   Define("__init_array_start", "__init_array_end", Out<ELFT>::InitArray);
   Define("__fini_array_start", "__fini_array_end", Out<ELFT>::FiniArray);
+
+  if (OutputSectionBase<ELFT> *Sec = findSection(".ARM.exidx"))
+    Define("__exidx_start", "__exidx_end", Sec);
 }
 
 // If a section name is valid as a C identifier (which is rare because of

Added: lld/trunk/test/ELF/arm-static-defines.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-static-defines.s?rev=285279&view=auto
==============================================================================
--- lld/trunk/test/ELF/arm-static-defines.s (added)
+++ lld/trunk/test/ELF/arm-static-defines.s Thu Oct 27 05:28:53 2016
@@ -0,0 +1,44 @@
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
+// RUN: ld.lld %t --static -o %t2 2>&1
+// RUN: llvm-readobj --symbols %t2 | FileCheck %s
+// REQUIRES: arm
+
+// Check that on ARM we don't get a multiply defined symbol for __tls_get_addr
+// and undefined symbols for references to __exidx_start and __exidx_end
+ .syntax unified
+.section .text
+ .global __tls_get_addr
+__tls_get_addr:
+ bx lr
+
+ .global _start
+ .global __exidx_start
+ .global __exidx_end
+_start:
+ .fnstart
+ bx lr
+ .word __exidx_start
+ .word __exidx_end
+ .cantunwind
+ .fnend
+
+// CHECK:          Name: __exidx_end
+// CHECK-NEXT:     Value: 0x100DC
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other [
+// CHECK-NEXT:       STV_HIDDEN
+// CHECK-NEXT:     ]
+// CHECK-NEXT:     Section: .ARM.exidx
+// CHECK:          Name: __exidx_start
+// CHECK-NEXT:     Value: 0x100D4
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other [
+// CHECK-NEXT:       STV_HIDDEN
+// CHECK-NEXT:     ]
+// CHECK-NEXT:   Section: .ARM.exidx
+// CHECK:          Symbol {
+// CHECK-NEXT:     Name: __tls_get_addr

Propchange: lld/trunk/test/ELF/arm-static-defines.s
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lld/trunk/test/ELF/arm-static-defines.s
------------------------------------------------------------------------------
    svn:keywords = Rev Date Author URL Id




More information about the llvm-commits mailing list