[PATCH] D52055: [PPC64] Support relaxing R_PPC64_TLSGD16 in TlsGdtoLe relaxation
Sean Fertile via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 13 13:05:00 PDT 2018
sfertile created this revision.
sfertile added reviewers: syzaara, ruiu, MaskRay, rdhindsa.
Herald added subscribers: kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
A General-dynamic tls access can be written using a R_PPC64_TLSGD16 relocation if the target got entry is within 16 bits of the TOC-base. This patch adds support for `R_PPC64_TLSGD16` by relaxing it the same as a `R_PPC64_GOT_TLSGD16_LO`, ie rewriting the instruction to an `addis 3, 13, a at tprel@ha`. The full transformation is:
gd: le:
addi 3,2,a at got@tlsgd --> addis 3, 13, a at tprel@ha
bl __tls_get_addr(a at tlsgd) --> nop
nop --> addi 3, 3, a at tprel@l
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D52055
Files:
ELF/Arch/PPC64.cpp
test/ELF/ppc64-tls-gd-le-small.s
Index: test/ELF/ppc64-tls-gd-le-small.s
===================================================================
--- /dev/null
+++ test/ELF/ppc64-tls-gd-le-small.s
@@ -0,0 +1,61 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
+# RUN: llvm-objdump -d -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s
+# RUN: ld.lld --defsym __tls_get_addr=0x1001000 %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck --check-prefix=CHECK-DIS %s
+# RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=DYN-RELOCS %s
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+# RUN: llvm-objdump -d -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s
+# RUN: ld.lld --defsym __tls_get_addr=0x1001000 %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck --check-prefix=CHECK-DIS %s
+# RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=DYN-RELOCS %s
+
+# Test checks the relaxation of a 'small' general-dynamic tls access into a
+# local-exec tls access.
+
+ .text
+ .abiversion 2
+
+ .global test
+ .p2align 4
+ .type test, @function
+
+test:
+.Lgep:
+ addis 2, 12, .TOC.-.Lgep at ha
+ addi 2, 2, .TOC.-.Lgep at l
+ .localentry test, .-test
+ mflr 0
+ std 0, 16(1)
+ stdu 1, -32(1)
+ addi 3, 2, a at got@tlsgd
+ bl __tls_get_addr(a at tlsgd)
+ nop
+ lwz 3, 0(3)
+ addi 1, 1, 32
+ ld 0, 16(1)
+ mtlr 0
+ blr
+
+ .type a, @object
+ .section .tdata,"awT", at progbits
+ .global a
+ .p2align 2
+a:
+ .long 55
+ .size a, 4
+
+# CHECK-INPUT: addi 3, 2, 0
+# CHECK-INPUT-NEXT: R_PPC64_GOT_TLSGD16 a
+# CHECK-INPUT-NEXT: bl .+0
+# CHECK-INPUT-NEXT: R_PPC64_TLSGD a
+# CHECK-INPUT-NEXT: R_PPC64_REL24 __tls_get_addr
+
+# CHECK-DIS: addis 3, 13, 0
+# CHECK-DIS-NEXT: nop
+# CHECK-DIS-NEXT: addi 3, 3, -28672
+# CHECK-DIS-NEXT: lwz 3, 0(3)
+
+# DYN-RELOCS: There are no relocations in this file
Index: ELF/Arch/PPC64.cpp
===================================================================
--- ELF/Arch/PPC64.cpp
+++ ELF/Arch/PPC64.cpp
@@ -197,6 +197,7 @@
case R_PPC64_GOT_TLSGD16_HA:
write32(Loc - EndianOffset, 0x60000000); // nop
break;
+ case R_PPC64_GOT_TLSGD16:
case R_PPC64_GOT_TLSGD16_LO:
write32(Loc - EndianOffset, 0x3c6d0000); // addis r3, r13
relocateOne(Loc, R_PPC64_TPREL16_HA, Val);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52055.165357.patch
Type: text/x-patch
Size: 2423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180913/57c66aa2/attachment.bin>
More information about the llvm-commits
mailing list