Skip to content

Commit c29f07c

Browse files
author
yavtuk
committed
[BOLT][AArch64] Adds tls relocations support
1 parent a0ef12c commit c29f07c

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

bolt/lib/Core/Relocation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static bool isSupportedAArch64(uint64_t Type) {
7575
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7676
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
7777
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
78+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
79+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
7880
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
7981
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
8082
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -183,6 +185,8 @@ static size_t getSizeForTypeAArch64(uint64_t Type) {
183185
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
184186
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
185187
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
188+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
189+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
186190
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
187191
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
188192
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
@@ -480,6 +484,12 @@ static uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents,
480484
Contents &= ~0xffffffffffc003ffU;
481485
return Contents >> (10 - 0);
482486
}
487+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
488+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC: {
489+
// 16 bits immediate goes in [20:5] bits
490+
Contents &= ~0xffffffffffe0001fU;
491+
return Contents >> 5;
492+
}
483493
case ELF::R_AARCH64_LDST128_ABS_LO12_NC: {
484494
// Immediate goes in bits 21:10 of ADD instruction, taken
485495
// from bits 11:4 of Symbol address
@@ -651,6 +661,8 @@ static bool isTLSAArch64(uint64_t Type) {
651661
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
652662
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
653663
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
664+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
665+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
654666
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
655667
case ELF::R_AARCH64_TLSDESC_ADD_LO12:
656668
case ELF::R_AARCH64_TLSDESC_CALL:
@@ -716,6 +728,8 @@ static bool isPCRelativeAArch64(uint64_t Type) {
716728
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
717729
case ELF::R_AARCH64_TLSLE_ADD_TPREL_HI12:
718730
case ELF::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
731+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
732+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
719733
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
720734
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
721735
case ELF::R_AARCH64_TLSDESC_ADD_LO12:

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
14491449
case ELF::R_AARCH64_TLSDESC_LD64_LO12:
14501450
case ELF::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
14511451
case ELF::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
1452+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0:
1453+
case ELF::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
14521454
case ELF::R_AARCH64_MOVW_UABS_G0:
14531455
case ELF::R_AARCH64_MOVW_UABS_G0_NC:
14541456
case ELF::R_AARCH64_MOVW_UABS_G1:

bolt/test/AArch64/r_aarch64_tls.s

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## This test checks processing of tls relocations
2+
##
3+
## R_AARCH64_TLSLE_MOVW_TPREL_G0, TPREL(S + A)
4+
## R_AARCH64_TLSLE_MOVW_TPREL_G0_NC, TPREL(S + A)
5+
6+
# REQUIRES: system-linux
7+
8+
# RUN: %clang %cflags -nostartfiles -nostdlib %s -o %t.exe -mlittle-endian \
9+
# RUN: -Wl,-q
10+
# RUN: llvm-readelf -Wr %t.exe | FileCheck %s -check-prefix=CHECKTLS
11+
12+
# CHECKTLS: R_AARCH64_TLSLE_MOVW_TPREL_G0 {{.*}} .tprel_tls_var + 0
13+
# CHECKTLS-NEXT: R_AARCH64_TLSLE_MOVW_TPREL_G0_NC {{.*}} .tprel_tls_var + 4
14+
15+
# RUN: llvm-bolt %t.exe -o %t.bolt
16+
# RUN: llvm-objdump -D %t.bolt | FileCheck %s --check-prefix=CHECKBOLT
17+
18+
# CHECKBOLT: Disassembly of section .tdata
19+
# CHECKBOLT: [[#%x,DATATABLEADDR:]] <.tdata
20+
# CHECKBOLT-NEXT: [[#DATATABLEADDR]]: 000000aa
21+
# CHECKBOLT-NEXT: [[#DATATABLEADDR + 4]]: 000000bb
22+
23+
.section .tdata
24+
.align 4
25+
.tprel_tls_var:
26+
.word 0xaa
27+
.word 0xbb
28+
29+
.section .text
30+
.align 4
31+
.globl _start
32+
.type _start, %function
33+
_start:
34+
mrs x0, TPIDR_EL0
35+
movz x1, #:tprel_g0:.tprel_tls_var
36+
add x0, x0, x1
37+
ldr w2, [x0]
38+
cmp w2, 0xaa
39+
bne exit_failure
40+
41+
mrs x0, TPIDR_EL0
42+
movk x1, #:tprel_g0_nc:.tprel_tls_var + 4
43+
add x0, x0, x1
44+
ldr w2, [x0]
45+
cmp w2, 0xbb
46+
bne exit_failure
47+
48+
exit_success:
49+
mov x0, #0
50+
b exit
51+
52+
exit_failure:
53+
mov x0, #1
54+
b exit
55+
56+
exit:
57+
mov x8, #93
58+
svc #0
59+
60+
.size _start, .-_start

0 commit comments

Comments
 (0)