Skip to content

Commit 43f1063

Browse files
authored
[lld-macho] Enable Linker Optimization Hints pass for arm64_32 (#148964)
The backend emits `.loh` directives for arm64_32 as well. Our pass already handles 32-bit pointer loads correctly (there was an extraneous sanity check for 8-byte pointer sizes, I removed that here), so we can enable them for all arm64 subtargets, including our upcoming arm64e support.
1 parent 362594a commit 43f1063

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

lld/MachO/LinkerOptimizationHints.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ static void applyAdrpLdrGotLdr(uint8_t *buf, const ConcatInputSection *isec,
351351
return;
352352
if (ldr3.baseRegister != ldr2.destRegister)
353353
return;
354-
// Loads from the GOT must be pointer sized.
355-
if (ldr2.p2Size != 3 || ldr2.isFloat)
356-
return;
357354
applyAdrpLdr(buf, isec, offset1, offset2);
358355
}
359356
}

lld/MachO/Writer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,8 @@ void Writer::writeSections() {
12101210
}
12111211

12121212
void Writer::applyOptimizationHints() {
1213-
if (config->arch() != AK_arm64 || config->ignoreOptimizationHints)
1213+
if (!is_contained({AK_arm64, AK_arm64e, AK_arm64_32}, config->arch()) ||
1214+
config->ignoreOptimizationHints)
12141215
return;
12151216

12161217
uint8_t *buf = buffer->getBufferStart();

lld/test/MachO/loh-arm64-32.s

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %s -o %t.o
4+
# RUN: %lld-watchos -U _external %t.o -o %t
5+
# RUN: llvm-objdump -d --macho %t | FileCheck %s
6+
7+
.text
8+
.align 2
9+
.globl _foo
10+
_foo:
11+
ret
12+
.globl _bar
13+
_bar:
14+
ret
15+
16+
.globl _main
17+
_main:
18+
# CHECK-LABEL: _main:
19+
20+
L1: adrp x0, _foo@PAGE
21+
L2: add x0, x0, _foo@PAGEOFF
22+
# CHECK-NEXT: adr x0
23+
# CHECK-NEXT: nop
24+
25+
L3: adrp x0, _ptr@PAGE
26+
L4: add x1, x0, _ptr@PAGEOFF
27+
L5: ldr x2, [x1]
28+
# CHECK-NEXT: nop
29+
# CHECK-NEXT: nop
30+
# CHECK-NEXT: ldr x2
31+
32+
L6: adrp x0, _foo@PAGE
33+
L7: adrp x0, _bar@PAGE
34+
# CHECK-NEXT: adrp x0
35+
# CHECK-NEXT: nop
36+
37+
L8: adrp x0, _ptr@PAGE
38+
L9: ldr x0, [x0, _ptr@PAGEOFF]
39+
# CHECK-NEXT: nop
40+
# CHECK-NEXT: ldr x0
41+
42+
L10: adrp x0, _ptr@PAGE
43+
L11: ldr w0, [x0, _ptr@PAGEOFF]
44+
# CHECK-NEXT: nop
45+
# CHECK-NEXT: ldr w0, _ptr
46+
47+
L12: adrp x0, _external@PAGE
48+
L13: ldr w1, [x0, _external@PAGEOFF]
49+
L14: ldr x2, [x1]
50+
# CHECK-NEXT: nop
51+
# CHECK-NEXT: ldr w1, 0x{{.*}}
52+
# CHECK-NEXT: ldr x2, [x1]
53+
54+
.data
55+
.align 4
56+
_ptr:
57+
.quad 0
58+
59+
.loh AdrpAdd L1, L2
60+
.loh AdrpAddLdr L3, L4, L5
61+
.loh AdrpAdrp L6, L7
62+
.loh AdrpLdr L8, L9
63+
.loh AdrpLdrGot L10, L11
64+
.loh AdrpLdrGotLdr L12, L13, L14

0 commit comments

Comments
 (0)