[lld] r272205 - Handle gd tls relocs pointing to local symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 14:32:00 PDT 2016


Author: rafael
Date: Wed Jun  8 16:31:59 2016
New Revision: 272205

URL: http://llvm.org/viewvc/llvm-project?rev=272205&view=rev
Log:
Handle gd tls relocs pointing to local symbols.

If the symbol is local we don't need to create a R_X86_64_DTPOFF64, we
can just write the correct value in the got.

Should fix pr28018.

Added:
    lld/trunk/test/ELF/x86-64-tls-gd-local.s
Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=272205&r1=272204&r2=272205&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Jun  8 16:31:59 2016
@@ -149,8 +149,8 @@ template <class ELFT> bool GotSection<EL
     return false;
   Sym.GlobalDynIndex = Entries.size();
   // Global Dynamic TLS entries take two GOT slots.
-  Entries.push_back(&Sym);
   Entries.push_back(nullptr);
+  Entries.push_back(&Sym);
   return true;
 }
 

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=272205&r1=272204&r2=272205&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Jun  8 16:31:59 2016
@@ -136,9 +136,13 @@ static unsigned handleTlsRelocation(uint
         uintX_t Off = Out<ELFT>::Got->getGlobalDynOffset(Body);
         Out<ELFT>::RelaDyn->addReloc(
             {Target->TlsModuleIndexRel, Out<ELFT>::Got, Off, false, &Body, 0});
-        Out<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, Out<ELFT>::Got,
-                                      Off + (uintX_t)sizeof(uintX_t), false,
-                                      &Body, 0});
+
+        // If the symbol is preemptible we need the dynamic linker to write
+        // the offset too.
+        if (Body.isPreemptible())
+          Out<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, Out<ELFT>::Got,
+                                        Off + (uintX_t)sizeof(uintX_t), false,
+                                        &Body, 0});
       }
       C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
       return 1;

Added: lld/trunk/test/ELF/x86-64-tls-gd-local.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-tls-gd-local.s?rev=272205&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-tls-gd-local.s (added)
+++ lld/trunk/test/ELF/x86-64-tls-gd-local.s Wed Jun  8 16:31:59 2016
@@ -0,0 +1,52 @@
+// REQUIRES: x86
+// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-readobj -r -s -section-data %t.so | FileCheck %s
+
+        .byte   0x66
+        leaq    foo at tlsgd(%rip), %rdi
+        .value  0x6666
+        rex64
+        call    __tls_get_addr at PLT
+
+        .byte   0x66
+        leaq    bar at tlsgd(%rip), %rdi
+        .value  0x6666
+        rex64
+        call    __tls_get_addr at PLT
+
+        .section        .tbss,"awT", at nobits
+
+        .hidden foo
+        .globl  foo
+foo:
+        .zero   4
+
+        .hidden bar
+        .globl  bar
+bar:
+        .zero   4
+
+
+// CHECK:      Name: .got
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC (0x2)
+// CHECK-NEXT:   SHF_WRITE (0x1)
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x20D0
+// CHECK-NEXT: Offset: 0x20D0
+// CHECK-NEXT: Size: 32
+// CHECK-NEXT: Link: 0
+// CHECK-NEXT: Info: 0
+// CHECK-NEXT: AddressAlignment: 8
+// CHECK-NEXT: EntrySize: 0
+// CHECK-NEXT: SectionData (
+// CHECK-NEXT:   0000: 00000000 00000000 00000000 00000000  |................|
+// CHECK-NEXT:   0010: 00000000 00000000 04000000 00000000  |................|
+// CHECK-NEXT: )
+
+// CHECK:      Section ({{.*}}) .rela.dyn {
+// CHECK-NEXT:   0x20D0 R_X86_64_DTPMOD64 - 0x0
+// CHECK-NEXT:   0x20E0 R_X86_64_DTPMOD64 - 0x0
+// CHECK-NEXT: }




More information about the llvm-commits mailing list