summaryrefslogtreecommitdiffstats
path: root/llvm/test/ExecutionEngine/RuntimeDyld/Mips/ELF_N32_relocations.s
blob: 46e764477ba5082d41678076e884e682f6ab246e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# RUN: rm -rf %t && mkdir -p %t
# RUN: llvm-mc -triple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %t/test_ELF_N32.o %s
# RUN: llc -mtriple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %t/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64el-unknown-linux -verify -map-section test_ELF_N32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N32.o,.text=0x10000 -check=%s %t/test_ELF_N32.o %t/test_ELF_ExternalFunction_N32.o

# RUN: llvm-mc -triple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %t/test_ELF_N32.o %s
# RUN: llc -mtriple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %t/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64-unknown-linux -verify -map-section test_ELF_N32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N32.o,.text=0x10000 -check=%s %t/test_ELF_N32.o %t/test_ELF_ExternalFunction_N32.o

	.data
# Test R_MIPS_PC32 relocation.
# rtdyld-check: *{4}(R_MIPS_PC32) = (foo - R_MIPS_PC32)[31:0]
R_MIPS_PC32:
	.word foo-.
# rtdyld-check: *{4}(R_MIPS_PC32 + 4) = (foo - tmp1)[31:0]
tmp1:
	.4byte foo-tmp1

	.text
	.abicalls
	.section	.mdebug.abi64,"",@progbits
	.nan	legacy
	.file	"ELF_N32_PIC_relocations.ll"
	.text
	.globl	bar
	.align	3
	.type	bar,@function
	.set	nomicromips
	.set	nomips16
	.ent	bar
bar:
	.frame	$fp,40,$ra
	.mask 	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	.set	noat
	daddiu	$sp, $sp, -40
	sd	$ra, 32($sp)
	sd	$fp, 24($sp)
	move	 $fp, $sp
	sd	$4, 16($fp)
	lb	$2, 0($4)
	sd	$4, 8($fp)

# Test R_MIPS_26 relocation.
# rtdyld-check:  decode_operand(insn1, 0)[27:0] = stub_addr(test_ELF_N32.o/.text, foo)[27:0]
insn1:
	.option pic0
	jal   foo
	.option pic2
	nop

# Test R_MIPS_PC16 relocation.
# rtdyld-check:  decode_operand(insn2, 1)[17:0] = (foo - insn2)[17:0]
insn2:
	bal   foo
	nop

	move	 $sp, $fp
	ld	$ra, 32($sp)
	ld	$fp, 24($sp)
	daddiu	$sp, $sp, 32
	jr	$ra
	nop
	.set	at
	.set	macro
	.set	reorder
	.end	bar
$func_end0:
	.size	bar, ($func_end0)-bar

	.globl	main
	.align	3
	.type	main,@function
	.set	nomicromips
	.set	nomips16
	.ent	main
main:
	.frame	$fp,32,$ra
	.mask 	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	.set	noat
	daddiu	$sp, $sp, -32
	sd	$ra, 24($sp)
	sd	$fp, 16($sp)
	sd	$gp, 8($sp)
	move	 $fp, $sp

# $gp register contains address of the .got section + 0x7FF0. 0x7FF0 is
# the offset of $gp from the beginning of the .got section. Check that we are
# loading address of the page pointer from correct offset. In this case
# the page pointer is the first entry in the .got section, so offset will be
# 0 - 0x7FF0.
# rtdyld-check:  decode_operand(insn5, 2)[15:0] = 0x8010
#
# Check that the global offset table contains the page pointer.
# rtdyld-check: *{4}(section_addr(test_ELF_N32.o, .got)) = (_str + 0x8000) & 0xffff0000
insn5:
	ld	$25, %got_page(_str)($1)

# Check the offset of _str from the page pointer.
# rtdyld-check:  decode_operand(insn6, 2)[15:0] = _str[15:0]
insn6:
	daddiu	$25, $25, %got_ofst(_str)

# Check that we are loading address of var from correct offset. In this case
# var is the second entry in the .got section, so offset will be 4 - 0x7FF0.
# rtdyld-check:  decode_operand(insn7, 2)[15:0] = 0x8014
#
# Check that the global offset table contains the address of the var.
# rtdyld-check: *{4}(section_addr(test_ELF_N32.o, .got) + 4) = var
insn7:
	ld	$2, %got_disp(var)($1)
	sd	$25, 0($2)

# Check that we are loading address of bar from correct offset. In this case
# bar is the third entry in the .got section, so offset will be 8 - 0x7FF0.
# rtdyld-check:  decode_operand(insn8, 2)[15:0] = 0x8018
#
# Check that the global offset table contains the address of the bar.
# rtdyld-check: *{4}(section_addr(test_ELF_N32.o, .got) + 8) = bar
insn8:
	ld	$2, %call16(bar)($1)

	move	 $4, $25
	move	 $gp, $1
	move	 $25, $2
	jalr	$25
	nop
	move	 $sp, $fp
	ld	$gp, 8($sp)
	ld	$fp, 16($sp)
	ld	$ra, 24($sp)
	daddiu	$sp, $sp, 32
	jr	$ra
	nop
	.set	at
	.set	macro
	.set	reorder
	.end	main
$func_end1:
	.size	main, ($func_end1)-main

	.type	_str,@object
	.section	.rodata.str1.1,"aMS",@progbits,1
_str:
	.asciz	"test"
	.size	_str, 5

	.type	var,@object
	.comm	var,8,8

	.section	".note.GNU-stack","",@progbits
	.text
OpenPOWER on IntegriCloud