Skip to content

Commit 72435e5

Browse files
author
Sean Fertile
committedSep 17, 2018
[PPC64] Support relaxing R_PPC64_TLSGD16 in TlsGdtoLe relaxation.
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. Differential Revision: https://reviews.llvm.org/D52055 llvm-svn: 342411
1 parent eed3e43 commit 72435e5

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 

‎lld/ELF/Arch/PPC64.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void PPC64::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {
208208
case R_PPC64_GOT_TLSGD16_HA:
209209
writeInstrFromHalf16(Loc, 0x60000000); // nop
210210
break;
211+
case R_PPC64_GOT_TLSGD16:
211212
case R_PPC64_GOT_TLSGD16_LO:
212213
writeInstrFromHalf16(Loc, 0x3c6d0000); // addis r3, r13
213214
relocateOne(Loc, R_PPC64_TPREL16_HA, Val);

‎lld/test/ELF/ppc64-tls-gd-le-small.s

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# REQUIRES: ppc
2+
3+
# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
4+
# RUN: llvm-objdump -d -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s
5+
# RUN: ld.lld --defsym __tls_get_addr=0x1001000 %t.o -o %t
6+
# RUN: llvm-objdump -d %t | FileCheck --check-prefix=CHECK-DIS %s
7+
# RUN: llvm-readelf -relocations %t | FileCheck --check-prefix=DYN-RELOCS %s
8+
9+
# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
10+
# RUN: llvm-objdump -d -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s
11+
# RUN: ld.lld --defsym __tls_get_addr=0x1001000 %t.o -o %t
12+
# RUN: llvm-objdump -d %t | FileCheck --check-prefix=CHECK-DIS %s
13+
# RUN: llvm-readelf -relocations %t | FileCheck --check-prefix=DYN-RELOCS %s
14+
15+
# Test checks the relaxation of a 'small' general-dynamic tls access into a
16+
# local-exec tls access.
17+
18+
.text
19+
.abiversion 2
20+
21+
.global test
22+
.p2align 4
23+
.type test, @function
24+
25+
test:
26+
.Lgep:
27+
addis 2, 12, .TOC.-.Lgep@ha
28+
addi 2, 2, .TOC.-.Lgep@l
29+
.localentry test, .-test
30+
mflr 0
31+
std 0, 16(1)
32+
stdu 1, -32(1)
33+
addi 3, 2, a@got@tlsgd
34+
bl __tls_get_addr(a@tlsgd)
35+
nop
36+
lwz 3, 0(3)
37+
addi 1, 1, 32
38+
ld 0, 16(1)
39+
mtlr 0
40+
blr
41+
42+
.type a, @object
43+
.section .tdata,"awT",@progbits
44+
.global a
45+
.p2align 2
46+
a:
47+
.long 55
48+
.size a, 4
49+
50+
# CHECK-INPUT: addi 3, 2, 0
51+
# CHECK-INPUT-NEXT: R_PPC64_GOT_TLSGD16 a
52+
# CHECK-INPUT-NEXT: bl .+0
53+
# CHECK-INPUT-NEXT: R_PPC64_TLSGD a
54+
# CHECK-INPUT-NEXT: R_PPC64_REL24 __tls_get_addr
55+
56+
# CHECK-DIS: addis 3, 13, 0
57+
# CHECK-DIS-NEXT: nop
58+
# CHECK-DIS-NEXT: addi 3, 3, -28672
59+
# CHECK-DIS-NEXT: lwz 3, 0(3)
60+
61+
# DYN-RELOCS: There are no relocations in this file

0 commit comments

Comments
 (0)
Please sign in to comment.