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.
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 # 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.
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
59 # UNPAIRED-NEXT: adrp 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
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
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
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.
89 .rodata 0x1000: { *(.rodata) }
90 .text 0x100002000: { *(.text) }
102 ldr x1
, [x1
, #:got_lo12:x]
104 ldr x2
, [x2
, #:got_lo12:x]
106 ldr x3
, [x3
, #:got_lo12:x+8]
108 ldr x5
, [x4
, #:got_lo12:x]
110 ldr x6
, [x0
, #:got_lo12:x]
123 ldr x0
, [x0
, #:got_lo12:x]
132 ldr x0
, [x0
, #:got_lo12:x]