2 # RUN: 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/linker.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.
14 # CHECK-NEXT: add x1, x1
16 ## ADRP contains a nonzero addend, no relaxations should be applied.
20 ## LDR contains a nonzero addend, no relaxations should be applied.
24 ## LDR and ADRP use different registers, no relaxations should be applied.
28 ## LDR and ADRP use different registers, no relaxations should be applied.
32 ## Symbol 'x' is nonpreemptible, but --no-relax surpresses relaxations.
33 # RUN: ld.lld %t/a.o -T %t/linker.t --no-relax -o %t/no-relax
34 # RUN: llvm-objdump --no-show-raw-insn -d %t/no-relax | \
35 # FileCheck --check-prefix=X1-NO-RELAX %s
37 # X1-NO-RELAX: adrp x1
38 # X1-NO-RELAX-NEXT: ldr
40 ## Symbol 'x' is nonpreemptible, but the address is not within adrp range.
41 # RUN: ld.lld %t/a.o -T %t/out-of-range.t -o %t/out-of-range
42 # RUN: llvm-objdump --no-show-raw-insn -d %t/out-of-range | \
43 # RUN: FileCheck --check-prefix=X1-NO-RELAX %s
45 ## Relocations do not appear in pairs, no relaxations should be applied.
46 # RUN: ld.lld %t/unpaired.o -o %t/unpaired
47 # RUN: llvm-objdump --no-show-raw-insn -d %t/unpaired | \
48 # RUN: FileCheck --check-prefix=UNPAIRED %s
52 # UNPAIRED-NEXT: adrp x0
55 ## Relocations do not appear in pairs, no relaxations should be applied.
56 # RUN: ld.lld %t/lone-ldr.o -o %t/lone-ldr
57 # RUN: llvm-objdump --no-show-raw-insn -d %t/lone-ldr | \
58 # RUN: FileCheck --check-prefix=LONE-LDR %s
62 ## This linker script ensures that .rodata and .text are sufficiently (>1M)
63 ## far apart so that the adrp + ldr pair cannot be relaxed to adr + nop.
66 .rodata 0x1000: { *(.rodata) }
67 .text 0x200100: { *(.text) }
70 ## This linker script ensures that .rodata and .text are sufficiently (>4GB)
71 ## far apart so that the adrp + ldr pair cannot be relaxed.
74 .rodata 0x1000: { *(.rodata) }
75 .text 0x100002000: { *(.text) }
87 ldr x1
, [x1
, #:got_lo12:x]
89 ldr x2
, [x2
, #:got_lo12:x]
91 ldr x3
, [x3
, #:got_lo12:x+8]
93 ldr x5
, [x4
, #:got_lo12:x]
95 ldr x6
, [x0
, #:got_lo12:x]
108 ldr x0
, [x0
, #:got_lo12:x]
117 ldr x0
, [x0
, #:got_lo12:x]