xref: /llvm-project/llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_data.s (revision f29352b63b448485177a2e2b31d864f808070c25)
1# RUN: rm -rf %t && mkdir -p %t/armv6 && mkdir -p %t/armv7 && mkdir -p %t/thumbv7
2# RUN: llvm-mc -triple=armv6-none-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t/armv6/out.o %s
3# RUN: llvm-objdump -r %t/armv6/out.o | FileCheck --check-prefix=CHECK-TYPE %s
4# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb -slab-page-size 4096 \
5# RUN:              -abs target=0x76bbe88f -check %s %t/armv6/out.o
6
7# RUN: llvm-mc -triple=armv7-none-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t/armv7/out.o %s
8# RUN: llvm-objdump -r %t/armv7/out.o | FileCheck --check-prefix=CHECK-TYPE %s
9# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb -slab-page-size 4096 \
10# RUN:              -abs target=0x76bbe88f -check %s %t/armv7/out.o
11
12# RUN: llvm-mc -triple=thumbv7-none-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t/thumbv7/out.o %s
13# RUN: llvm-objdump -r %t/thumbv7/out.o | FileCheck --check-prefix=CHECK-TYPE %s
14# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb -slab-page-size 4096 \
15# RUN:              -abs target=0x76bbe88f -check %s %t/thumbv7/out.o
16
17	.data
18	.global target
19
20	.text
21	.syntax unified
22
23# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_ABS32 target
24# jitlink-check: *{4}(abs32) = target
25	.global abs32
26abs32:
27	.word target
28	.size abs32, .-abs32
29
30# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_REL32 target
31# jitlink-check: (rel32 + *{4}(rel32))[31:0] = target
32	.global rel32
33rel32:
34	.word target - .
35	.size rel32, .-rel32
36
37# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_TARGET1 target
38# jitlink-check: *{4}(target1_abs32) = target
39	.global target1_abs32
40target1_abs32:
41	.word target(target1)
42	.size	target1_abs32, .-target1_abs32
43
44# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_GOT_PREL target
45#
46# The GOT entry contains the absolute address of the external:
47# jitlink-check: *{4}(got_addr(out.o, target)) = target
48#
49# The embedded offset value contains the offset to the GOT entry relative to pc.
50# The +12 accounts for the ARM branch offset (8) and the .LPC offset (4), which
51# is stored as initial addend inline.
52# FIXME: We shouldn't need to substract the 64-bit sign-extension manually.
53# jitlink-check: *{4}got_prel_offset = got_addr(out.o, target) - (next_pc(got_prel) + 4) - 0xffffffff00000000
54	.globl	got_prel
55	.type	got_prel,%function
56	.p2align	2
57	.code	32
58got_prel:
59	ldr	r0, .LCPI
60.LPC:
61	ldr	r0, [pc, r0]
62	ldr	r0, [r0]
63	bx	lr
64# Actual relocation site is on the embedded offset value:
65	.globl	got_prel_offset
66got_prel_offset:
67.LCPI:
68	.long	target(GOT_PREL)-((.LPC+8)-.LCPI)
69	.size	got_prel_offset, .-got_prel_offset
70	.size	got_prel, .-got_prel
71
72# EH personality routine in .ARM.exidx
73# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_NONE __aeabi_unwind_cpp_pr0
74	.globl __aeabi_unwind_cpp_pr0
75	.type __aeabi_unwind_cpp_pr0,%function
76	.align 2
77__aeabi_unwind_cpp_pr0:
78	bx lr
79
80# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_PREL31 .text
81#
82# An .ARM.exidx table entry is 8-bytes in size, made up of 2 4-byte entries.
83# First word contains offset to function for this entry:
84# jitlink-check: (*{4}section_addr(out.o, .ARM.exidx))[31:0] = prel31 - section_addr(out.o, .ARM.exidx)
85#
86# Most-significant bit in second word denotes inline entry when set (and
87# relocation to .ARM.extab otherwise). Inline entry with compact model index 0:
88#   0x9b      vsp = r11
89#   0x84 0x80 pop {r11, r14}
90#
91# jitlink-check: *{4}(section_addr(out.o, .ARM.exidx) + 4) = 0x809b8480
92#
93	.globl  prel31
94	.type   prel31,%function
95	.align  2
96prel31:
97	.fnstart
98	.save   {r11, lr}
99	push    {r11, lr}
100	.setfp  r11, sp
101	mov     r11, sp
102	pop     {r11, lr}
103	mov     pc, lr
104	.fnend
105	.size   prel31,.-prel31
106
107# This test is executable with any 4-byte external target:
108#  > echo "unsigned target = 42;" | clang -target armv7-linux-gnueabihf -o target.o -c -xc -
109#  > llvm-jitlink target.o armv7/out.o
110#
111	.globl  main
112	.type main, %function
113	.p2align  2
114main:
115	push	{lr}
116	bl	got_prel
117	bl	prel31
118	pop	{pc}
119	.size   main, .-main
120