[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / lld / test / ELF / aarch64-adrp-ldr-got.s
blob56a90aac3876c8ab1de965d085f7431c1d453b6b
1 # REQUIRES: aarch64
2 # RUN: rm -rf %t && split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=aarch64 %t/a.s -o %t/a.o
5 # RUN: llvm-mc -filetype=obj -triple=aarch64 %t/unpaired.s -o %t/unpaired.o
6 # RUN: llvm-mc -filetype=obj -triple=aarch64 %t/lone-ldr.s -o %t/lone-ldr.o
8 # RUN: ld.lld %t/a.o -T %t/out-of-adr-range.t -o %t/a
9 # RUN: llvm-objdump --no-show-raw-insn -d %t/a | FileCheck %s
11 ## Symbol 'x' is nonpreemptible, the relaxation should be applied.
12 ## This test verifies the encoding when the register x1 is used.
13 # CHECK: adrp x1
14 # CHECK-NEXT: add x1, x1
16 ## ADRP contains a nonzero addend, no relaxations should be applied.
17 # CHECK-NEXT: adrp x2
18 # CHECK-NEXT: ldr
20 ## LDR contains a nonzero addend, no relaxations should be applied.
21 # CHECK-NEXT: adrp x3
22 # CHECK-NEXT: ldr
24 ## LDR and ADRP use different registers, no relaxations should be applied.
25 # CHECK-NEXT: adrp x4
26 # CHECK-NEXT: ldr
28 ## LDR and ADRP use different registers, no relaxations should be applied.
29 # CHECK-NEXT: adrp x6
30 # CHECK-NEXT: ldr
32 # RUN: ld.lld %t/a.o -T %t/within-adr-range.t -o %t/a
33 # RUN: llvm-objdump --no-show-raw-insn -d %t/a | FileCheck --check-prefix=ADR %s
35 ## Symbol 'x' is nonpreemptible, the relaxation should be applied.
36 # ADR: nop
37 # ADR-NEXT: adr x1
39 ## Symbol 'x' is nonpreemptible, but --no-relax surpresses relaxations.
40 # RUN: ld.lld %t/a.o -T %t/out-of-adr-range.t --no-relax -o %t/no-relax
41 # RUN: llvm-objdump --no-show-raw-insn -d %t/no-relax | \
42 # RUN: FileCheck --check-prefix=X1-NO-RELAX %s
44 # X1-NO-RELAX: adrp x1
45 # X1-NO-RELAX-NEXT: ldr
47 ## Symbol 'x' is nonpreemptible, but the address is not within adrp range.
48 # RUN: ld.lld %t/a.o -T %t/out-of-range.t -o %t/out-of-range
49 # RUN: llvm-objdump --no-show-raw-insn -d %t/out-of-range | \
50 # RUN: FileCheck --check-prefix=X1-NO-RELAX %s
52 ## Relocations do not appear in pairs, no relaxations should be applied.
53 # RUN: ld.lld %t/unpaired.o -o %t/unpaired
54 # RUN: llvm-objdump --no-show-raw-insn -d %t/unpaired | \
55 # RUN: FileCheck --check-prefix=UNPAIRED %s
57 # UNPAIRED: adrp x0
58 # UNPAIRED-NEXT: b
59 # UNPAIRED-NEXT: adrp x0
60 # UNPAIRED: ldr x0
62 ## Relocations do not appear in pairs, no relaxations should be applied.
63 # RUN: ld.lld %t/lone-ldr.o -o %t/lone-ldr
64 # RUN: llvm-objdump --no-show-raw-insn -d %t/lone-ldr | \
65 # RUN: FileCheck --check-prefix=LONE-LDR %s
67 # LONE-LDR: ldr x0
69 ## This linker script ensures that .rodata and .text are sufficiently (>1M)
70 ## far apart so that the adrp + ldr pair cannot be relaxed to adr + nop.
71 #--- out-of-adr-range.t
72 SECTIONS {
73 .rodata 0x1000: { *(.rodata) }
74 .text 0x200100: { *(.text) }
77 ## This linker script ensures that .rodata and .text are sufficiently (<1M)
78 ## close to each other so that the adrp + ldr pair can be relaxed to nop + adr.
79 #--- within-adr-range.t
80 SECTIONS {
81 .rodata 0x1000: { *(.rodata) }
82 .text 0x2000: { *(.text) }
85 ## This linker script ensures that .rodata and .text are sufficiently (>4GB)
86 ## far apart so that the adrp + ldr pair cannot be relaxed.
87 #--- out-of-range.t
88 SECTIONS {
89 .rodata 0x1000: { *(.rodata) }
90 .text 0x100002000: { *(.text) }
93 #--- a.s
94 .rodata
95 .hidden x
97 .word 10
98 .text
99 .global _start
100 _start:
101 adrp x1, :got:x
102 ldr x1, [x1, #:got_lo12:x]
103 adrp x2, :got:x+1
104 ldr x2, [x2, #:got_lo12:x]
105 adrp x3, :got:x
106 ldr x3, [x3, #:got_lo12:x+8]
107 adrp x4, :got:x
108 ldr x5, [x4, #:got_lo12:x]
109 adrp x6, :got:x
110 ldr x6, [x0, #:got_lo12:x]
112 #--- unpaired.s
113 .text
114 .hidden x
117 .global _start
118 _start:
119 adrp x0, :got:x
121 adrp x0, :got:x
123 ldr x0, [x0, #:got_lo12:x]
125 #--- lone-ldr.s
126 .text
127 .hidden x
130 .global _start
131 _start:
132 ldr x0, [x0, #:got_lo12:x]