File tree Expand file tree Collapse file tree 6 files changed +72
-85
lines changed Expand file tree Collapse file tree 6 files changed +72
-85
lines changed Original file line number Diff line number Diff line change @@ -81,17 +81,15 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
81
81
It = BB.eraseInstruction (std::prev (It));
82
82
} else if (std::next (It) != BB.end () && BC.MIB ->isNoop (*std::next (It))) {
83
83
BB.eraseInstruction (std::next (It));
84
- } else if (!opts::StrictMode && ! BF.isSimple ()) {
84
+ } else if (!BF.isSimple ()) {
85
85
// If the function is not simple, it may contain a jump table undetected
86
86
// by us. This jump table may use an offset from the branch instruction
87
87
// to land in the desired place. If we add new instructions, we
88
88
// invalidate this offset, so we have to rely on linker-inserted NOP to
89
89
// replace it with ADRP, and abort if it is not present.
90
90
auto L = BC.scopeLock ();
91
- BC.errs () << formatv (
92
- " BOLT-ERROR: Cannot relax adr in non-simple function "
93
- " {0}. Use --strict option to override\n " ,
94
- BF.getOneName ());
91
+ BC.errs () << " BOLT-ERROR: cannot relax ADR in non-simple function "
92
+ << BF << ' \n ' ;
95
93
PassFailed = true ;
96
94
return ;
97
95
}
Original file line number Diff line number Diff line change
1
+ ## Check that llvm-bolt generates a proper error message when ADR instruction
2
+ ## cannot be relaxed.
3
+
4
+ # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
5
+ # RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static
6
+ # RUN: not llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
7
+ # RUN: not llvm-bolt %t.exe -o %t.bolt --strict 2>&1 | FileCheck %s
8
+
9
+ # CHECK: BOLT-ERROR: cannot relax ADR in non-simple function _start
10
+
11
+ ## The function contains unknown control flow and llvm-bolt fails to recover
12
+ ## CFG. As BOLT has to preserve the function layout, the ADR instruction cannot
13
+ ## be relaxed into ADRP+ADD.
14
+ .text
15
+ .globl _start
16
+ .type _start, %function
17
+ _start:
18
+ .cfi_startproc
19
+ adr x1, foo
20
+ adr x2, .L1
21
+ .L1:
22
+ br x0
23
+ ret x0
24
+ .cfi_endproc
25
+ .size _start, .-_start
26
+
27
+ .globl foo
28
+ .type foo, %function
29
+ foo:
30
+ .cfi_startproc
31
+ ret x0
32
+ .cfi_endproc
33
+ .size foo, .-foo
Original file line number Diff line number Diff line change 3
3
# RUN: llvm - mc - filetype=obj - triple aarch64 - unknown - unknown %s - o %t.o
4
4
# RUN: %clang %cflags %t.o - o %t.exe - Wl ,- q - static
5
5
# RUN: llvm - bolt %t.exe - o %t.bolt -- split - functions -- split - strategy=random2
6
- # RUN: llvm - objdump - d -- disassemble - symbols=_start %t.bolt | FileCheck %s
6
+ # RUN: llvm - objdump - d - j .text %t.bolt | FileCheck %s
7
7
# RUN: llvm - objdump - d -- disassemble - symbols=foo.cold. 0 %t.bolt \
8
8
# RUN: | FileCheck -- check - prefix=CHECK - FOO %s
9
9
13
13
.globl _start
14
14
.type _start , %function
15
15
_start:
16
- # CHECK: <_start>:
17
16
.cfi_startproc
17
+ # CHECK: <_start>:
18
+ # CHECK - NEXT: adr
18
19
adr x1 , _start
19
- # CHECK - NOT : adrp
20
- # CHECK: adr
21
20
cmp x1 , x11
22
21
b.hi .L1
23
22
mov x0 , # 0x0
38
37
mov x0 , # 0x0
39
38
.L2:
40
39
# CHECK - FOO: <foo.cold. 0 >:
41
- adr x1 , foo
42
- # CHECK - FOO: adrp
40
+ # CHECK - FOO - NEXT: adrp
43
41
# CHECK - FOO - NEXT: add
42
+ adr x1 , foo
44
43
ret x30
45
44
.cfi_endproc
46
45
.size foo , . - foo
47
46
48
- ## Force relocation mode.
49
- .reloc 0 , R_AARCH64_NONE
47
+ ## bar is a non - simple function. We can still relax ADR , because it has a
48
+ ## preceding NOP .
49
+ .globl bar
50
+ .type bar , %function
51
+ bar:
52
+ .cfi_startproc
53
+ # CHECK - LABEL: <bar>:
54
+ # CHECK - NEXT: adrp
55
+ # CHECK - NEXT: add
56
+ nop
57
+ adr x0 , foo
58
+ adr x1 , .L3
59
+ br x1
60
+ .L3:
61
+ ret x0
62
+ .cfi_endproc
63
+ .size bar , . - bar
Original file line number Diff line number Diff line change 12
12
// CHECKPREL - NEXT: R_AARCH64_PREL32 {{. * }} _start + 4
13
13
// CHECKPREL - NEXT: R_AARCH64_PREL64 {{. * }} _start + 8
14
14
15
- // RUN: llvm - bolt %t.exe - o %t.bolt -- strict
15
+ // RUN: llvm - bolt %t.exe - o %t.bolt
16
16
// RUN: llvm - objdump - D %t.bolt | FileCheck %s -- check - prefix=CHECKPREL32
17
17
18
18
// CHECKPREL32: [[ #%x , DATATABLEADDR: ]] <datatable>:
19
19
// CHECKPREL32 - NEXT: 00 :
20
20
// CHECKPREL32 - NEXT: 04 : {{. * }} .word 0x [[ #%x , VALUE: ]]
21
21
22
- // 4 is offset in datatable
23
- // 8 is addend
24
- // CHECKPREL32: [[ #DATATABLEADDR + 4 - 8 + VALUE ]] <_start>:
22
+ // CHECKPREL32: [[ #DATATABLEADDR + VALUE ]] <_start>:
25
23
26
24
// RUN: llvm - objdump - D %t.bolt | FileCheck %s -- check - prefix=CHECKPREL64
27
25
// CHECKPREL64: [[ #%x , DATATABLEADDR: ]] <datatable>:
30
28
// CHECKPREL64 - NEXT: 08 : {{. * }} .word 0x [[ #%x , VALUE: ]]
31
29
// CHECKPREL64 - NEXT: 0c: {{. * }} .word 0x00000000
32
30
33
- // 8 is offset in datatable
34
- // 12 is addend
35
- // CHECKPREL64: [[ #DATATABLEADDR + 8 - 12 + VALUE ]] <_start>:
31
+ // CHECKPREL64: [[ #DATATABLEADDR + VALUE ]] <_start>:
36
32
37
33
. section .text
38
34
. align 4
39
35
.globl _start
40
36
.type _start , %function
41
37
_start:
42
- adr x0 , datatable
38
+ adrp x0 , datatable
39
+ add x0 , x0 , :lo12:datable
43
40
mov x0 , # 0
44
41
ret
45
42
Original file line number Diff line number Diff line change 7
7
8
8
// RUN: llvm - mc - filetype=obj - triple aarch64 - unknown - unknown - mattr= + pauth %s - o %t.o
9
9
// RUN: %clang %cflags -- target=aarch64 - unknown - linux %t.o - o %t.exe - Wl ,- q
10
- // RUN: llvm - bolt %t.exe - o %t.bolt -- print - cfg -- strict -- debug - only=mcplus \
11
- // RUN: - v= 1 2 >& 1 | FileCheck %s
10
+ // RUN: llvm - bolt %t.exe - o %t.bolt -- print - cfg -- debug - only=mcplus - v= 1 2 >& 1 \
11
+ // RUN: | FileCheck %s
12
12
13
13
// Pattern 1 : there is no shift amount after the 'add' instruction.
14
14
//
@@ -45,6 +45,7 @@ _start:
45
45
.type test1 , %function
46
46
test1:
47
47
mov x1 , # 0
48
+ nop
48
49
adr x3 , datatable
49
50
add x3 , x3 , x1 , lsl # 2
50
51
ldr w2 , [ x3 ]
@@ -56,6 +57,11 @@ test1_1:
56
57
ret
57
58
test1_2:
58
59
ret
60
+ .size test1 , . - test1
61
+
62
+ // Temporary workaround for PC - relative relocations from datatable leaking into
63
+ // test2 function and creating phantom entry points.
64
+ .skip 0x100
59
65
60
66
// Pattern 2
61
67
// CHECK: BOLT - DEBUG: failed to match indirect branch: nop /adr instead of adrp/ add
65
71
nop
66
72
adr x3 , jump_table
67
73
ldrh w3 , [ x3 , x1 , lsl # 1 ]
74
+ nop
68
75
adr x1 , test2_0
69
76
add x3 , x1 , w3 , sxth # 2
70
77
br x3
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments