]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-mips-elf/mips-elf.exp
MIPS/BFD: Report `bfd_reloc_outofrange' errors as such
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf.exp
1 # Expect script for MIPS ELF linker tests
2 # Copyright (C) 2002-2016 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 if {[istarget "mips*-*-vxworks"]} {
23 set mipsvxtests {
24 {"VxWorks shared library test 1" "-shared -Tvxworks1.ld" ""
25 "-mips2" {vxworks1-lib.s}
26 {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
27 {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
28 "libvxworks1.so"}
29 {"VxWorks executable test 1 (dynamic)" \
30 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" ""
31 "-mips2" {vxworks1.s}
32 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
33 "vxworks1"}
34 {"VxWorks executable test 2 (dynamic)" \
35 "-Tvxworks1.ld -q --force-dynamic" ""
36 "-mips2" {vxworks2.s}
37 {{readelf --segments vxworks2.sd}}
38 "vxworks2"}
39 {"VxWorks executable test 2 (static)"
40 "-Tvxworks1.ld" ""
41 "-mips2" {vxworks2.s}
42 {{readelf --segments vxworks2-static.sd}}
43 "vxworks2"}
44 }
45 run_ld_link_tests $mipsvxtests
46 run_dump_test "vxworks1-static"
47 run_dump_test "vxworks-forced-local-1"
48 return
49 }
50
51 if {![istarget mips*-*-*] || ![is_elf_format]} {
52 return
53 }
54
55 set has_newabi [expr [istarget *-*-irix6*] \
56 || [istarget mips*-*-linux*] \
57 || [istarget mips*-sde-elf*] \
58 || [istarget mips*-mti-elf*] \
59 || [istarget mips*-img-elf*]]
60 set linux_gnu [expr [istarget mips*-*-linux*]]
61 set embedded_elf [expr [istarget mips*-*-elf]]
62
63 # Set defaults.
64 set abi_asflags(o32) "-32"
65 set abi_asflags(n32) "-march=from-abi -n32 -EB"
66 set abi_asflags(n64) "-march=from-abi -64 -EB"
67 set abi_ldflags(o32) ""
68 set abi_ldflags(n32) -melf32bmipn32
69 set abi_ldflags(n64) -melf64bmip
70
71 # Override as needed.
72 if { [istarget *-*-irix6*] } {
73 set abi_asflags(o32) "-32 -EB"
74 set abi_ldflags(o32) -melf32bsmip
75 } elseif { [istarget mips64*-linux*] } {
76 set abi_asflags(o32) "-32 -EB"
77 set abi_ldflags(o32) -melf32btsmip
78 } elseif { [istarget mips64*-*freebsd*] } {
79 set abi_asflags(o32) "-32 -EB"
80 set abi_ldflags(o32) -melf32btsmip_fbsd
81 }
82 if { [istarget mips*-*-linux*] || [istarget mips*-sde-elf*]
83 || [istarget mips*-mti-elf*] || [istarget mips*-img-elf*]} {
84 set abi_ldflags(n32) -melf32btsmipn32
85 set abi_ldflags(n64) -melf64btsmip
86 } elseif { [istarget mips64*-*freebsd*] } {
87 set abi_ldflags(n32) -melf32btsmipn32_fbsd
88 set abi_ldflags(n64) -melf64btsmip_fbsd
89 }
90
91 if { $linux_gnu } {
92 run_ld_link_tests [list \
93 [list "Dummy shared library for MIPS16 PIC test 1" \
94 "-shared -melf32btsmip" "" \
95 "-EB -32 -mips1" \
96 { mips16-pic-1-dummy.s } \
97 {} \
98 "mips16-pic-1-dummy.so"] \
99 [list "MIPS16 PIC test 1" \
100 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
101 "-EB -32 -mips1 -I $srcdir/$subdir" \
102 { mips16-pic-1a.s mips16-pic-1b.s } \
103 { { objdump { -dr -j.text } mips16-pic-1.dd }
104 { readelf -A mips16-pic-1.gd } } \
105 "mips16-pic-1"] \
106 [list "MIPS16 PIC test 2" \
107 "-melf32btsmip -T mips16-pic-1.ld -shared" "" \
108 "-EB -32 -mips1 -I $srcdir/$subdir" \
109 { mips16-pic-2a.s mips16-pic-2b.s } \
110 { { objdump { -dr -j.text } mips16-pic-2.dd } \
111 { readelf -A mips16-pic-2.gd } \
112 { readelf --symbols mips16-pic-2.nd } \
113 { readelf --relocs mips16-pic-2.rd } \
114 { readelf -d mips16-pic-2.ad } } \
115 "mips16-pic-2"] \
116 [list "MIPS16 PIC test 3" \
117 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
118 "-EB -32 -mips1 -I $srcdir/$subdir" \
119 { mips16-pic-3a.s mips16-pic-3b.s } \
120 { { objdump -dr mips16-pic-3.dd } \
121 { readelf --relocs mips16-pic-3.rd } \
122 { readelf -A mips16-pic-3.gd } } \
123 "mips16-pic-3"] \
124 [list "MIPS16 PIC test 4 (shared library)" \
125 "-shared -melf32btsmip -T mips16-pic-1.ld --version-script mips16-pic-4.ver" "" \
126 "-EB -32 -mips1" \
127 { mips16-pic-4a.s mips16-pic-4b.s } \
128 { { objdump -dr mips16-pic-4a.dd } \
129 { readelf --symbols mips16-pic-4a.nd } \
130 { readelf -A mips16-pic-4a.gd } } \
131 "mips16-pic-4.so"] \
132 [list "MIPS16 PIC test 4 (executable)" \
133 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-4.so" "" \
134 "-EB -32 -mips1" \
135 { mips16-pic-4c.s } \
136 { { objdump -dr mips16-pic-4b.dd } } \
137 "mips16-pic-4"]]
138 }
139
140 # Check MIPS16 markings being passed through link.
141 run_dump_test "mips16-1"
142
143 # MIPS branch offset final link checking.
144 run_dump_test "branch-misc-1"
145
146 # Jalx test
147 run_dump_test "jalx-1"
148
149 if { $linux_gnu } {
150 run_ld_link_tests [list \
151 [list "Dummy shared library for JALX test 2" \
152 "-shared -nostdlib -melf32btsmip" "" \
153 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -KPIC" \
154 { jalx-2-printf.s } \
155 {} \
156 "libjalx-2.so"] \
157 [list "Dummy external function for JALX test 2" \
158 "-r -melf32btsmip" "" \
159 "-G0 -EB -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
160 { jalx-2-ex.s } \
161 {} \
162 "jalx-2-ex.o.r"] \
163 [list "MIPS JALX test 2" \
164 "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r -melf32btsmip" "" \
165 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
166 { jalx-2-main.s } \
167 { { objdump -d jalx-2.dd } } \
168 "jalx-2"]]
169 }
170
171 run_dump_test "jalx-addend" [list [list ld $abi_ldflags(o32)]]
172 run_dump_test "jalx-local" [list [list ld $abi_ldflags(o32)]]
173 if $has_newabi {
174 run_dump_test "jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
175 run_dump_test "jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
176 run_dump_test "jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
177 run_dump_test "jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
178 }
179
180 run_dump_test "unaligned-jalx-0" [list [list ld $abi_ldflags(o32)]]
181 run_dump_test "unaligned-jalx-1" [list [list ld $abi_ldflags(o32)]]
182 run_dump_test "unaligned-jalx-2" [list [list ld $abi_ldflags(o32)]]
183 run_dump_test "unaligned-jalx-mips16-0" [list [list ld $abi_ldflags(o32)]]
184 run_dump_test "unaligned-jalx-mips16-1" [list [list ld $abi_ldflags(o32)]]
185 run_dump_test "unaligned-jalx-mips16-2" [list [list ld $abi_ldflags(o32)]]
186 run_dump_test "unaligned-jalx-micromips-0" [list [list ld $abi_ldflags(o32)]]
187 run_dump_test "unaligned-jalx-micromips-1" [list [list ld $abi_ldflags(o32)]]
188 run_dump_test "unaligned-jalx-micromips-2" [list [list ld $abi_ldflags(o32)]]
189
190 run_dump_test "unaligned-lwpc-0" [list [list ld $abi_ldflags(o32)]]
191 run_dump_test "unaligned-lwpc-1" [list [list ld $abi_ldflags(o32)]]
192 run_dump_test "unaligned-lwpc-2" [list [list ld $abi_ldflags(o32)]]
193 run_dump_test "unaligned-lwpc-3" [list [list ld $abi_ldflags(o32)]]
194 run_dump_test "unaligned-ldpc-0" [list [list ld $abi_ldflags(o32)]]
195 run_dump_test "unaligned-ldpc-1" [list [list ld $abi_ldflags(o32)]]
196 run_dump_test "unaligned-ldpc-2" [list [list ld $abi_ldflags(o32)]]
197 run_dump_test "unaligned-ldpc-3" [list [list ld $abi_ldflags(o32)]]
198 run_dump_test "unaligned-ldpc-4" [list [list ld $abi_ldflags(o32)]]
199
200 # Test multi-got link. We only do this on GNU/Linux because it requires
201 # the "traditional" emulations.
202 if { $linux_gnu } {
203 run_dump_test "multi-got-1"
204 run_dump_test "multi-got-no-shared"
205 run_dump_test "multi-got-hidden-1"
206 run_dump_test "multi-got-hidden-2"
207 }
208
209 # Test __gnu_local_gp accesses
210 if { $linux_gnu } {
211 run_dump_test "no-shared-1-o32"
212 if { $has_newabi } {
213 run_dump_test "no-shared-1-n32"
214 run_dump_test "no-shared-1-n64"
215 }
216 }
217
218 # Test PIE debug dynamic tags
219 if { $linux_gnu } {
220 run_dump_test "pie-o32"
221 if { $has_newabi } {
222 run_dump_test "pie-n32"
223 run_dump_test "pie-n64"
224 }
225 }
226
227 if $has_newabi {
228 if { $embedded_elf } {
229 run_dump_test "elf-rel-got-n32-embed" \
230 [list [list ld $abi_ldflags(n32)]]
231 run_dump_test "elf-rel-xgot-n32-embed" \
232 [list [list ld $abi_ldflags(n32)]]
233 } else {
234 run_dump_test "elf-rel-got-n32" [list [list ld $abi_ldflags(n32)]]
235 run_dump_test "elf-rel-xgot-n32" [list [list ld $abi_ldflags(n32)]]
236 }
237 if { $linux_gnu } {
238 run_dump_test "elf-rel-got-n64-linux" \
239 [list [list ld $abi_ldflags(n64)]]
240 run_dump_test "elf-rel-xgot-n64-linux" \
241 [list [list ld $abi_ldflags(n64)]]
242 } elseif { $embedded_elf } {
243 run_dump_test "elf-rel-got-n64-embed" \
244 [list [list ld $abi_ldflags(n64)]]
245 run_dump_test "elf-rel-xgot-n64-embed" \
246 [list [list ld $abi_ldflags(n64)]]
247 } else {
248 run_dump_test "elf-rel-got-n64" [list [list ld $abi_ldflags(n64)]]
249 run_dump_test "elf-rel-xgot-n64" [list [list ld $abi_ldflags(n64)]]
250 }
251
252 run_dump_test "relax-jalr-n32"
253 run_dump_test "relax-jalr-n32-shared"
254 run_dump_test "relax-jalr-n64"
255 run_dump_test "relax-jalr-n64-shared"
256 }
257
258 if { $linux_gnu } {
259 run_dump_test "rel32-o32"
260 if { $has_newabi } {
261 run_dump_test "rel32-n32"
262 run_dump_test "rel64"
263 }
264 # The first test checks that a mixed PIC/non-PIC relocatable link
265 # will not introduce any stubs itself, but will flag PIC functions
266 # for the final link.
267 #
268 # The second test checks that we insert stubs for calls from
269 # non-PIC functions to PIC functions when linking the original
270 # two objects together.
271 #
272 # The third test checks that we do the same when linking the
273 # result of the first link (with no other source files).
274 run_ld_link_tests {
275 {"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip" ""
276 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
277 {{objdump -dr pic-and-nonpic-1-rel.dd}
278 {readelf --symbols pic-and-nonpic-1-rel.nd}}
279 "pic-and-nonpic-1-rel.o"}
280 {"PIC and non-PIC test 1 (static 1)"
281 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
282 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
283 {{objdump -dr pic-and-nonpic-1.dd}
284 {readelf --symbols pic-and-nonpic-1.nd}}
285 "pic-and-nonpic-1-static1.o"}
286 {"PIC and non-PIC test 1 (static 2)"
287 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o" ""
288 "" {}
289 {{objdump -dr pic-and-nonpic-1.dd}
290 {readelf --symbols pic-and-nonpic-1.nd}}
291 "pic-and-nonpic-1-static2.o"}
292 }
293 run_dump_test "pic-and-nonpic-2"
294 run_ld_link_tests {
295 {"PIC and non-PIC test 3 (shared library)"
296 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
297 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
298 {{readelf --segments pic-and-nonpic-3a.sd}
299 {readelf -A pic-and-nonpic-3a.gd}
300 {objdump -dr pic-and-nonpic-3a.dd}}
301 "pic-and-nonpic-3a.so"}
302 {"PIC and non-PIC test 3 (executable)"
303 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so" ""
304 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
305 {{readelf --segments pic-and-nonpic-3b.sd}
306 {objdump -dr pic-and-nonpic-3b.dd}
307 {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
308 {readelf -A pic-and-nonpic-3b.gd}
309 {readelf --relocs pic-and-nonpic-3b.rd}
310 {readelf --symbols pic-and-nonpic-3b.nd}
311 {readelf -d pic-and-nonpic-3b.ad}}
312 "pic-and-nonpic-3b"}
313 }
314 run_dump_test "pic-and-nonpic-3-error"
315 run_ld_link_tests {
316 {"PIC and non-PIC test 4 (shared library)"
317 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
318 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
319 {}
320 "pic-and-nonpic-4a.so"}
321 {"PIC and non-PIC test 4 (executable)"
322 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so" ""
323 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
324 {{readelf --segments pic-and-nonpic-4b.sd}
325 {objdump -dr pic-and-nonpic-4b.dd}
326 {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
327 {readelf --relocs pic-and-nonpic-4b.rd}
328 {readelf --symbols pic-and-nonpic-4b.nd}
329 {readelf -d pic-and-nonpic-4b.ad}}
330 "pic-and-nonpic-4b"}
331 }
332 run_dump_test "pic-and-nonpic-4-error"
333 run_ld_link_tests {
334 {"PIC and non-PIC test 5 (executable)"
335 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so" ""
336 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
337 {{readelf --segments pic-and-nonpic-5b.sd}
338 {objdump -dr pic-and-nonpic-5b.dd}
339 {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
340 {readelf -A pic-and-nonpic-5b.gd}
341 {readelf --relocs pic-and-nonpic-5b.rd}
342 {readelf --symbols pic-and-nonpic-5b.nd}
343 {readelf -d pic-and-nonpic-5b.ad}}
344 "pic-and-nonpic-5b"}
345 }
346 set abis { o32 -32 elf32btsmip }
347 if $has_newabi {
348 lappend abis n32 -n32 elf32btsmipn32
349 lappend abis n64 -64 elf64btsmip
350 }
351 foreach { abi flag emul } $abis {
352 run_ld_link_tests [list \
353 [list "PIC and non-PIC test 6 ($abi shared library)" \
354 "-m$emul -shared -Tpic-and-nonpic-3a.ld" "" \
355 "$flag -EB -mips3" \
356 [list "pic-and-nonpic-6-${abi}a.s"] {} \
357 "pic-and-nonpic-6-${abi}.so"] \
358 [list "PIC and non-PIC test 6 ($abi executable)" \
359 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" "" \
360 "$flag -EB -mips3" \
361 [list "pic-and-nonpic-6-${abi}b.s" \
362 "pic-and-nonpic-6-${abi}c.s"] \
363 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
364 "objdump -dr pic-and-nonpic-6-${abi}.dd" \
365 "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
366 "readelf -A pic-and-nonpic-6-${abi}.gd" \
367 "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
368 "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
369 "readelf -d pic-and-nonpic-6-${abi}.ad"] \
370 "pic-and-nonpic-6-${abi}"]]
371
372 # This checks whether our linker scripts get the scope of _gp right,
373 # and must therefore use default scripts. If they don't, then -- in
374 # addition to dumps failing to match -- the final link fails with:
375 #
376 # ld: gp-hidden.o: undefined reference to symbol '_gp'
377 # ld: note: '_gp' is defined in DSO ./tmpdir/gp-hidden-lib-${abi}.so
378 # so try adding it to the linker command line
379 #
380 set suff64 [string map {o32 "" n32 "" n64 -64} $abi]
381 run_ld_link_tests [list \
382 [list \
383 "_gp scope test ($abi shared library)" \
384 "$abi_ldflags($abi) -shared" "" \
385 "$abi_asflags($abi) -KPIC" \
386 { gp-hidden-lib.s } \
387 [list \
388 "readelf --relocs gp-hidden-lib${suff64}.rd" \
389 "readelf --syms gp-hidden.sd"] \
390 "gp-hidden-lib-${abi}.so"] \
391 [list \
392 "_gp scope test ($abi versioned library)" \
393 "$abi_ldflags($abi) -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \
394 "$abi_asflags($abi) -KPIC" \
395 { gp-hidden-ver.s } \
396 [list \
397 "readelf --relocs gp-hidden-ver${suff64}.rd" \
398 "readelf --syms gp-hidden.sd"] \
399 "gp-hidden-ver-${abi}.so"] \
400 [list \
401 "_gp scope test ($abi executable)" \
402 "$abi_ldflags($abi) -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \
403 "$abi_asflags($abi) -call_nonpic" \
404 { gp-hidden.s } \
405 [list \
406 "readelf --relocs gp-hidden${suff64}.rd" \
407 "readelf --syms gp-hidden.sd"] \
408 "gp-hidden-${abi}"]]
409 }
410 }
411
412 if { $embedded_elf } {
413 run_dump_test "region1"
414 }
415
416 if $embedded_elf {
417 # This could work on other targets too, but would need the appropriate
418 # ld -m switch.
419 run_dump_test "reloc-1-rel"
420 }
421 if $has_newabi {
422 run_dump_test "reloc-1-n32" [list [list ld $abi_ldflags(n32)]]
423 run_dump_test "reloc-1-n64" [list [list ld $abi_ldflags(n64)]]
424 }
425 run_dump_test "reloc-2"
426 run_dump_test "reloc-merge-lo16"
427 run_dump_test "reloc-3"
428 if {$has_newabi} {
429 run_dump_test "reloc-3-n32"
430 }
431 run_dump_test "reloc-4"
432 run_dump_test "reloc-5"
433 if { $has_newabi } {
434 run_ld_link_tests [list \
435 [list \
436 "reloc test 6a" \
437 "-shared $abi_ldflags(n32)" "" \
438 "$abi_asflags(n32)" \
439 "reloc-6a.s" \
440 {} \
441 "reloc-6a.so"] \
442 [list \
443 "reloc test 6b" \
444 "$abi_ldflags(n32) tmpdir/reloc-6a.so" "" \
445 "$abi_asflags(n32)" \
446 "reloc-6b.s" \
447 {} \
448 "reloc-6b"]]
449 }
450
451 if {$has_newabi && $linux_gnu} {
452 run_dump_test "eh-frame1-n32"
453 run_dump_test "eh-frame1-n64"
454 run_dump_test "eh-frame2-n32"
455 run_dump_test "eh-frame2-n64"
456 }
457 if {$embedded_elf} {
458 run_dump_test "eh-frame3"
459 run_dump_test "eh-frame4"
460 }
461 if {$linux_gnu} {
462 set eh_frame5_test {
463 {"MIPS eh-frame 5"
464 "-melf32btsmip -shared -Teh-frame5.ld" ""
465 "-32 -EB"
466 {eh-frame5.s}
467 {{readelf {--relocs -wf} eh-frame5.d}}
468 "eh-frame5.so"}
469 }
470 run_ld_link_tests $eh_frame5_test
471 }
472
473 if {$embedded_elf} {
474 run_dump_test "compact-eh1"
475 run_dump_test "compact-eh2"
476 run_dump_test "compact-eh3"
477 }
478
479 if {$linux_gnu} {
480 run_dump_test "compact-eh4"
481 run_dump_test "compact-eh5"
482 run_dump_test "compact-eh6"
483 }
484
485 run_dump_test "jaloverflow"
486 run_dump_test "jaloverflow-2"
487 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(o32)] \
488 [list ld $abi_ldflags(o32)]]
489
490 if {$has_newabi} {
491 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(n32)] \
492 [list ld $abi_ldflags(n32)]]
493 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(n64)] \
494 [list ld $abi_ldflags(n64)]]
495 }
496
497 if {$has_newabi} {
498 run_dump_test "jalbal" [list [list ld $abi_ldflags(n32)]]
499 }
500
501 run_dump_test "mode-change-error-1"
502
503 run_dump_test "mips16-hilo"
504 if {$has_newabi} {
505 run_dump_test "mips16-hilo-n32"
506 }
507
508 if { $linux_gnu } {
509 if { $has_newabi } {
510 run_dump_test "textrel-1"
511 }
512 run_dump_test "got-page-1"
513 if $has_newabi {
514 run_dump_test "got-page-2"
515 run_dump_test "dyn-sec64"
516 }
517 run_dump_test "got-page-3"
518 run_ld_link_tests [subst {
519 {"GOT page 4 (one file)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
520 "" "$abi_asflags(o32) -mips2" {got-page-4b.s}
521 {{objdump -dr got-page-4a.d}
522 {readelf -A got-page-4a.got}}
523 "got-page-4a.so"}
524 {"GOT page 4 (two files)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
525 "" "$abi_asflags(o32) -mips2" {got-page-4a.s got-page-4b.s}
526 {{objdump -dr got-page-4b.d}
527 {readelf -A got-page-4b.got}}
528 "got-page-4b.so"}
529 }]
530 if $has_newabi {
531 run_ld_link_tests [subst {
532 {"GOT page 5" "-shared $abi_ldflags(n32) -T got-page-1.ld"
533 "" "$abi_asflags(n32)" {got-page-5.s}
534 {{objdump -dr got-page-5.d}
535 {readelf -A got-page-5.got}}
536 "got-page-5.so"}
537 {"GOT page 6" "-shared $abi_ldflags(n32) -T got-page-1.ld"
538 "" "$abi_asflags(n32)" {got-page-6.s}
539 {{objdump -dr got-page-6.d}
540 {readelf -A got-page-6.got}}
541 "got-page-6.so"}
542 {"GOT page 7 (order 1)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
543 "" "$abi_asflags(n32)"
544 {got-page-7a.s got-page-7b.s got-page-7c.s got-page-7d.s
545 got-page-7e.s}
546 {{objdump -dr got-page-7.d}
547 {readelf -A got-page-7.got}}
548 "got-page-7a.so"}
549 {"GOT page 7 (order 2)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
550 "" "$abi_asflags(n32)"
551 {got-page-7e.s got-page-7a.s got-page-7b.s got-page-7c.s
552 got-page-7d.s}
553 {{objdump -dr got-page-7.d}
554 {readelf -A got-page-7.got}}
555 "got-page-7b.so"}
556 }]
557 }
558 run_dump_test "got-dump-1"
559 if $has_newabi {
560 run_dump_test "got-dump-2"
561 }
562 run_dump_test "reloc-estimate-1"
563 }
564
565 if $has_newabi {
566 run_dump_test "emit-relocs-1"
567 }
568
569 run_dump_test "hash1a"
570 run_dump_test "hash1b"
571 run_dump_test "hash1c"
572
573 if {[istarget mips*-*-linux*]} {
574 # The number of symbols that are always included in the symbol table
575 # for these tests. The 4 are:
576 #
577 # the null symbol entry
578 # the .MIPS.stubs section symbol
579 set base_syms 2
580 foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
581 run_ld_link_tests \
582 [list [list \
583 "Stub for dynsym 0x$dynsym" \
584 "-shared -melf32btsmip -T stub-dynsym-1.ld" "" \
585 [concat \
586 "-EB -march=mips1 -32 -KPIC" \
587 "--defsym base_syms=$base_syms" \
588 "--defsym dynsym=0x$dynsym"] \
589 [list "stub-dynsym-1.s"] \
590 [list [list \
591 "objdump" "-dz" \
592 "stub-dynsym-1-$dynsym.d"]] \
593 "stub-dynsym-1-$dynsym"]]
594 }
595 }
596
597 # For tests which may involve multiple files, use run_ld_link_tests.
598
599 # List contains test-items with 3 items followed by 2 lists:
600 # 0:name 1:ld early options 2:ld late options 3:assembler options
601 # 4:filenames of assembler files 5: action and options. 6: name of output file
602
603 # Actions:
604 # objdump: Apply objdump options on result. Compare with regex (last arg).
605 # nm: Apply nm options on result. Compare with regex (last arg).
606 # readelf: Apply readelf options on result. Compare with regex (last arg).
607
608 set mips_tls_tests {
609 {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld" ""
610 "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
611 {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
612 "tls-static-o32"}
613 {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld" ""
614 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
615 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
616 "tlslib-o32.so"}
617 {"Dynamic executable with TLS"
618 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so" ""
619 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
620 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
621 "tls-dynamic-o32"}
622 {"Shared library with multiple GOTs and TLS"
623 "-shared -melf32btsmip -T mips-lib.ld" ""
624 "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
625 {{readelf {-d -r} tls-multi-got-1.r}
626 {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
627 {objdump -Rsj.got tls-multi-got-1.got}}
628 "tlslib-multi.so"}
629 {"Shared library with TLS and versioning"
630 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver" ""
631 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
632 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
633 "tlslib-o32-ver.so"}
634 {"Dynamic executable with TLS and versioning"
635 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so" ""
636 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
637 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
638 "tls-dynamic-o32-ver"}
639 {"Dynamic executable with TLS and versioning (order 2)"
640 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o" ""
641 "-EB -march=mips1 -32 -KPIC" {}
642 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
643 "tls-dynamic-o32-ver-2"}
644 {"Dynamic executable with TLS and versioning (order 3)"
645 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o" ""
646 "-EB -march=mips1 -32 -KPIC" {}
647 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
648 "tls-dynamic-o32-ver-3"}
649 {"Shared library with TLS and hidden symbols"
650 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver" ""
651 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
652 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
653 "tlslib-o32-hidden.so"}
654 {"Shared library with TLS and hidden symbols (2)"
655 "-shared -melf32btsmip -T mips-lib.ld" ""
656 "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
657 {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
658 "tls-hidden2.so"}
659 {"Shared library with TLS and hidden symbols (3)"
660 "-shared -melf32btsmip -T tls-hidden3.ld" ""
661 "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
662 {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
663 {readelf --relocs tls-hidden3.r}}
664 "tls-hidden3.so"}
665 {"Shared library with TLS and hidden symbols (4)"
666 "-shared -melf32btsmip -T tls-hidden3.ld" ""
667 "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
668 {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
669 "tls-hidden4.so"}
670 }
671
672 if {[istarget mips*-*-linux*]} {
673 run_ld_link_tests $mips_tls_tests
674 }
675
676 set mips16_call_global_test [list \
677 [list "Global calls from mips16" \
678 "$abi_ldflags(o32) -T no-shared-1.ld" "" \
679 "$abi_asflags(o32) -mips32r2" \
680 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
681 {{objdump -dr mips16-call-global.d}} \
682 "mips16-call-global"]]
683
684 run_ld_link_tests $mips16_call_global_test
685
686 set mips16_intermix_test [list \
687 [list "Intermixing mips32 and mips16 functions" \
688 "$abi_ldflags(o32)" "" \
689 "$abi_asflags(o32) -mips32r2" \
690 {mips16-intermix-1.s mips16-intermix-2.s} \
691 {{objdump -t mips16-intermix.d}} \
692 "mips16-intermix"]]
693
694 run_ld_link_tests $mips16_intermix_test
695
696 run_dump_test "mips16-local-stubs-1"
697
698 set mips16_fp_stub_test [list \
699 [list "Floating-point stub for mips16 functions" \
700 "$abi_ldflags(o32)" "" \
701 "$abi_asflags(o32) -mips32r2" \
702 {mips16-fp-stub-1.s mips16-fp-stub-2.s} \
703 {{readelf --debug-dump=frames mips16-fp-stub.d}} \
704 "mips16-fp-stub"]]
705
706 run_ld_link_tests $mips16_fp_stub_test
707
708 set o32flagslist [list [list as $abi_asflags(o32)] [list ld $abi_ldflags(o32)]]
709
710 foreach firstfpabi [list 0 1 2 3 4 5 6 7 ] {
711 foreach secondfpabi [list 4 5 6 7 ] {
712 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
713 }
714 }
715 foreach firstfpabi [list 4 5 6 7 ] {
716 foreach secondfpabi [list 0 1 2 3 8 9] {
717 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
718 }
719 }
720 foreach firstfpabi [list 0 1 2 3 ] {
721 foreach secondfpabi [list 0 1 2 3 8 9] {
722 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}"
723 }
724 }
725
726 run_dump_test "attr-gnu-4-81"
727
728 run_dump_test "attr-gnu-8-00"
729 run_dump_test "attr-gnu-8-01"
730 run_dump_test "attr-gnu-8-02"
731 run_dump_test "attr-gnu-8-10"
732 run_dump_test "attr-gnu-8-11"
733 run_dump_test "attr-gnu-8-12"
734 run_dump_test "attr-gnu-8-20"
735 run_dump_test "attr-gnu-8-21"
736 run_dump_test "attr-gnu-8-22"
737
738 run_dump_test "attr-gnu-4-0-ph" $o32flagslist
739 run_dump_test "attr-gnu-4-1-ph" $o32flagslist
740 run_dump_test "attr-gnu-4-2-ph" $o32flagslist
741 run_dump_test "attr-gnu-4-3-ph" $o32flagslist
742 run_dump_test "attr-gnu-4-4-ph" $o32flagslist
743 run_dump_test "attr-gnu-4-5-ph" $o32flagslist
744 run_dump_test "attr-gnu-4-6-ph" $o32flagslist
745 run_dump_test "attr-gnu-4-7-ph" $o32flagslist
746
747 if $has_newabi {
748 run_dump_test "attr-gnu-4-0-n32-ph"
749 run_dump_test "attr-gnu-4-1-n32-ph"
750 run_dump_test "attr-gnu-4-2-n32-ph"
751 run_dump_test "attr-gnu-4-3-n32-ph"
752 run_dump_test "attr-gnu-4-0-n64-ph"
753 run_dump_test "attr-gnu-4-1-n64-ph"
754 run_dump_test "attr-gnu-4-2-n64-ph"
755 run_dump_test "attr-gnu-4-3-n64-ph"
756 }
757
758 run_dump_test "abiflags-strip1-ph" $o32flagslist
759 run_dump_test "abiflags-strip2-ph" $o32flagslist
760 run_dump_test "abiflags-strip3-ph" $o32flagslist
761 run_dump_test "abiflags-strip4-ph" $o32flagslist
762 run_dump_test "abiflags-strip5-ph" $o32flagslist
763 run_dump_test "abiflags-strip6-ph" $o32flagslist
764 run_dump_test "abiflags-strip7-ph" $o32flagslist
765 run_dump_test "abiflags-strip8-ph" $o32flagslist
766 run_dump_test "abiflags-strip9-ph" $o32flagslist
767 run_dump_test "abiflags-strip10-ph" $o32flagslist
768
769 run_dump_test "nan-legacy"
770 run_dump_test "nan-2008"
771 run_dump_test "nan-mixed-1"
772 run_dump_test "nan-mixed-2"
773
774 if { $linux_gnu } {
775 run_ld_link_tests {
776 {"GOT and versioning 1"
777 "-shared -melf32btsmip --version-script got-vers-1.ver" ""
778 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
779 {{readelf -d got-vers-1.dd}
780 {readelf --symbols got-vers-1.sd}
781 {readelf --relocs got-vers-1.rd}}
782 "got-vers-1.so"}
783 }
784 }
785
786 run_dump_test "undefined"
787
788 # Test the conversion from jr to b
789 if { $linux_gnu } {
790 run_dump_test "jr-to-b-1"
791 run_dump_test "jr-to-b-2"
792 }
793
794 # MIPS16 and microMIPS interlinking test.
795 run_dump_test "mips16-and-micromips"
796
797 # Export class call relocation tests.
798 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
799 foreach { abi } $abis {
800 set loadaddr [string map \
801 {o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
802 set suff [subst \
803 [expr { [istarget *-*-irix*] \
804 ? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
805 : $abi }]]
806 run_ld_link_tests [list \
807 [list \
808 "MIPS export class call relocation test ($abi)" \
809 "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
810 "$abi_asflags($abi) -mips3 -KPIC" \
811 [list export-class-call16-${abi}.s export-class-call16-def.s] \
812 [list \
813 "objdump -d export-class-call16-${suff}.dd" \
814 "readelf -A export-class-call16-${abi}.gd"] \
815 "export-class-call16-${abi}.so"]]
816 }
817
818 # Magic __ehdr_start symbol tests.
819 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
820 foreach { abi } $abis {
821 set suff [string map {o32 o32 n32 new n64 new} $abi]
822 run_ld_link_tests [list \
823 [list \
824 "MIPS magic __ehdr_start symbol test 1 ($abi)" \
825 "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
826 "$abi_asflags($abi)" \
827 [list ehdr_start-${suff}.s] \
828 [list "readelf -s ehdr_start-1.nd"] \
829 "ehdr_start-1-${abi}"]]
830 if [regexp "(?:n32|n64)" "$abi"] {
831 setup_kfail "mips*-*-*" "ld/15428"
832 }
833 run_ld_link_tests [list \
834 [list \
835 "MIPS magic __ehdr_start symbol test 2 ($abi)" \
836 "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
837 "$abi_asflags($abi)" \
838 [list ehdr_start-${suff}.s] \
839 [list "readelf -s ehdr_start-2.nd"] \
840 "ehdr_start-2-${abi}"]]
841 }
842
843 # R_MIPS_JALR reloc tests.
844 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
845 foreach { abi } $abis {
846 run_ld_link_tests [list \
847 [list \
848 "MIPS JALR reloc test ($abi)" \
849 "$abi_ldflags($abi) -T jalr3.ld" "" \
850 "$abi_asflags($abi)" \
851 [list ../../../gas/testsuite/gas/mips/jalr3.s] \
852 [list "objdump -d jalr3.dd"] \
853 "jalr3-${abi}"]]
854 }
855
856 proc build_mips_plt_lib { abi } {
857 global abi_asflags
858 global abi_ldflags
859
860 run_ld_link_tests [list \
861 [list "Shared $abi library for compressed PLT tests" \
862 "-shared $abi_ldflags($abi)" "" \
863 "$abi_asflags($abi)" \
864 { compressed-plt-1-dyn.s } \
865 {} \
866 "compressed-plt-1-${abi}-dyn.so"]]
867 }
868
869 proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
870 global abi_asflags
871 global abi_ldflags
872
873 set as_flags "$abi_asflags($abi) --defsym filter=$filter"
874 append as_flags " --defsym micromips=$micromips --defsym $abi=1"
875 if {[string equal $abi o32]} {
876 append as_flags " -march=mips2"
877 }
878 set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
879 set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
880 set files [list]
881 if { $filter & 3 } {
882 lappend files compressed-plt-1a.s
883 }
884 if { $filter & 12 } {
885 lappend files compressed-plt-1b.s
886 }
887 if { $filter & 16 } {
888 lappend files compressed-plt-1c.s
889 }
890 eval [list lappend files] $extra
891 set readelf_flags "-A --syms --relocs -d"
892 if { [string match "*word*" $suffix] } {
893 append readelf_flags " -x.data"
894 }
895 set objdump_flags "-d -Mgpr-names=numeric"
896 set basename "compressed-plt-1-${abi}-${suffix}"
897 run_ld_link_tests [list \
898 [list "$name" $ld_flags $dynobj \
899 "$as_flags" $files \
900 [list [list readelf $readelf_flags ${basename}.rd] \
901 [list objdump $objdump_flags ${basename}.od]] \
902 $basename]]
903 }
904
905 if { $linux_gnu } {
906 build_mips_plt_lib o32
907 run_mips_plt_test "o32 PLTs for standard encoding" o32 28 0 se
908 run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 19 0 mips16-only
909 run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 19 1 umips-only
910 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
911 o32 -1 0 mips16
912 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
913 o32 -1 0 mips16-got compressed-plt-1d.s
914 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
915 o32 -1 0 mips16-word compressed-plt-1e.s
916 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
917 o32 -1 1 umips
918 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
919 o32 -1 1 umips-got compressed-plt-1d.s
920 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
921 o32 -1 1 umips-word compressed-plt-1e.s
922
923 if $has_newabi {
924 build_mips_plt_lib n32
925 run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
926 n32 -1 0 mips16
927 run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
928 n32 -1 1 umips
929 }
930 }
931
932 # PR ld/19908 export class tests.
933 if { $linux_gnu } {
934 run_ld_link_tests [list \
935 [list "Shared library for MIPS export class symbol reference tests" \
936 "$abi_ldflags(o32) -shared" "" \
937 "$abi_asflags(o32)" \
938 { export-class-ref-f2.s } \
939 { { readelf --dyn-syms export-class-ref-lib.sd } } \
940 "export-class-ref-lib.so"]]
941 foreach { class flag } { internal 1 hidden 2 protected 3 } {
942 run_ld_link_tests [list \
943 [list "MIPS $class symbol reference test 1" \
944 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
945 "$abi_asflags(o32) --defsym defv=$flag" \
946 { export-class-ref-f0.s export-class-ref-f1.s } \
947 [list [list readelf --dyn-syms export-$class-ref.sd] \
948 [list readelf --dyn-syms export-local-ref.sd]] \
949 "export-$class-ref"] \
950 [list "MIPS $class symbol reference test 2" \
951 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
952 "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
953 { export-class-ref-f0.s export-class-ref-f1.s } \
954 [list [list readelf --dyn-syms export-$class-ref.sd] \
955 [list readelf --dyn-syms export-local-ref.sd]] \
956 "export-$class-ref"]]
957 }
958 }