File: ELF_stubs_arm.s

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (65 lines) | stat: -rw-r--r-- 2,451 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
# RUN: rm -rf %t && mkdir -p %t/armv4t && mkdir -p %t/armv6 && mkdir -p %t/armv7
#
# RUN: llvm-mc -triple=armv4t-linux-gnueabi -arm-add-build-attributes \
# RUN:         -filetype=obj -o %t/armv4t/out.o %s
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \
# RUN:              -slab-allocate 10Kb -slab-page-size 4096 \
# RUN:              -abs ext=0x76bbe880 -check %s %t/armv4t/out.o
#
# RUN: llvm-mc -triple=armv6-linux-gnueabi -arm-add-build-attributes \
# RUN:         -filetype=obj -o %t/armv6/out.o %s
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \
# RUN:              -slab-allocate 10Kb -slab-page-size 4096 \
# RUN:              -abs ext=0x76bbe880 -check %s %t/armv6/out.o
#
# RUN: llvm-mc -triple=armv7-linux-gnueabi -arm-add-build-attributes \
# RUN:         -filetype=obj -o %t/armv7/out.o %s
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \
# RUN:              -slab-allocate 10Kb -slab-page-size 4096 \
# RUN:              -abs ext=0x76bbe880 -check %s %t/armv7/out.o

	.text
	.syntax unified

# Check that calls/jumps to external functions trigger the generation of
# branch-range extension stubs. These stubs don't follow the default PLT model
# where the branch-target address is loaded from a GOT entry. Instead, they
# hard-code it in the immediate field.

# The external function ext will return to the caller directly.
# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - (test_arm_jump + 8)
	.globl	test_arm_jump
	.type	test_arm_jump,%function
	.p2align	2
test_arm_jump:
	b	ext
	.size	test_arm_jump, .-test_arm_jump

# The branch-with-link sets the LR register so that the external function ext
# returns to us. We have to save the register (push) and return to main manually
# (pop). This adds the +4 offset for the bl instruction we decode:
# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - (test_arm_call + 8) - 4
	.globl  test_arm_call
	.type	test_arm_call,%function
	.p2align	2
test_arm_call:
	push	{lr}
	bl	ext
	pop	{pc}
	.size	test_arm_call, .-test_arm_call

# This test is executable with any Arm (and for v7+ also Thumb) `ext` functions.
# It only has to return with `bx lr`. For example:
#   > echo "void ext() {}" | clang -target armv7-linux-gnueabihf -o ext.o -c -xc -
#   > llvm-jitlink ext.o out.o
#
	.globl	main
	.type	main,%function
	.p2align	2
main:
	push	{lr}
	bl	test_arm_call
	bl	test_arm_jump
	mov	r0, #0
	pop	{pc}
	.size	main, .-main