Skip to content

Commit cd0f891

Browse files
authored
[JITLink][AArch32] Fix Unaligned Data Symbol Address Resolution (#97030)
The ARM architecture uses the LSB bit for ARM/Thumb mode switch flagging. This is true for alignments of 2 and 4 but in data relocations the alignment is 1 allowing the LSB bit to be set. Now only `ELF::STT_FUNC` typed symbols are used in the TargetFlag mechanism. The test is a minimal example of the issue mentioned below. Fixes #95911 "Orc global constructor order test fails on 32 bit ARM".
1 parent 0ce801f commit cd0f891

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class ELFLinkGraphBuilder_aarch32
200200

201201
protected:
202202
TargetFlagsType makeTargetFlags(const typename ELFT::Sym &Sym) override {
203+
// Only emit target flag for callable symbols
204+
if (Sym.getType() != ELF::STT_FUNC)
205+
return TargetFlagsType{};
203206
if (Sym.getValue() & 0x01)
204207
return aarch32::ThumbSymbol;
205208
return TargetFlagsType{};
@@ -209,7 +212,9 @@ class ELFLinkGraphBuilder_aarch32
209212
TargetFlagsType Flags) override {
210213
assert((makeTargetFlags(Sym) & Flags) == Flags);
211214
static constexpr uint64_t ThumbBit = 0x01;
212-
return Sym.getValue() & ~ThumbBit;
215+
if (Sym.getType() == ELF::STT_FUNC)
216+
return Sym.getValue() & ~ThumbBit;
217+
return Sym.getValue();
213218
}
214219

215220
public:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# RUN: llvm-mc -triple=armv7-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t_armv7.o %s
2+
# RUN: llvm-objdump -s --section=.rodata %t_armv7.o | FileCheck --check-prefix=CHECK-OBJ %s
3+
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \
4+
# RUN: -slab-page-size 4096 %t_armv7.o -debug-only=jitlink 2>&1 \
5+
# RUN: | FileCheck --check-prefix=CHECK-LG %s
6+
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \
7+
# RUN: -slab-page-size 4096 %t_armv7.o -check %s
8+
9+
# RUN: llvm-mc -triple=thumbv7-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t_thumbv7.o %s
10+
# RUN: llvm-objdump -s --section=.rodata %t_thumbv7.o | FileCheck --check-prefix=CHECK-OBJ %s
11+
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \
12+
# RUN: -slab-page-size 4096 %t_thumbv7.o -debug-only=jitlink 2>&1 \
13+
# RUN: | FileCheck --check-prefix=CHECK-LG %s
14+
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \
15+
# RUN: -slab-page-size 4096 %t_thumbv7.o -check %s
16+
17+
# The strings of "H1\00", "H2\00" and "H3\00" are encoded as
18+
# 0x483100, 0x483200 and 0x483300 in the .rodata section.
19+
# CHECK-OBJ: Contents of section .rodata:
20+
# CHECK-OBJ: 0000 48310048 32004833 00 H1.H2.H3.
21+
22+
# CHECK-LG: Starting link phase 1 for graph
23+
# CHECK-LG: section .rodata:
24+
25+
# CHECK-LG: block 0x0 size = 0x00000009, align = 1, alignment-offset = 0
26+
# CHECK-LG-NEXT: symbols:
27+
# CHECK-LG-NEXT: 0x0 (block + 0x00000000): size: 0x00000003, linkage: strong, scope: default, live - Lstr.H1
28+
# CHECK-LG-NEXT: 0x3 (block + 0x00000003): size: 0x00000003, linkage: strong, scope: default, live - Lstr.H2
29+
# CHECK-LG-NOT: 0x2 (block + 0x00000002): size: 0x00000003, linkage: strong, scope: default, live - Lstr.H2
30+
# CHECK-LG-NEXT: 0x6 (block + 0x00000006): size: 0x00000003, linkage: strong, scope: default, live - Lstr.H3
31+
32+
# jitlink-check: Lstr.H1 = 0x76ff0000
33+
# jitlink-check: (*{4}(Lstr.H1))[23:0] = 0x003148
34+
.globl Lstr.H1
35+
.type Lstr.H1,%object
36+
.section .rodata,"a",%progbits
37+
Lstr.H1:
38+
.asciz "H1"
39+
.size Lstr.H1, 3
40+
41+
# H2 is unaligned as its beginning address is base address + 0x3
42+
# Make sure the string we get is 0x003248 and not 0x324800
43+
# jitlink-check: Lstr.H2 = 0x76ff0003
44+
# jitlink-check: (*{4}(Lstr.H2))[23:0] = 0x003248
45+
.globl Lstr.H2
46+
.type Lstr.H2,%object
47+
Lstr.H2:
48+
.asciz "H2"
49+
.size Lstr.H2, 3
50+
51+
# jitlink-check: Lstr.H3 = 0x76ff0006
52+
# jitlink-check: (*{4}(Lstr.H3))[23:0] = 0x003348
53+
.globl Lstr.H3
54+
.type Lstr.H3,%object
55+
Lstr.H3:
56+
.asciz "H3"
57+
.size Lstr.H3, 3
58+
59+
.text
60+
.syntax unified
61+
# Empty main function for jitlink to be happy
62+
.globl main
63+
.type main,%function
64+
.p2align 2
65+
main:
66+
bx lr
67+
.size main,.-main

llvm/test/ExecutionEngine/Orc/global-ctor-order.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
; Test that global constructors are correctly ordered
22
;
3-
; Uncovers a pre-existing issue on Arm 32 bit, see
4-
; https://github.com/llvm/llvm-project/issues/95911.
5-
; UNSUPPORTED: target=arm{{.*}}
6-
;
73
; RUN: lli -jit-kind=orc %s | FileCheck %s
84
;
95
; CHECK: H1

0 commit comments

Comments
 (0)