4713c118e125f1c7e2fcf15d724162354016789c
[oota-llvm.git] / test / ExecutionEngine / RuntimeDyld / AArch64 / MachO_ARM64_relocations.s
1 # RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -code-model=small -relocation-model=pic -filetype=obj -o %T/foo.o %s
2 # RUN: sed "s,<filename>,%/T/foo.o,g" %s > %T/foo.s
3 # RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -verify -check=%T/foo.s %/T/foo.o
4
5     .section  __TEXT,__text,regular,pure_instructions
6     .ios_version_min 7, 0
7     .globl  _foo
8     .align  2
9 _foo:
10     movz  w0, #0
11     ret
12
13     .globl  _test_branch_reloc
14     .align  2
15
16
17 # Test ARM64_RELOC_BRANCH26 relocation. The branch instruction only encodes 26
18 # bits of the 28-bit possible branch range. The lower two bits are always zero
19 # and therefore ignored.
20 # rtdyld-check:  decode_operand(br1, 0)[25:0] = (_foo - br1)[27:2]
21 _test_branch_reloc:
22 br1:
23     b _foo
24     ret
25
26
27 # Test ARM64_RELOC_PAGE21 and ARM64_RELOC_PAGEOFF12 relocation. adrp encodes
28 # the PC-relative page (4 KiB) difference between the adrp instruction and the
29 # variable ptr. ldr encodes the offset of the variable within the page. The ldr
30 # instruction perfroms an implicit shift on the encoded immediate (imm<<3).
31 # rtdyld-check:  decode_operand(adrp1, 1) = (_ptr[32:12] - adrp1[32:12])
32 # rtdyld-check:  decode_operand(ldr1, 2) = _ptr[11:3]
33     .globl  _test_adrp_ldr
34     .align  2
35 _test_adrp_ldr:
36 adrp1:
37     adrp x0, _ptr@PAGE
38 ldr1:
39     ldr  x0, [x0, _ptr@PAGEOFF]
40     ret
41
42
43 # Test ARM64_RELOC_GOT_LOAD_PAGE21 and ARM64_RELOC_GOT_LOAD_PAGEOFF12
44 # relocation. adrp encodes the PC-relative page (4 KiB) difference between the
45 # adrp instruction and the GOT entry for ptr. ldr encodes the offset of the GOT
46 # entry within the page. The ldr instruction perfroms an implicit shift on the
47 # encoded immediate (imm<<3).
48 # rtdyld-check:  *{8}(stub_addr(<filename>, __text, _ptr)) = _ptr
49 # rtdyld-check:  decode_operand(adrp2, 1) = (stub_addr(<filename>, __text, _ptr)[32:12] - adrp2[32:12])
50 # rtdyld-check:  decode_operand(ldr2, 2) = stub_addr(<filename>, __text, _ptr)[11:3]
51     .globl  _test_adrp_ldr
52     .align  2
53 _test_got_adrp_ldr:
54 adrp2:
55     adrp x0, _ptr@GOTPAGE
56 ldr2:
57     ldr  x0, [x0, _ptr@GOTPAGEOFF]
58     ret
59
60
61 # Test ARM64_RELOC_UNSIGNED relocation. The absolute 64-bit address of the
62 # function should be stored at the 8-byte memory location.
63 # rtdyld-check: *{8}_ptr = _foo
64     .section  __DATA,__data
65     .globl  _ptr
66     .align  3
67     .fill 4096, 1, 0
68 _ptr:
69     .quad _foo