xref: /llvm-project/bolt/test/runtime/AArch64/adrrelaxationpass.s (revision abec50cb9391522d7a7019d0cb040e946c8af164)
1# The second and third ADR instructions are non-local to functions
2# and must be replaced with ADRP + ADD by BOLT
3# Also since main and test are non-simple, we can't change it's length so we
4# have to replace NOP with adrp, and if there is no nop before adr in non-simple
5# function, we can't guarantee we didn't break possible jump tables, so we
6# fail in non-strict mode
7
8# REQUIRES: system-linux
9
10# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
11# RUN:   %s -o %t.o
12# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
13# RUN: llvm-bolt %t.exe -o %t.bolt --adr-relaxation=true --strict
14# RUN: llvm-objdump --no-print-imm-hex -d --disassemble-symbols=main %t.bolt | FileCheck %s
15# RUN: %t.bolt
16# RUN: not llvm-bolt %t.exe -o %t.bolt --adr-relaxation=true \
17# RUN: 2>&1 | FileCheck %s --check-prefix CHECK-ERROR
18
19  .text
20  .align 4
21  .global test
22  .type test, %function
23test:
24  adr x2, Gvar
25  mov x0, xzr
26  ret
27  .size test, .-test
28
29  .align 4
30  .global main
31  .type main, %function
32main:
33  adr x0, .CI
34  nop
35  adr x1, test
36  adr x2, Gvar2
37  adr x3, br
38br:
39  br x1
40  .size main, .-main
41.CI:
42  .word 0xff
43
44  .data
45  .align 8
46  .global Gvar
47Gvar: .xword 0x0
48  .global Gvar2
49Gvar2: .xword 0x42
50  .balign 4
51jmptable:
52  .word 0
53  .word test - jmptable
54
55# CHECK: <main>:
56# CHECK-NEXT: adr x0, 0x{{[1-8a-f][0-9a-f]*}}
57# CHECK-NEXT: adrp x1, 0x{{[1-8a-f][0-9a-f]*}}
58# CHECK-NEXT: add x1, x1, #{{[1-8a-f][0-9a-f]*}}
59# CHECK-NEXT: adrp x2, 0x{{[1-8a-f][0-9a-f]*}}
60# CHECK-NEXT: add x2, x2, #{{[1-8a-f][0-9a-f]*}}
61# CHECK-NEXT: adr x3, 0x{{[1-8a-f][0-9a-f]*}}
62# CHECK-ERROR: BOLT-ERROR: Cannot relax adr in non-simple function
63