|
1 | 1 | // Test how BOLT handles indirect branch sequence of instructions in |
2 | 2 | // AArch64MCPlus builder. |
3 | | -// This test checks the pattern where there is no shift amount after add |
4 | | -// instruction. The pattern come from libc, it can be reproduced with |
5 | | -// a 'static' built binary. |
| 3 | + |
| 4 | +// clang-format off |
| 5 | + |
| 6 | +// REQUIRES: system-linux |
| 7 | +// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o |
| 8 | +// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q |
| 9 | +// RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg --strict\ |
| 10 | +// RUN: -v=1 2>&1 | FileCheck %s |
| 11 | + |
| 12 | +// Pattern 1: there is no shift amount after the 'add' instruction. |
6 | 13 | // |
7 | 14 | // adr x6, 0x219fb0 <sigall_set+0x88> |
8 | 15 | // add x6, x6, x14, lsl #2 |
9 | 16 | // ldr w7, [x6] |
10 | 17 | // add x6, x6, w7, sxtw => no shift amount |
11 | 18 | // br x6 |
12 | 19 | // |
13 | | -// It also tests another case where there is no adrp/add pair. |
14 | | -// The pattern also come from libc, and it only represents in the binary |
15 | | -// if the lld linker is used to create the static binary. |
16 | | -// It doesn't occur with GCC ld linker. |
| 20 | + |
| 21 | +// Pattern 2: nop/adr pair is used in place of adrp/add |
17 | 22 | // |
18 | 23 | // nop => nop/adr instead of adrp/add |
19 | 24 | // adr x13, 0x215a18 <_nl_value_type_LC_COLLATE+0x50> |
|
22 | 27 | // add x13, x12, w13, sxth #2 |
23 | 28 | // br x13 |
24 | 29 |
|
25 | | -// clang-format off |
26 | | - |
27 | | -// REQUIRES: system-linux |
28 | | -// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o |
29 | | -// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q |
30 | | -// RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg \ |
31 | | -// RUN: -v=1 2>&1 | FileCheck %s |
32 | | - |
33 | | -// CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add |
34 | | -// CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2 |
35 | | - |
36 | | - |
37 | 30 | .section .text |
38 | 31 | .align 4 |
39 | 32 | .globl _start |
40 | 33 | .type _start, %function |
41 | 34 | _start: |
42 | | - bl bar |
43 | | - bl end |
44 | | - mov x0, #4 |
45 | | - mov w8, #93 |
46 | | - svc #0 |
| 35 | + bl test1 |
| 36 | + bl test2 |
| 37 | +// mov x0, #4 |
| 38 | +// mov w8, #93 |
| 39 | +// svc #0 |
47 | 40 |
|
48 | | -bar: |
49 | | - mov w1, #3 |
50 | | - cmp x1, #0 |
51 | | - b.eq end |
52 | | - nop |
53 | | - adr x3, jump_table |
54 | | - ldrh w3, [x3, x1, lsl #1] |
55 | | - adr x1, .case0 |
56 | | - add x3, x1, w3, sxth #2 |
57 | | - br x3 |
58 | | -.case0: |
59 | | - mov w0, #1 |
60 | | - ret |
61 | | -.case1: |
62 | | - mov w0, #2 |
63 | | - ret |
64 | | -.case3: |
65 | | - mov w0, #3 |
66 | | - ret |
67 | | -.case4: |
68 | | - nop |
| 41 | +// Pattern 1 |
| 42 | +// CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2 |
| 43 | + .globl test1 |
| 44 | + .type test1, %function |
| 45 | +test1: |
69 | 46 | mov x1, #0 |
70 | 47 | adr x3, datatable |
71 | 48 | add x3, x3, x1, lsl #2 |
72 | 49 | ldr w2, [x3] |
73 | 50 | add x3, x3, w2, sxtw |
74 | 51 | br x3 |
75 | | - nop |
76 | | - mov w0, #4 |
77 | | - ret |
78 | | -.case7: |
79 | | - mov w0, #4 |
80 | | - ret |
81 | | - |
82 | | -foo1: |
| 52 | +test1_0: |
83 | 53 | ret |
84 | | - |
85 | | -foo2: |
86 | | - add w0, w0, #3 |
| 54 | +test1_1: |
87 | 55 | ret |
88 | | - |
89 | | -foo3: |
90 | | - add w0, w0, #3 |
| 56 | +test1_2: |
91 | 57 | ret |
92 | 58 |
|
93 | | -end: |
94 | | - add x0, x0, #99 |
| 59 | +// Pattern 2 |
| 60 | +// CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add |
| 61 | + .globl test2 |
| 62 | + .type test2, %function |
| 63 | +test2: |
| 64 | + nop |
| 65 | + adr x3, jump_table |
| 66 | + ldrh w3, [x3, x1, lsl #1] |
| 67 | + adr x1, test2_0 |
| 68 | + add x3, x1, w3, sxth #2 |
| 69 | + br x3 |
| 70 | +test2_0: |
| 71 | + ret |
| 72 | +test2_1: |
95 | 73 | ret |
96 | 74 |
|
97 | 75 | .section .rodata,"a",@progbits |
98 | | -jump_table: |
99 | | - .hword (.case0-.case0)>>2 |
100 | | - .hword (.case1-.case0)>>2 |
101 | | - .hword (.case3-.case0)>>2 |
102 | | - .hword (.case4-.case0)>>2 |
103 | | - .hword (.case7-.case0)>>2 |
104 | | - |
105 | | - |
106 | 76 | datatable: |
107 | | - .word foo1-datatable |
108 | | - .word foo2-datatable |
109 | | - .word foo3-datatable |
110 | | - .word 20 |
| 77 | + .word test1_0-datatable |
| 78 | + .word test1_1-datatable |
| 79 | + .word test1_2-datatable |
| 80 | + |
| 81 | +jump_table: |
| 82 | + .hword (test2_0-test2_0)>>2 |
| 83 | + .hword (test2_1-test2_0)>>2 |
0 commit comments