Skip to content

Commit 441cf5d

Browse files
committedJul 20, 2016
Initial support for the local dynamic model ARM TLS relocations:
- R_ARM_TLS_LDM32 - R_ARM_TLS_LDO32 The local dynamic implementation and tests follows the same model as the other ARM TLS models. The R_ARM_TLS_LDO32 is implemented as R_ABS expr type as the getVA() for a TLS symbol will return the offset from the start of the TLS block. Differential Revision https://reviews.llvm.org/D22563 llvm-svn: 276123
1 parent 6de4bd6 commit 441cf5d

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
 

‎lld/ELF/Target.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class ARMTargetInfo final : public TargetInfo {
178178
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
179179
uint32_t getDynRel(uint32_t Type) const override;
180180
uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
181+
bool isTlsLocalDynamicRel(uint32_t Type) const override;
181182
bool isTlsGlobalDynamicRel(uint32_t Type) const override;
182183
bool isTlsInitialExecRel(uint32_t Type) const override;
183184
void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override;
@@ -1523,6 +1524,8 @@ RelExpr ARMTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
15231524
return R_GOT_PC;
15241525
case R_ARM_TLS_GD32:
15251526
return R_TLSGD_PC;
1527+
case R_ARM_TLS_LDM32:
1528+
return R_TLSLD_PC;
15261529
case R_ARM_BASE_PREL:
15271530
// B(S) + A - P
15281531
// FIXME: currently B(S) assumed to be .got, this may not hold for all
@@ -1624,6 +1627,8 @@ void ARMTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
16241627
case R_ARM_REL32:
16251628
case R_ARM_TLS_GD32:
16261629
case R_ARM_TLS_IE32:
1630+
case R_ARM_TLS_LDM32:
1631+
case R_ARM_TLS_LDO32:
16271632
case R_ARM_TLS_LE32:
16281633
write32le(Loc, Val);
16291634
break;
@@ -1749,6 +1754,8 @@ uint64_t ARMTargetInfo::getImplicitAddend(const uint8_t *Buf,
17491754
case R_ARM_GOT_PREL:
17501755
case R_ARM_REL32:
17511756
case R_ARM_TLS_GD32:
1757+
case R_ARM_TLS_LDM32:
1758+
case R_ARM_TLS_LDO32:
17521759
case R_ARM_TLS_IE32:
17531760
case R_ARM_TLS_LE32:
17541761
return SignExtend64<32>(read32le(Buf));
@@ -1808,6 +1815,10 @@ uint64_t ARMTargetInfo::getImplicitAddend(const uint8_t *Buf,
18081815
}
18091816
}
18101817

1818+
bool ARMTargetInfo::isTlsLocalDynamicRel(uint32_t Type) const {
1819+
return Type == R_ARM_TLS_LDO32 || Type == R_ARM_TLS_LDM32;
1820+
}
1821+
18111822
bool ARMTargetInfo::isTlsGlobalDynamicRel(uint32_t Type) const {
18121823
return Type == R_ARM_TLS_GD32;
18131824
}

‎lld/test/ELF/arm-tls-ldm32.s

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi
2+
// RUN: ld.lld %t.o -o %t.so -shared
3+
// RUN: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s
4+
// RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s
5+
// REQUIRES: arm
6+
7+
// Test the handling of the local-dynamic TLS model. Dynamic loader finds
8+
// module index R_ARM_TLS_DTPMOD32. The offset in the next GOT slot is 0
9+
// The R_ARM_TLS_LDO is the offset of the variable within the TLS block.
10+
.global __tls_get_addr
11+
.text
12+
.p2align 2
13+
.global _start
14+
.syntax unified
15+
.arm
16+
.type _start, %function
17+
_start:
18+
.L0:
19+
nop
20+
21+
.word x(tlsldm) + (. - .L0 - 8)
22+
.word x(tlsldo)
23+
.word y(tlsldo)
24+
25+
.section .tbss,"awT",%nobits
26+
.p2align 2
27+
.type y, %object
28+
y:
29+
.space 4
30+
.section .tdata,"awT",%progbits
31+
.p2align 2
32+
.type x, %object
33+
x:
34+
.word 10
35+
36+
// SEC: Name: .tdata
37+
// SEC-NEXT: Type: SHT_PROGBITS
38+
// SEC-NEXT: Flags [
39+
// SEC-NEXT: SHF_ALLOC
40+
// SEC-NEXT: SHF_TLS
41+
// SEC-NEXT: SHF_WRITE
42+
// SEC-NEXT: ]
43+
// SEC-NEXT: Address: 0x2000
44+
// SEC: Size: 4
45+
// SEC: Name: .tbss
46+
// SEC-NEXT: Type: SHT_NOBITS (0x8)
47+
// SEC-NEXT: Flags [
48+
// SEC-NEXT: SHF_ALLOC
49+
// SEC-NEXT: SHF_TLS
50+
// SEC-NEXT: SHF_WRITE
51+
// SEC-NEXT: ]
52+
// SEC-NEXT: Address: 0x2004
53+
// SEC: Size: 4
54+
55+
// SEC: Dynamic Relocations {
56+
// SEC-NEXT: 0x204C R_ARM_TLS_DTPMOD32 - 0x0
57+
58+
// CHECK: Disassembly of section .text:
59+
// CHECK-NEXT: _start:
60+
// CHECK-NEXT: 1000: 00 f0 20 e3 nop
61+
62+
// (0x204c - 0x1004) + (0x1004 - 0x1000 - 8) = 0x1044
63+
// CHECK: 1004: 44 10 00 00
64+
// CHECK-NEXT: 1008: 00 00 00 00
65+
// CHECK-NEXT: 100c: 04 00 00 00
66+
67+
// CHECK-EXE: Disassembly of section .text:
68+
// CHECK-NEXT-EXE: _start:
69+
// CHECK-NEXT-EXE: 11000: 00 f0 20 e3 nop
70+
71+
// CHECK-EXE: 11004: fc 0f 00 00
72+
// CHECK-EXE: 11008: 00 00 00 00
73+
// CHECK-EXE: 1100c: 04 00 00 00

0 commit comments

Comments
 (0)