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