File: aarch64-ifunc-bti.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 (91 lines) | stat: -rw-r--r-- 2,985 bytes parent folder | download | duplicates (8)
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
89
90
91
# REQUIRES: aarch64
# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %p/Inputs/aarch64-addrifunc.s -o %t1.o

# RUN: ld.lld --shared --soname=t1.so %t1.o -o %t1.so
# RUN: ld.lld --pie %t1.so %t.o -o %t
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --mattr=+bti --triple=aarch64-linux-gnu %t | FileCheck %s

# RUN: ld.lld -shared -Bsymbolic %t1.so %t.o -o %t.so
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --mattr=+bti %t.so | FileCheck %s --check-prefix=SHARED

# When the address of an ifunc is taken using a non-got reference which clang
# can do, LLD exports a canonical PLT entry that may have its address taken so
# we must use bti c.

# CHECK: Disassembly of section .plt:
# CHECK: 00000000000103a0 <.plt>:
# CHECK-NEXT:    103a0:         bti     c
# CHECK-NEXT:                   stp     x16, x30, [sp, #-16]!
# CHECK-NEXT:                   adrp    x16, 0x30000
# CHECK-NEXT:                   ldr     x17, [x16, #1344]
# CHECK-NEXT:                   add     x16, x16, #1344
# CHECK-NEXT:                   br      x17
# CHECK-NEXT:                   nop
# CHECK-NEXT:                   nop
# CHECK: 00000000000103c0 <func1@plt>:
# CHECK-NEXT:    103c0:         adrp    x16, 0x30000
# CHECK-NEXT:                   ldr     x17, [x16, #1352]
# CHECK-NEXT:                   add     x16, x16, #1352
# CHECK-NEXT:                   br      x17
# CHECK-NEXT:                   nop
# CHECK-NEXT:                   nop
# CHECK-EMPTY:
# CHECK: Disassembly of section .iplt:
# CHECK-EMPTY:
## The address of ifunc1@plt does not escape so it does not need `bti c`,
## but having bti is not wrong.
# CHECK-NEXT: 00000000000103e0 <ifunc2>:
# CHECK-NEXT:    103e0:         bti     c
# CHECK-NEXT:                   adrp    x16, 0x30000
# CHECK-NEXT:                   ldr     x17, [x16, #1360]
# CHECK-NEXT:                   add     x16, x16, #1360
# CHECK-NEXT:                   br      x17
# CHECK-NEXT:                   nop
# CHECK-NEXT:    103f8:         bti     c
# CHECK-NEXT:                   adrp    x16, 0x30000
# CHECK-NEXT:                   ldr     x17, [x16, #1368]
# CHECK-NEXT:                   add     x16, x16, #1368
# CHECK-NEXT:                   br      x17
# CHECK-NEXT:                   nop

## The address of ifunc2 (STT_FUNC) escapes, so it must have `bti c`.
# SHARED:      <ifunc2>:
# SHARED-NEXT:    bti     c

# SHARED:         nop
# SHARED-NEXT:    bti     c

.section ".note.gnu.property", "a"
.long 4
.long 0x10
.long 0x5
.asciz "GNU"

.long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
.long 4
.long 1          // GNU_PROPERTY_AARCH64_FEATURE_1_BTI
.long 0

.text
.globl ifunc1
.type ifunc1,@gnu_indirect_function
ifunc1:
 ret

.globl ifunc2
.type ifunc2,@gnu_indirect_function
ifunc2:
  ret

.globl func1

.text
.globl _start
.type _start, %function
_start:
  bl func1
  bl ifunc1
  adrp x8, ifunc2
  add x8, x8, :lo12:ifunc2
  ret