1## This test verifies that the pair adrp + ldr is relaxed/not relaxed
2## depending on the target symbol properties.
3
4# REQUIRES: aarch64
5# RUN: rm -rf %t && split-file %s %t
6
7# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/symbols.s -o %t/symbols.o
8# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/abs.s -o %t/abs.o
9
10# RUN: ld.lld -shared -T %t/linker.t %t/symbols.o %t/abs.o -o %t/symbols.so
11# RUN: llvm-objdump --no-show-raw-insn -d %t/symbols.so | \
12# RUN:   FileCheck --check-prefix=LIB %s
13
14## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
15LIB:      adrp   x0
16LIB-NEXT: add    x0
17
18## Symbol 'global_sym' is preemptible, no relaxations should be applied.
19LIB-NEXT: adrp   x1
20LIB-NEXT: ldr    x1
21
22## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
23LIB-NEXT: adrp   x2
24LIB-NEXT: ldr    x2
25
26## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
27LIB-NEXT: adrp   x3
28LIB-NEXT: ldr    x3
29
30## Symbol 'abs_sym' is absolute, no relaxations should be applied.
31LIB-NEXT: adrp   x4
32LIB-NEXT: ldr    x4
33
34# RUN: ld.lld -T %t/linker.t -z undefs %t/symbols.o %t/abs.o -o %t/symbols
35# RUN: llvm-objdump --no-show-raw-insn -d %t/symbols | \
36# RUN:   FileCheck --check-prefix=EXE %s
37
38## Symbol 'global_sym' is nonpreemptible, the relaxation should be applied.
39EXE:      adrp   x1
40EXE-NEXT: add    x1
41
42## Symbol 'abs_sym' is absolute, relaxations may be applied in -no-pie mode.
43EXE:      adrp   x4
44EXE-NEXT: add    x4
45
46## The linker script ensures that .rodata and .text are sufficiently (>1MB)
47## far apart so that the adrp + ldr pair cannot be relaxed to adr + nop.
48#--- linker.t
49SECTIONS {
50 .rodata 0x1000: { *(.rodata) }
51 .text   0x300100: { *(.text) }
52}
53
54# This symbol is defined in a separate file to prevent the definition from
55# being folded into the instructions that reference it.
56#--- abs.s
57.global abs_sym
58.hidden abs_sym
59abs_sym = 0x1000
60
61#--- symbols.s
62.rodata
63.hidden hidden_sym
64hidden_sym:
65.word 10
66
67.global global_sym
68global_sym:
69.word 10
70
71.text
72.type ifunc_sym STT_GNU_IFUNC
73.hidden ifunc_sym
74ifunc_sym:
75  nop
76
77.global _start
78_start:
79  adrp    x0, :got:hidden_sym
80  ldr     x0, [x0, #:got_lo12:hidden_sym]
81  adrp    x1, :got:global_sym
82  ldr     x1, [x1, #:got_lo12:global_sym]
83  adrp    x2, :got:undefined_sym
84  ldr     x2, [x2, #:got_lo12:undefined_sym]
85  adrp    x3, :got:ifunc_sym
86  ldr     x3, [x3, #:got_lo12:ifunc_sym]
87  adrp    x4, :got:abs_sym
88  ldr     x4, [x4, #:got_lo12:abs_sym]
89