Skip to content

Commit 99a9923

Browse files
committedApr 7, 2017
[ELF] Fix ARM TLS global dynamic TlsOffsetRel for non-preemtible symbols
When the target of the TlsOffsetRel is non-preemptible we can write the offset directly into the GOT without needing a dynamic relocation. This is optional for dynamically linked executables but is required for static linking. This change adds the relocation to the GOT entry and a test case for non-0 offsets so that if we miss out the offset the test won't spuriously pass by virtue of the default value being 0. Differential Revision: https://reviews.llvm.org/D31749 llvm-svn: 299751
1 parent a630d0f commit 99a9923

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
 

‎lld/ELF/Relocations.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ static unsigned handleARMTlsRelocation(GotSection<ELFT> *Got, uint32_t Type,
181181
if (Body.isPreemptible())
182182
In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, Got,
183183
Off + Config->Wordsize, false, &Body, 0});
184+
else
185+
Got->Relocations.push_back(
186+
{R_ABS, R_ARM_ABS32, Off + Config->Wordsize, 0, &Body});
184187
}
185188
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
186189
return 1;
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
2+
// RUN: ld.lld %t -o %t2
3+
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi
4+
// RUN: llvm-objdump -s %t2 | FileCheck %s
5+
// RUN: ld.lld %t --shared -o %t3.so
6+
// RUN: llvm-objdump -s %t3.so | FileCheck -check-prefix=CHECK-SHARED %s
7+
// REQUIRES: arm
8+
9+
// For an executable, we write the module index 1 and the offset into the TLS
10+
// directly into the GOT. For a shared library we can only write the offset
11+
// into the TLS directly if the symbol is non-preemptible
12+
13+
.text
14+
.syntax unified
15+
.globl __tls_get_addr
16+
.type __tls_get_addr,%function
17+
__tls_get_addr:
18+
bx lr
19+
20+
.globl _start
21+
.p2align 2
22+
.type _start,%function
23+
func:
24+
.L0:
25+
nop
26+
.L1:
27+
nop
28+
.L2:
29+
nop
30+
.L3:
31+
nop
32+
.p2align 2
33+
// Generate R_ARM_TLS_GD32 relocations
34+
// These can be resolved at static link time for executables as 1 is always the
35+
// module index and the offset into tls is known at static link time
36+
.Lt0: .word x1(TLSGD) + (. - .L0 - 8)
37+
.Lt1: .word x2(TLSGD) + (. - .L1 - 8)
38+
.Lt2: .word x3(TLSGD) + (. - .L2 - 8)
39+
.Lt3: .word x4(TLSGD) + (. - .L3 - 8)
40+
.hidden x1
41+
.globl x1
42+
.hidden x2
43+
.globl x2
44+
.globl x3
45+
.globl x4
46+
47+
.section .tdata,"awT",%progbits
48+
.p2align 2
49+
.TLSSTART:
50+
.type x1, %object
51+
x1:
52+
.word 10
53+
.type x2, %object
54+
x2:
55+
.word 20
56+
57+
.section .tbss,"awT",%nobits
58+
.p2align 2
59+
.type x3, %object
60+
x3:
61+
.space 4
62+
.type x4, %object
63+
x4:
64+
.space 4
65+
66+
// CHECK: Contents of section .got:
67+
// CHECK-NEXT: 12008 01000000 00000000 01000000 04000000
68+
// CHECK-NEXT: 12018 01000000 08000000 01000000 0c000000
69+
70+
// CHECK-SHARED: Contents of section .got:
71+
// CHECK-SHARED-NEXT: 2050 00000000 00000000 00000000 04000000
72+
// CHECK-SHARED-NEXT: 2060 00000000 00000000 00000000 00000000

0 commit comments

Comments
 (0)
Please sign in to comment.