Skip to content

Commit 1395dbd

Browse files
author
George Rimar
committedJan 11, 2016
[ELF/AARCH64] - Implemented R_AARCH64_TSTBR14 relocation.
R_AARCH64_TSTBR14 is calculated as S+A-P, Set the immediate field of a TBZ/TBNZ instruction to bits [15:2] of X; check -2^15 ≤ X < 2^15 Differential revision: http://reviews.llvm.org/D15824 llvm-svn: 257334
1 parent 4102bfb commit 1395dbd

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
 

‎lld/ELF/Target.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ bool AArch64TargetInfo::relocNeedsPlt(uint32_t Type,
12251225
case R_AARCH64_CALL26:
12261226
case R_AARCH64_CONDBR19:
12271227
case R_AARCH64_JUMP26:
1228+
case R_AARCH64_TSTBR14:
12281229
return canBePreempted(&S, true);
12291230
}
12301231
}
@@ -1320,6 +1321,12 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
13201321
case R_AARCH64_PREL64:
13211322
write64le(Loc, SA - P);
13221323
break;
1324+
case R_AARCH64_TSTBR14: {
1325+
uint64_t X = SA - P;
1326+
checkInt<16>(X, Type);
1327+
or32le(Loc, (X & 0xFFFC) << 3);
1328+
break;
1329+
}
13231330
default:
13241331
error("unrecognized reloc " + Twine(Type));
13251332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.globl _foo
2+
_foo:
3+
nop
4+
nop
5+
nop
6+
nop
7+
8+
.globl _bar
9+
_bar:
10+
nop
11+
nop
12+
nop

‎lld/test/ELF/aarch64-tstbr14-reloc.s

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-tstbr14-reloc.s -o %t1
2+
# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t2
3+
# RUN: ld.lld %t1 %t2 -o %t
4+
# RUN: llvm-objdump -d %t | FileCheck %s
5+
# RUN: ld.lld -shared %t1 %t2 -o %t3
6+
# RUN: llvm-objdump -d %t3 | FileCheck -check-prefix=DSO %s
7+
# RUN: llvm-readobj -s -r %t3 | FileCheck -check-prefix=DSOREL %s
8+
# REQUIRES: aarch64
9+
10+
# 0x1101c - 28 = 0x11000
11+
# 0x11020 - 16 = 0x11010
12+
# 0x11024 - 36 = 0x11000
13+
# 0x11028 - 24 = 0x11010
14+
# CHECK: Disassembly of section .text:
15+
# CHECK-NEXT: _foo:
16+
# CHECK-NEXT: 11000: {{.*}} nop
17+
# CHECK-NEXT: 11004: {{.*}} nop
18+
# CHECK-NEXT: 11008: {{.*}} nop
19+
# CHECK-NEXT: 1100c: {{.*}} nop
20+
# CHECK: _bar:
21+
# CHECK-NEXT: 11010: {{.*}} nop
22+
# CHECK-NEXT: 11014: {{.*}} nop
23+
# CHECK-NEXT: 11018: {{.*}} nop
24+
# CHECK: _start:
25+
# CHECK-NEXT: 1101c: {{.*}} tbnz w3, #15, #-28
26+
# CHECK-NEXT: 11020: {{.*}} tbnz w3, #15, #-16
27+
# CHECK-NEXT: 11024: {{.*}} tbz x6, #45, #-36
28+
# CHECK-NEXT: 11028: {{.*}} tbz x6, #45, #-24
29+
30+
#DSOREL: Section {
31+
#DSOREL: Index:
32+
#DSOREL: Name: .got.plt
33+
#DSOREL-NEXT: Type: SHT_PROGBITS
34+
#DSOREL-NEXT: Flags [
35+
#DSOREL-NEXT: SHF_ALLOC
36+
#DSOREL-NEXT: SHF_WRITE
37+
#DSOREL-NEXT: ]
38+
#DSOREL-NEXT: Address: 0x3000
39+
#DSOREL-NEXT: Offset: 0x3000
40+
#DSOREL-NEXT: Size: 40
41+
#DSOREL-NEXT: Link: 0
42+
#DSOREL-NEXT: Info: 0
43+
#DSOREL-NEXT: AddressAlignment: 8
44+
#DSOREL-NEXT: EntrySize: 0
45+
#DSOREL-NEXT: }
46+
#DSOREL: Relocations [
47+
#DSOREL-NEXT: Section ({{.*}}) .rela.plt {
48+
#DSOREL-NEXT: 0x3018 R_AARCH64_JUMP_SLOT _foo
49+
#DSOREL-NEXT: 0x3020 R_AARCH64_JUMP_SLOT _bar
50+
#DSOREL-NEXT: }
51+
#DSOREL-NEXT:]
52+
53+
#DSO: Disassembly of section .text:
54+
#DSO-NEXT: _foo:
55+
#DSO-NEXT: 1000: {{.*}} nop
56+
#DSO-NEXT: 1004: {{.*}} nop
57+
#DSO-NEXT: 1008: {{.*}} nop
58+
#DSO-NEXT: 100c: {{.*}} nop
59+
#DSO: _bar:
60+
#DSO-NEXT: 1010: {{.*}} nop
61+
#DSO-NEXT: 1014: {{.*}} nop
62+
#DSO-NEXT: 1018: {{.*}} nop
63+
#DSO: _start:
64+
# 0x101c + 52 = 0x1050 = PLT[1]
65+
# 0x1020 + 64 = 0x1060 = PLT[2]
66+
# 0x1024 + 44 = 0x1050 = PLT[1]
67+
# 0x1028 + 56 = 0x1060 = PLT[2]
68+
#DSO-NEXT: 101c: {{.*}} tbnz w3, #15, #52
69+
#DSO-NEXT: 1020: {{.*}} tbnz w3, #15, #64
70+
#DSO-NEXT: 1024: {{.*}} tbz x6, #45, #44
71+
#DSO-NEXT: 1028: {{.*}} tbz x6, #45, #56
72+
#DSO-NEXT: Disassembly of section .plt:
73+
#DSO-NEXT: .plt:
74+
#DSO-NEXT: 1030: {{.*}} stp x16, x30, [sp, #-16]!
75+
#DSO-NEXT: 1034: {{.*}} adrp x16, #8192
76+
#DSO-NEXT: 1038: {{.*}} ldr x17, [x16, #16]
77+
#DSO-NEXT: 103c: {{.*}} add x16, x16, #16
78+
#DSO-NEXT: 1040: {{.*}} br x17
79+
#DSO-NEXT: 1044: {{.*}} nop
80+
#DSO-NEXT: 1048: {{.*}} nop
81+
#DSO-NEXT: 104c: {{.*}} nop
82+
#DSO-NEXT: 1050: {{.*}} adrp x16, #8192
83+
#DSO-NEXT: 1054: {{.*}} ldr x17, [x16, #24]
84+
#DSO-NEXT: 1058: {{.*}} add x16, x16, #24
85+
#DSO-NEXT: 105c: {{.*}} br x17
86+
#DSO-NEXT: 1060: {{.*}} adrp x16, #8192
87+
#DSO-NEXT: 1064: {{.*}} ldr x17, [x16, #32]
88+
#DSO-NEXT: 1068: {{.*}} add x16, x16, #32
89+
#DSO-NEXT: 106c: {{.*}} br x17
90+
91+
.globl _start
92+
_start:
93+
tbnz w3, #15, _foo
94+
tbnz w3, #15, _bar
95+
tbz x6, #45, _foo
96+
tbz x6, #45, _bar

0 commit comments

Comments
 (0)
Please sign in to comment.