[lld] r254500 - [ELF] - Implemented some GD, LD and IE TLS access models for x86 target.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 01:58:21 PST 2015


Author: grimar
Date: Wed Dec  2 03:58:20 2015
New Revision: 254500

URL: http://llvm.org/viewvc/llvm-project?rev=254500&view=rev
Log:
[ELF] - Implemented some GD, LD and IE TLS access models for x86 target.

Main aim of the patch to introduce basic support for TLS access models for x86 target.
Models using @tlsgd, @tlsldm and @gotntpoff are implemented.

Differential revision: http://reviews.llvm.org/D15060

Added:
    lld/trunk/test/ELF/tls-dynamic-i686.s
Modified:
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=254500&r1=254499&r2=254500&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Dec  2 03:58:20 2015
@@ -123,6 +123,7 @@ public:
   bool empty() const { return Entries.empty(); }
   uintX_t getEntryAddr(const SymbolBody &B) const;
   uintX_t getGlobalDynAddr(const SymbolBody &B) const;
+  uintX_t getNumEntries() const { return Entries.size(); }
 
   // Returns the symbol which corresponds to the first entry of the global part
   // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=254500&r1=254499&r2=254500&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Dec  2 03:58:20 2015
@@ -224,6 +224,11 @@ X86TargetInfo::X86TargetInfo() {
   PCRelReloc = R_386_PC32;
   GotReloc = R_386_GLOB_DAT;
   PltReloc = R_386_JUMP_SLOT;
+  TlsGotReloc = R_386_TLS_TPOFF;
+  TlsGlobalDynamicReloc = R_386_TLS_GD;
+  TlsLocalDynamicReloc = R_386_TLS_LDM;
+  TlsModuleIndexReloc = R_386_TLS_DTPMOD32;
+  TlsOffsetReloc = R_386_TLS_DTPOFF32;
   LazyRelocations = true;
   PltEntrySize = 16;
   PltZeroEntrySize = 16;
@@ -247,7 +252,8 @@ unsigned X86TargetInfo::getDynReloc(unsi
 }
 
 bool X86TargetInfo::isTlsDynReloc(unsigned Type) const {
-  if (Type == R_386_TLS_LE || Type == R_386_TLS_LE_32)
+  if (Type == R_386_TLS_LE || Type == R_386_TLS_LE_32 ||
+      Type == R_386_TLS_GOTIE)
     return Config->Shared;
   return false;
 }
@@ -300,7 +306,8 @@ bool X86TargetInfo::relocNeedsCopy(uint3
 }
 
 bool X86TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
-  return Type == R_386_GOT32 || relocNeedsPlt(Type, S);
+  return Type == R_386_TLS_GOTIE || Type == R_386_GOT32 ||
+         relocNeedsPlt(Type, S);
 }
 
 bool X86TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
@@ -323,6 +330,18 @@ void X86TargetInfo::relocateOne(uint8_t
   case R_386_PC32:
     add32le(Loc, SA - P);
     break;
+  case R_386_TLS_GD:
+  case R_386_TLS_LDM:
+  case R_386_TLS_TPOFF: {
+    uint64_t V = SA - Out<ELF32LE>::Got->getVA() -
+                 Out<ELF32LE>::Got->getNumEntries() * 4;
+    checkInt<32>(V, Type);
+    write32le(Loc, V);
+    break;
+  }
+  case R_386_TLS_LDO_32:
+    write32le(Loc, SA);
+    break;
   case R_386_TLS_LE:
     write32le(Loc, SA - Out<ELF32LE>::TlsPhdr->p_memsz);
     break;

Added: lld/trunk/test/ELF/tls-dynamic-i686.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-dynamic-i686.s?rev=254500&view=auto
==============================================================================
--- lld/trunk/test/ELF/tls-dynamic-i686.s (added)
+++ lld/trunk/test/ELF/tls-dynamic-i686.s Wed Dec  2 03:58:20 2015
@@ -0,0 +1,92 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t
+// RUN: ld.lld -shared %t -o %tout
+// RUN: llvm-readobj -sections -relocations %tout | FileCheck %s
+// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DIS
+
+.type tls0, at object
+.section .tbss,"awT", at nobits
+.globl tls0
+.align 4
+tls0:
+ .long 0
+ .size tls0, 4
+
+.type  tls1, at object
+.globl tls1
+.align 4
+tls1:
+ .long 0
+ .size tls1, 4
+
+.section .text
+.globl _start
+_start:
+leal tls0 at tlsgd(,%ebx,1),%eax
+call __tls_get_addr at plt
+
+leal tls1 at tlsgd(,%ebx,1),%eax
+call __tls_get_addr at plt
+
+leal tls0 at tlsldm(%ebx),%eax
+call __tls_get_addr at plt
+leal tls0 at dtpoff(%eax),%edx
+
+leal tls1 at tlsldm(%ebx),%eax
+call __tls_get_addr at plt
+leal tls1 at dtpoff(%eax),%edx
+
+movl %gs:0,%eax
+addl tls0 at gotntpoff(%ebx),%eax
+
+movl %gs:0,%eax
+addl tls1 at gotntpoff(%ebx),%eax
+
+// CHECK:      Index: 10
+// CHECK-NEXT: Name: .got
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x2068
+// CHECK-NEXT: Offset: 0x2068
+// CHECK-NEXT: Size: 32
+// CHECK-NEXT: Link: 0
+// CHECK-NEXT: Info: 0
+// CHECK-NEXT: AddressAlignment: 4
+// CHECK-NEXT: EntrySize: 0
+
+// CHECK: Relocations [
+// CHECK:      Section ({{.+}}) .rel.dyn {
+// CHECK-NEXT: 0x2068 R_386_TLS_DTPMOD32 tls0 0x0
+// CHECK-NEXT: 0x206C R_386_TLS_DTPOFF32 tls0 0x0
+// CHECK-NEXT: 0x2070 R_386_TLS_DTPMOD32 tls1 0x0
+// CHECK-NEXT: 0x2074 R_386_TLS_DTPOFF32 tls1 0x0
+// CHECK-NEXT: 0x2078 R_386_TLS_DTPMOD32 - 0x0
+// CHECK-NEXT: 0x2080 R_386_TLS_TPOFF tls0 0x0
+// CHECK-NEXT: 0x2084 R_386_TLS_TPOFF tls1 0x0
+// CHECK-NEXT: }
+
+// DIS:      Disassembly of section .text:
+// DIS-NEXT: _start:
+// General dynamic model:
+// -32 and -24 are first and second GOT entries offsets.
+// Each one is a pair of records.
+// DIS-NEXT: 1000: 8d 04 1d e0 ff ff ff  leal -32(,%ebx), %eax
+// DIS-NEXT: 1007: e8 64 00 00 00        calll 100
+// DIS-NEXT: 100c: 8d 04 1d e8 ff ff ff  leal -24(,%ebx), %eax
+// DIS-NEXT: 1013: e8 58 00 00 00        calll 88
+// Local dynamic model:
+// -16 is a local module tls index offset.
+// DIS-NEXT: 1018: 8d 83 f0 ff ff ff leal -16(%ebx), %eax
+// DIS-NEXT: 101e: e8 4d 00 00 00    calll 77
+// DIS-NEXT: 1023: 8d 90 00 00 00 00 leal (%eax), %edx
+// DIS-NEXT: 1029: 8d 83 f0 ff ff ff leal -16(%ebx), %eax
+// DIS-NEXT: 102f: e8 3c 00 00 00    calll 60
+// DIS-NEXT: 1034: 8d 90 04 00 00 00 leal 4(%eax), %edx
+// Initial exec model:
+// DIS-NEXT: 103a: 65 a1 00 00 00 00 movl %gs:0, %eax
+// DIS-NEXT: 1040: 03 83 f8 ff ff ff addl -8(%ebx), %eax
+// DIS-NEXT: 1046: 65 a1 00 00 00 00 movl %gs:0, %eax
+// DIS-NEXT: 104c: 03 83 fc ff ff ff addl -4(%ebx), %eax




More information about the llvm-commits mailing list