Skip to content

Commit 2828557

Browse files
committedJun 9, 2017
[ELF] Be more precise about Thumb state bit in ARM thunks
The symbols generated for Thunks have type STT_FUNC, to permit a thunk to be reused via a blx instruction the Thumb bit (0) needs to be set properly. Differential Revision: https://reviews.llvm.org/D34036 llvm-svn: 305065
1 parent ad09735 commit 2828557

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed
 

‎lld/ELF/Thunks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void ThumbV7ABSLongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const {
143143
void ThumbV7ABSLongThunk::addSymbols(ThunkSection &IS) {
144144
ThunkSym = addSyntheticLocal(
145145
Saver.save("__Thumbv7ABSLongThunk_" + Destination.getName()), STT_FUNC,
146-
Offset, size(), &IS);
146+
Offset | 0x1, size(), &IS);
147147
addSyntheticLocal("$t", STT_NOTYPE, Offset, 0, &IS);
148148
}
149149

@@ -176,7 +176,7 @@ void ThumbV7PILongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const {
176176
0x60, 0x47, // bx r12
177177
};
178178
uint64_t S = getARMThunkDestVA(Destination);
179-
uint64_t P = ThunkSym->getVA();
179+
uint64_t P = ThunkSym->getVA() & ~0x1;
180180
memcpy(Buf, Data, sizeof(Data));
181181
Target->relocateOne(Buf, R_ARM_THM_MOVW_PREL_NC, S - P - 12);
182182
Target->relocateOne(Buf + 4, R_ARM_THM_MOVT_PREL, S - P - 8);
@@ -185,7 +185,7 @@ void ThumbV7PILongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const {
185185
void ThumbV7PILongThunk::addSymbols(ThunkSection &IS) {
186186
ThunkSym = addSyntheticLocal(
187187
Saver.save("__ThumbV7PILongThunk_" + Destination.getName()), STT_FUNC,
188-
Offset, size(), &IS);
188+
Offset | 0x1, size(), &IS);
189189
addSyntheticLocal("$t", STT_NOTYPE, Offset, 0, &IS);
190190
}
191191

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
2+
// RUN: ld.lld %t -o %t2 2>&1
3+
// RUN: llvm-readobj --symbols %t2 | FileCheck %s
4+
// RUN: ld.lld --shared %t -o %t3 2>&1
5+
// RUN: llvm-readobj --symbols %t3 | FileCheck -check-prefix=CHECK-PI %s
6+
// REQUIRES: arm
7+
8+
// Check that the symbols generated for Thunks have the correct symbol type
9+
// of STT_FUNC and the correct value of bit 0 (0 for ARM 1 for Thumb)
10+
.syntax unified
11+
.section .text.thumb, "ax", %progbits
12+
.thumb
13+
.balign 0x1000
14+
.globl thumb_fn
15+
.type thumb_fn, %function
16+
thumb_fn:
17+
b.w arm_fn
18+
19+
.section .text.arm, "ax", %progbits
20+
.arm
21+
.balign 0x1000
22+
.globl arm_fn
23+
.type arm_fn, %function
24+
arm_fn:
25+
b thumb_fn
26+
27+
// CHECK: Name: __Thumbv7ABSLongThunk_arm_fn
28+
// CHECK-NEXT: Value: 0x11005
29+
// CHECK-NEXT: Size: 10
30+
// CHECK-NEXT: Binding: Local (0x0)
31+
// CHECK-NEXT: Type: Function (0x2)
32+
// CHECK: Name: __ARMv7ABSLongThunk_thumb_fn
33+
// CHECK-NEXT: Value: 0x11010
34+
// CHECK-NEXT: Size: 12
35+
// CHECK-NEXT: Binding: Local (0x0)
36+
// CHECK-NEXT: Type: Function (0x2)
37+
38+
// CHECK-PI: Name: __ThumbV7PILongThunk_arm_fn
39+
// CHECK-PI-NEXT: Value: 0x1005
40+
// CHECK-PI-NEXT: Size: 12
41+
// CHECK-PI-NEXT: Binding: Local (0x0)
42+
// CHECK-PI-NEXT: Type: Function (0x2)

0 commit comments

Comments
 (0)
Please sign in to comment.