[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / aarch64-adrp-ldr-got.s
blobc789e720e02e71e40609afc74807b9fcf4f5e905
1 # REQUIRES: aarch64
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.
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 ## 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
50 # UNPAIRED: adrp x0
51 # UNPAIRED-NEXT: b
52 # UNPAIRED-NEXT: adrp x0
53 # UNPAIRED: ldr 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
60 # LONE-LDR: ldr x0
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.
64 #--- linker.t
65 SECTIONS {
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.
72 #--- out-of-range.t
73 SECTIONS {
74 .rodata 0x1000: { *(.rodata) }
75 .text 0x100002000: { *(.text) }
78 #--- a.s
79 .rodata
80 .hidden x
82 .word 10
83 .text
84 .global _start
85 _start:
86 adrp x1, :got:x
87 ldr x1, [x1, #:got_lo12:x]
88 adrp x2, :got:x+1
89 ldr x2, [x2, #:got_lo12:x]
90 adrp x3, :got:x
91 ldr x3, [x3, #:got_lo12:x+8]
92 adrp x4, :got:x
93 ldr x5, [x4, #:got_lo12:x]
94 adrp x6, :got:x
95 ldr x6, [x0, #:got_lo12:x]
97 #--- unpaired.s
98 .text
99 .hidden x
102 .global _start
103 _start:
104 adrp x0, :got:x
106 adrp x0, :got:x
108 ldr x0, [x0, #:got_lo12:x]
110 #--- lone-ldr.s
111 .text
112 .hidden x
115 .global _start
116 _start:
117 ldr x0, [x0, #:got_lo12:x]