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