[lld] r333769 - [PPC64] Add support for initial-exec TLS model
Zaara Syeda via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 1 08:20:57 PDT 2018
Author: syzaara
Date: Fri Jun 1 08:20:56 2018
New Revision: 333769
URL: http://llvm.org/viewvc/llvm-project?rev=333769&view=rev
Log:
[PPC64] Add support for initial-exec TLS model
This patch adds the relocations needed support the initial-exec TLS model:
R_PPC64_GOT_TPREL16_HA
R_PPC64_GOT_TPREL16_LO_DS
R_PPC64_GOT_TPREL16_DS
R_PPC64_GOT_TPREL16_HI
R_PPC64_TLS
Differential Revision: https://reviews.llvm.org/D47455
Added:
lld/trunk/test/ELF/Inputs/ppc64-tls.s
lld/trunk/test/ELF/ppc64-initial-exec-tls.s
Modified:
lld/trunk/ELF/Arch/PPC64.cpp
Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=333769&r1=333768&r2=333769&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Fri Jun 1 08:20:56 2018
@@ -83,6 +83,8 @@ PPC64::PPC64() {
TlsModuleIndexRel = R_PPC64_DTPMOD64;
TlsOffsetRel = R_PPC64_DTPREL64;
+ TlsGotRel = R_PPC64_TPREL64;
+
// We need 64K pages (at least under glibc/Linux, the loader won't
// set different permissions on a finer granularity than that).
DefaultMaxPageSize = 65536;
@@ -180,8 +182,14 @@ RelExpr PPC64::getRelExpr(RelType Type,
case R_PPC64_GOT_TLSLD16_HI:
case R_PPC64_GOT_TLSLD16_LO:
return R_TLSLD_GOT;
+ case R_PPC64_GOT_TPREL16_HA:
+ case R_PPC64_GOT_TPREL16_LO_DS:
+ case R_PPC64_GOT_TPREL16_DS:
+ case R_PPC64_GOT_TPREL16_HI:
+ return R_GOT_OFF;
case R_PPC64_TLSGD:
case R_PPC64_TLSLD:
+ case R_PPC64_TLS:
return R_HINT;
default:
return R_ABS;
@@ -231,13 +239,16 @@ static std::pair<RelType, uint64_t> toAd
case R_PPC64_TOC16:
return {R_PPC64_ADDR16, V};
case R_PPC64_TOC16_DS:
+ case R_PPC64_GOT_TPREL16_DS:
return {R_PPC64_ADDR16_DS, V};
case R_PPC64_GOT_TLSGD16_HA:
case R_PPC64_GOT_TLSLD16_HA:
+ case R_PPC64_GOT_TPREL16_HA:
case R_PPC64_TOC16_HA:
return {R_PPC64_ADDR16_HA, V};
case R_PPC64_GOT_TLSGD16_HI:
case R_PPC64_GOT_TLSLD16_HI:
+ case R_PPC64_GOT_TPREL16_HI:
case R_PPC64_TOC16_HI:
return {R_PPC64_ADDR16_HI, V};
case R_PPC64_GOT_TLSGD16_LO:
@@ -245,6 +256,7 @@ static std::pair<RelType, uint64_t> toAd
case R_PPC64_TOC16_LO:
return {R_PPC64_ADDR16_LO, V};
case R_PPC64_TOC16_LO_DS:
+ case R_PPC64_GOT_TPREL16_LO_DS:
return {R_PPC64_ADDR16_LO_DS, V};
default:
return {Type, Val};
Added: lld/trunk/test/ELF/Inputs/ppc64-tls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/ppc64-tls.s?rev=333769&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/ppc64-tls.s (added)
+++ lld/trunk/test/ELF/Inputs/ppc64-tls.s Fri Jun 1 08:20:56 2018
@@ -0,0 +1,20 @@
+ .text
+ .abiversion 2
+ .type a, at object # @a
+ .type b, at object # @a
+ .type c, at object # @a
+ .section .tdata,"awT", at progbits
+ .globl a
+a:
+ .long 10 # 0xa
+ .size a, 4
+
+ .globl b
+b:
+ .long 10 # 0xa
+ .size b, 4
+
+ .globl c
+c:
+ .long 10 # 0xa
+ .size c, 4
Added: lld/trunk/test/ELF/ppc64-initial-exec-tls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-initial-exec-tls.s?rev=333769&view=auto
==============================================================================
--- lld/trunk/test/ELF/ppc64-initial-exec-tls.s (added)
+++ lld/trunk/test/ELF/ppc64-initial-exec-tls.s Fri Jun 1 08:20:56 2018
@@ -0,0 +1,102 @@
+// REQUIRES: ppc
+
+// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t2.so
+// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t
+// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s
+// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s
+// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s
+// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s
+
+// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t2.so
+// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t
+// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s
+// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s
+// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s
+// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s
+
+ .text
+ .abiversion 2
+ .file "intial_exec.c"
+ .globl test_initial_exec # -- Begin function test_initial_exec
+ .p2align 4
+ .type test_initial_exec, at function
+test_initial_exec: # @test_initial_exec
+.Lfunc_begin0:
+.Lfunc_gep0:
+ addis 2, 12, .TOC.-.Lfunc_gep0 at ha
+ addi 2, 2, .TOC.-.Lfunc_gep0 at l
+.Lfunc_lep0:
+ .localentry test_initial_exec, .Lfunc_lep0-.Lfunc_gep0
+# %bb.0: # %entry
+ li 3, 0
+ stw 3, -12(1)
+ addis 3, 2, a at got@tprel at ha
+ ld 3, a at got@tprel at l(3)
+ lwzx 4, 3, a at tls
+ extsw 3, 4
+ blr
+
+
+test_hi:
+.Lfunc_gep1:
+ addis 2, 12, .TOC.-.Lfunc_gep1 at ha
+ addi 2, 2, .TOC.-.Lfunc_gep1 at l
+.Lfunc_lep1:
+ .localentry test2, .Lfunc_lep1-.Lfunc_gep1
+ addis 3, 0, b at got@tprel at h
+ blr
+
+test_ds:
+.Lfunc_gep2:
+ addis 2, 12, .TOC.-.Lfunc_gep2 at ha
+ addi 2, 2, .TOC.-.Lfunc_gep2 at l
+.Lfunc_lep2:
+ .localentry test16, .Lfunc_lep2-.Lfunc_gep2
+ addi 3, 0, c at got@tprel
+ blr
+
+// Verify that the input has every initial-exec tls relocation type.
+// InputRelocs: Relocation section '.rela.text'
+// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} a + 0
+// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} a + 0
+// InputRelocs: R_PPC64_TLS {{0+}} a + 0
+// InputRelocs: R_PPC64_GOT_TPREL16_HI {{0+}} b + 0
+// InputRelocs: R_PPC64_GOT_TPREL16_DS {{0+}} c + 0
+
+// There is a got entry for each tls variable that is accessed with the
+// initial-exec model to be filled in by the dynamic linker.
+// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 3 entries:
+// OutputRelocs: R_PPC64_TPREL64 {{0+}} a + 0
+// OutputRelocs: R_PPC64_TPREL64 {{0+}} b + 0
+// OutputRelocs: R_PPC64_TPREL64 {{0+}} c + 0
+
+// Check that the got has 4 entires. (1 for the TOC and 3 entries for TLS
+// variables). Also verify the address so we can check
+// the offsets we calculated for each relocation type.
+// CheckGot: got 00000020 00000000100200c0
+
+// GOT stats at 0x100200c0, so TOC will be 0x100280c0
+
+// We are building the address of the first TLS got entry which contains the
+// offset of the tls variable relative to the thread pointer.
+// 0x100200c8 (got[1]).
+// #ha(a at got@tprel) --> (0x100200c8 - 0x100280c0 + 0x8000) >> 16 = 0
+// #lo(a at got@tprel)) --> (0x100200c8 - 0x100280c0) & 0xFFFF = -7ff8 = -32760
+// Dis: test_initial_exec:
+// Dis: addis 3, 2, 0
+// Dis: ld 3, -32760(3)
+// Dis: lwzx 4, 3, 13
+
+// Second TLS got entry starts at got[2] 0x100200d0
+// #hi(b at got@tprel) --> (0x100200d0 - 0x100280c0) >> 16 = -1
+// Dis: test_hi:
+// Dis: lis 3, -1
+
+// Third TLS got entry starts at got[3] 0x100200d8.
+// c at got@tprel--> (0x100200d8. - 0x100280c0) = -0x7fe8 = 32744
+// Dis: test_ds:
+// Dis: li 3, -32744
More information about the llvm-commits
mailing list