File: aarch64-adrp-ldr-got-symbols.s

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
## This test verifies that the pair adrp + ldr is relaxed/not relaxed
## depending on the target symbol properties.

# REQUIRES: aarch64
# RUN: rm -rf %t && split-file %s %t

# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/symbols.s -o %t/symbols.o
# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/abs.s -o %t/abs.o

# RUN: ld.lld -shared -T %t/linker.t %t/symbols.o %t/abs.o -o %t/symbols.so
# RUN: llvm-objdump --no-show-raw-insn -d %t/symbols.so | \
# RUN:   FileCheck --check-prefix=LIB %s

## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
LIB:      adrp   x0
LIB-NEXT: add    x0

## Symbol 'global_sym' is preemptible, no relaxations should be applied.
LIB-NEXT: adrp   x1
LIB-NEXT: ldr    x1

## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
LIB-NEXT: adrp   x2
LIB-NEXT: ldr    x2

## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
LIB-NEXT: adrp   x3
LIB-NEXT: ldr    x3

## Symbol 'abs_sym' is absolute, no relaxations should be applied.
LIB-NEXT: adrp   x4
LIB-NEXT: ldr    x4

# RUN: ld.lld -T %t/linker.t -z undefs %t/symbols.o %t/abs.o -o %t/symbols
# RUN: llvm-objdump --no-show-raw-insn -d %t/symbols | \
# RUN:   FileCheck --check-prefix=EXE %s

## Symbol 'global_sym' is nonpreemptible, the relaxation should be applied.
EXE:      adrp   x1
EXE-NEXT: add    x1

## Symbol 'abs_sym' is absolute, relaxations may be applied in -no-pie mode.
EXE:      adrp   x4
EXE-NEXT: add    x4

## The linker script ensures that .rodata and .text are sufficiently (>1MB)
## far apart so that the adrp + ldr pair cannot be relaxed to adr + nop.
#--- linker.t
SECTIONS {
 .rodata 0x1000: { *(.rodata) }
 .text   0x300100: { *(.text) }
}

# This symbol is defined in a separate file to prevent the definition from
# being folded into the instructions that reference it.
#--- abs.s
.global abs_sym
.hidden abs_sym
abs_sym = 0x1000

#--- symbols.s
.rodata
.hidden hidden_sym
hidden_sym:
.word 10

.global global_sym
global_sym:
.word 10

.text
.type ifunc_sym STT_GNU_IFUNC
.hidden ifunc_sym
ifunc_sym:
  nop

.global _start
_start:
  adrp    x0, :got:hidden_sym
  ldr     x0, [x0, #:got_lo12:hidden_sym]
  adrp    x1, :got:global_sym
  ldr     x1, [x1, #:got_lo12:global_sym]
  adrp    x2, :got:undefined_sym
  ldr     x2, [x2, #:got_lo12:undefined_sym]
  adrp    x3, :got:ifunc_sym
  ldr     x3, [x3, #:got_lo12:ifunc_sym]
  adrp    x4, :got:abs_sym
  ldr     x4, [x4, #:got_lo12:abs_sym]