1// RUN: llvm-mc -triple i686-windows -filetype obj -o %t.obj %s
2// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0xfffffffd -dummy-extern _OutputDebugStringA@4=0xfffffffe -dummy-extern _ExitProcess@4=0xffffffff -verify -check=%s %t.obj
3
4	.text
5
6	.def _main
7		.scl 2
8		.type 32
9	.endef
10	.global _main
11_main:
12rel1:
13	call _function				// IMAGE_REL_I386_REL32
14# rtdyld-check: decode_operand(rel1, 0) = (_function-_main-4-1)
15	xorl %eax, %eax
16rel12:
17	jmp _printf
18# rtdyld-check: decode_operand(rel12, 0)[31:0] = (_printf-_main-4-8)
19
20	.def _function
21		.scl 2
22		.type 32
23	.endef
24_function:
25rel2:
26	pushl string
27rel3:
28	calll *__imp__OutputDebugStringA	// IMAGE_REL_I386_DIR32
29# rtdyld-check: decode_operand(rel3, 3) = __imp__OutputDebugStringA
30	addl  $4, %esp
31	pushl $0
32rel4:
33	calll *__imp__ExitProcess		// IMAGE_REL_I386_DIR32
34# rtdyld-check: decode_operand(rel4, 3) = __imp__ExitProcess
35	addl  $4, %esp
36	retl
37
38	.data
39
40	.global __imp__OutputDebugStringA
41	.align 4
42__imp__OutputDebugStringA:
43	.long "_OutputDebugStringA@4"		// IMAGE_REL_I386_DIR32
44# rtdyld-check: *{4}__imp__OutputDebugStringA = 0xfffffffe
45
46	.global __imp__ExitProcess
47	.align 4
48__imp__ExitProcess:
49	.long "_ExitProcess@4"			// IMAGE_REL_I386_DIR32
50# rtdyld-check: *{4}__imp__ExitProcess = 0xffffffff
51
52	.global string
53	.align 1
54string:
55	.asciz "Hello World!\n"
56
57	.global relocations
58relocations:
59rel5:
60	.long _function@imgrel			// IMAGE_REL_I386_DIR32NB
61# rtdyld-check: *{4}rel5 = _function - section_addr(COFF_i386.s.tmp.obj, .text)
62rel6:
63# rtdyld-check: *{2}rel6 = 1
64	.secidx __imp__OutputDebugStringA	// IMAGE_REL_I386_SECTION
65rel7:
66# rtdyld-check: *{4}rel7 = relocations - section_addr(COFF_i386.s.tmp.obj, .data)
67	.secrel32 relocations			// IMAGE_REL_I386_SECREL
68
69# Test that addends work.
70rel8:
71# rtdyld-check: *{4}rel8 = string
72	.long string				// IMAGE_REL_I386_DIR32
73rel9:
74# rtdyld-check: *{4}rel9 = string+1
75	.long string+1				// IMAGE_REL_I386_DIR32
76rel10:
77# rtdyld-check: *{4}rel10 = string - section_addr(COFF_i386.s.tmp.obj, .text) + 1
78	.long string@imgrel+1			// IMAGE_REL_I386_DIR32NB
79rel11:
80# rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.s.tmp.obj, .data) + 1
81	.long string@SECREL32+1			// IMAGE_REL_I386_SECREL
82