File: aarch64-gnu-ifunc-nonpreemptable.s

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,436 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (72 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download | duplicates (2)
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
# REQUIRES: aarch64
# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o

# RUN: ld.lld %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PDE
# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PDE-RELOC

# RUN: ld.lld -pie %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PIE
# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PIE-RELOC

## When compiling with -fno-PIE or -fPIE, if the ifunc is in the same
## translation unit as the address taker, the compiler knows that ifunc is not
## defined in a shared library so it can use a non GOT generating relative reference.
.text
.globl myfunc
.type myfunc,@gnu_indirect_function
myfunc:
.globl myfunc_resolver
.type myfunc_resolver,@function
myfunc_resolver:
 ret

.text
.globl main
.type main,@function
main:
 adrp x8, myfunc
 add  x8, x8, :lo12: myfunc
 ret

## The address of myfunc is the address of the PLT entry for myfunc.
# PDE:      myfunc_resolver:
# PDE-NEXT:   210000:   ret
# PDE:      main:
# PDE-NEXT:   210004:   adrp    x8, #0
# PDE-NEXT:   210008:   add     x8, x8, #16
# PDE-NEXT:   21000c:   ret
# PDE-EMPTY:
# PDE-NEXT: Disassembly of section .plt:
# PDE-EMPTY:
# PDE-NEXT: myfunc:
## page(.got.plt) - page(0x210010) = 65536
# PDE-NEXT:   210010: adrp    x16, #65536
# PDE-NEXT:   210014: ldr     x17, [x16]
# PDE-NEXT:   210018: add     x16, x16, #0
# PDE-NEXT:   21001c: br      x17

## The adrp to myfunc should generate a PLT entry and a GOT entry with an
## irelative relocation.
# PDE-RELOC:      .rela.plt {
# PDE-RELOC-NEXT:   0x220000 R_AARCH64_IRELATIVE - 0x210000
# PDE-RELOC-NEXT: }

# PIE:      myfunc_resolver:
# PIE-NEXT:    10000: ret
# PIE:      main:
# PIE-NEXT:    10004: adrp    x8, #0
# PIE-NEXT:    10008: add     x8, x8, #16
# PIE-NEXT:    1000c: ret
# PIE-EMPTY:
# PIE-NEXT: Disassembly of section .plt:
# PIE-EMPTY:
# PIE-NEXT: myfunc:
# PIE-NEXT:    10010: adrp    x16, #131072
# PIE-NEXT:    10014: ldr     x17, [x16]
# PIE-NEXT:    10018: add     x16, x16, #0
# PIE-NEXT:    1001c: br      x17

# PIE-RELOC:      .rela.plt {
# PIE-RELOC-NEXT:   0x30000 R_AARCH64_IRELATIVE - 0x10000
# PIE-RELOC-NEXT: }