1// RUN: rm -rf %t && mkdir -p %t
2// RUN: llvm-mc -triple i686-windows -filetype obj -o %t/COFF_i386.o %s
3// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0x7ffffffd \
4// RUN:   -dummy-extern _ExitProcess=0x7fffffff \
5// RUN:   -verify -check=%s %t/COFF_i386.o
6
7	.text
8
9	.def _main
10		.scl 2
11		.type 32
12	.endef
13	.global _main
14_main:
15rel1:
16	call _function				// IMAGE_REL_I386_REL32
17# rtdyld-check: decode_operand(rel1, 0) = (_function-_main-4-1)
18	xorl %eax, %eax
19rel12:
20	jmp _printf
21# rtdyld-check: decode_operand(rel12, 0)[31:0] = (_printf-_main-4-8)
22
23	.def _function
24		.scl 2
25		.type 32
26	.endef
27_function:
28rel2:
29	pushl string
30# rtdyld-check: decode_operand(rel3, 3) = \
31# rtdyld-check:   stub_addr(COFF_i386.o/.text, __imp__ExitProcess)
32# rtdyld-check: *{4}(stub_addr(COFF_i386.o/.text, __imp__ExitProcess)) = \
33# rtdyld-check:   _ExitProcess
34rel3:
35	calll *__imp__ExitProcess       	// IMAGE_REL_I386_DIR32
36
37	.data
38
39	.global relocations
40relocations:
41rel5:
42	.long _function@imgrel			// IMAGE_REL_I386_DIR32NB
43# rtdyld-check: *{4}rel5 = _function - section_addr(COFF_i386.o, .text)
44rel6:
45# rtdyld-check: *{2}rel6 = 1
46	.secidx rel5                            // IMAGE_REL_I386_SECTION
47rel7:
48# rtdyld-check: *{4}rel7 = string - section_addr(COFF_i386.o, .data)
49	.secrel32 string			// IMAGE_REL_I386_SECREL
50
51# Test that addends work.
52rel8:
53# rtdyld-check: *{4}rel8 = string
54	.long string				// IMAGE_REL_I386_DIR32
55rel9:
56# rtdyld-check: *{4}rel9 = string+1
57	.long string+1				// IMAGE_REL_I386_DIR32
58rel10:
59# rtdyld-check: *{4}rel10 = string - section_addr(COFF_i386.o, .text) + 1
60	.long string@imgrel+1			// IMAGE_REL_I386_DIR32NB
61rel11:
62# rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.o, .data) + 1
63	.long string@SECREL32+1			// IMAGE_REL_I386_SECREL
64
65# We explicitly add padding to put string outside of the 16bit address space
66# (absolute and as an offset from .data), so that relocations involving
67# 32bit addresses / offsets are not accidentally truncated to 16 bits.
68	.space 65536
69	.global string
70	.align 1
71string:
72	.asciz "Hello World!\n"
73