xref: /llvm-project/llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s (revision 0e124b37bd7fa42ab1087668b1fa7c35a9684deb)
1# RUN: rm -rf %t && mkdir -p %t
2# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t/test_x86-64.o %s
3# RUN: llvm-rtdyld -triple=x86_64-apple-macosx10.9 -dummy-extern ds1=0xfffffffffffffffe -dummy-extern ds2=0xffffffffffffffff -verify -check=%s %t/test_x86-64.o
4
5        .section	__TEXT,__text,regular,pure_instructions
6	.globl	foo
7	.align	4, 0x90
8foo:
9        retq
10
11	.globl	main
12	.align	4, 0x90
13main:
14# Test PC-rel branch.
15# rtdyld-check: decode_operand(insn1, 0) = foo - next_pc(insn1)
16insn1:
17        callq	foo
18
19# Test PC-rel signed.
20# rtdyld-check: decode_operand(insn2, 4) = x - next_pc(insn2)
21insn2:
22	movl	x(%rip), %eax
23
24# Test PC-rel GOT relocation.
25# Verify the alignment of the GOT entry, the contents of the GOT entry for y,
26# and that the movq instruction references the correct GOT entry address:
27# rtdyld-check: stub_addr(test_x86-64.o/__text, y)[2:0] = 0
28# rtdyld-check: *{8}(stub_addr(test_x86-64.o/__text, y)) = y
29# rtdyld-check: decode_operand(insn3, 4) = stub_addr(test_x86-64.o/__text, y) - next_pc(insn3)
30insn3:
31        movq	y@GOTPCREL(%rip), %rax
32
33        movl	$0, %eax
34	retq
35
36# Test processing of the __eh_frame section.
37# rtdyld-check: *{8}(section_addr(test_x86-64.o, __eh_frame) + 0x20) = eh_frame_test - (section_addr(test_x86-64.o, __eh_frame) + 0x20)
38eh_frame_test:
39        .cfi_startproc
40        retq
41        .cfi_endproc
42
43        .comm   y,4,2
44
45        .section	__DATA,__data
46	.globl	x
47	.align	2
48x:
49        .long   5
50
51# Test dummy-extern relocation.
52# rtdyld-check: *{8}z1 = ds1
53z1:
54        .quad   ds1
55
56# Test external-symbol relocation bypass: symbols with addr 0xffffffffffffffff
57# don't have their relocations applied.
58# rtdyld-check: *{8}z2 = 0
59z2:
60        .quad   ds2
61
62# Test absolute symbols.
63# rtdyld-check: abssym = 0xdeadbeef
64        .globl  abssym
65abssym = 0xdeadbeef
66
67# Test subtractor relocations between named symbols.
68# rtdyld-check: *{8}z3a = z4 - z5 + 4
69z3a:
70        .quad  z4 - z5 + 4
71
72# Test subtractor relocations between anonymous symbols.
73# rtdyld-check: *{8}z3b = (section_addr(test_x86-64.o, _tmp3) + 4) - (section_addr(test_x86-64.o, _tmp4)) + 8
74z3b:
75        .quad  Lanondiff_1 - Lanondiff_2 + 8
76
77# Test subtractor relocations between named and anonymous symbols.
78# rtdyld-check: *{8}z3c = z4 - (section_addr(test_x86-64.o, _tmp4)) + 12
79z3c:
80        .quad  z4 - Lanondiff_2 + 12
81
82# Test subtractor relocations between anonymous and named symbols.
83# rtdyld-check: *{8}z3d = (section_addr(test_x86-64.o, _tmp3) + 4) - z4 + 16
84z3d:
85        .quad  Lanondiff_1 - z4 + 16
86
87        .section        __DATA,_tmp1
88z4:
89        .byte 1
90
91        .section        __DATA,_tmp2
92z5:
93        .byte 1
94
95        .section        __DATA,_tmp3
96        .long 1         # padding to make sure we handle non-zero offsets.
97Lanondiff_1:
98        .byte 1
99
100        .section        __DATA,_tmp4
101Lanondiff_2:
102        .byte 1
103
104.subsections_via_symbols
105