[RuntimeDyld][MachO][AArch64] Add a helper function for encoding addends in instructions.
[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.o %s
2 # RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -verify -check=%s %t.o
3 # RUN: rm %t.o
4
5 # FIXME: Add GOT relocation tests once GOT testing is supported.
6
7     .section  __TEXT,__text,regular,pure_instructions
8     .ios_version_min 7, 0
9     .globl  foo
10     .align  2
11 foo:
12     movz  w0, #0
13     ret
14
15     .globl  _test_branch_reloc
16     .align  2
17
18
19 # Test ARM64_RELOC_BRANCH26 relocation. The branch instruction only encodes 26
20 # bits of the 28-bit possible branch range. The lower two bits are always zero
21 # and therefore ignored.
22 # rtdyld-check:  decode_operand(br1, 0)[25:0] = (foo-br1)[27:2]
23 _test_branch_reloc:
24 br1:
25     b foo
26     ret
27
28
29 # Test ARM64_RELOC_UNSIGNED relocation. The absolute 64-bit address of the
30 # function should be stored at the 8-byte memory location.
31 # rtdyld-check: *{8}ptr = foo
32     .section  __DATA,__data
33     .globl  ptr
34     .align  3
35     .fill 8192, 1, 0
36 ptr:
37     .quad foo
38
39
40 # Test ARM64_RELOC_PAGE21 and ARM64_RELOC_PAGEOFF12 relocation. adrp encodes
41 # the PC-relative page (4 KiB) difference between the adrp instruction and the
42 # variable ptr. ldr encodes the offset of the variable within the page. The ldr
43 # instruction perfroms an implicit shift on the encoded immediate (imm<<3).
44 # rtdyld-check:  decode_operand(adrp1, 1) = (ptr[32:12]-adrp1[32:12])
45 # rtdyld-check:  decode_operand(ldr1, 2) = (ptr[11:3])
46     .globl  _test_adrp_ldr
47     .align  2
48 _test_adrp_ldr:
49 adrp1:
50     adrp x0, ptr@PAGE
51 ldr1:
52     ldr  x0, [x0, ptr@PAGEOFF]
53     ret
54     .fill 8192, 1, 0