1 # Expect script for MIPS ELF linker tests
2 # Copyright (C) 2002-2016 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 if {[istarget "mips*-*-vxworks"]} {
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}}
29 {"VxWorks executable test 1 (dynamic)" \
30 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" ""
32 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
34 {"VxWorks executable test 2 (dynamic)" \
35 "-Tvxworks1.ld -q --force-dynamic" ""
37 {{readelf --segments vxworks2.sd}}
39 {"VxWorks executable test 2 (static)"
42 {{readelf --segments vxworks2-static.sd}}
45 run_ld_link_tests $mipsvxtests
46 run_dump_test "vxworks1-static"
47 run_dump_test "vxworks-forced-local-1"
51 if {![istarget mips*-*-*] || ![is_elf_format]} {
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]]
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
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
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
92 run_ld_link_tests [list \
93 [list "Dummy shared library for MIPS16 PIC test 1" \
94 "-shared -melf32btsmip" "" \
96 { mips16-pic-1-dummy.s } \
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 } } \
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 } } \
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 } } \
124 [list "MIPS16 PIC test 4 (shared library)" \
125 "-shared -melf32btsmip -T mips16-pic-1.ld --version-script mips16-pic-4.ver" "" \
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 } } \
132 [list "MIPS16 PIC test 4 (executable)" \
133 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-4.so" "" \
135 { mips16-pic-4c.s } \
136 { { objdump -dr mips16-pic-4b.dd } } \
140 # Check MIPS16 markings being passed through link.
141 run_dump_test "mips16-1"
143 # MIPS branch offset final link checking.
144 run_dump_test "branch-misc-1"
145 run_dump_test "branch-misc-2"
146 run_dump_test "branch-absolute" [list [list ld $abi_ldflags(o32)]]
147 run_dump_test "branch-absolute-addend" [list [list ld $abi_ldflags(o32)]]
149 run_dump_test "branch-absolute-n32" [list [list ld $abi_ldflags(n32)]]
150 run_dump_test "branch-absolute-addend-n32" \
151 [list [list ld $abi_ldflags(n32)]]
152 run_dump_test "branch-absolute-n64" [list [list ld $abi_ldflags(n64)]]
153 run_dump_test "branch-absolute-addend-n64" \
154 [list [list ld $abi_ldflags(n64)]]
157 run_dump_test "mips16-branch-2" [list [list ld $abi_ldflags(o32)]]
158 run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
159 run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
160 run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
161 run_dump_test "mips16-branch-absolute" [list [list ld $abi_ldflags(o32)]]
162 run_dump_test "mips16-branch-absolute-addend" \
163 [list [list ld $abi_ldflags(o32)]]
165 run_dump_test "mips16-branch-absolute-n32" \
166 [list [list ld $abi_ldflags(n32)]]
167 run_dump_test "mips16-branch-absolute-addend-n32" \
168 [list [list ld $abi_ldflags(n32)]]
169 run_dump_test "mips16-branch-absolute-n64" \
170 [list [list ld $abi_ldflags(n64)]]
171 run_dump_test "mips16-branch-absolute-addend-n64" \
172 [list [list ld $abi_ldflags(n64)]]
175 run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
176 run_dump_test "micromips-branch-absolute-addend" \
177 [list [list ld $abi_ldflags(o32)]]
179 run_dump_test "micromips-branch-absolute-n32" \
180 [list [list ld $abi_ldflags(n32)]]
181 run_dump_test "micromips-branch-absolute-addend-n32" \
182 [list [list ld $abi_ldflags(n32)]]
183 run_dump_test "micromips-branch-absolute-n64" \
184 [list [list ld $abi_ldflags(n64)]]
185 run_dump_test "micromips-branch-absolute-addend-n64" \
186 [list [list ld $abi_ldflags(n64)]]
190 run_dump_test "jalx-1"
193 run_ld_link_tests [list \
194 [list "Dummy shared library for JALX test 2" \
195 "-shared -nostdlib -melf32btsmip" "" \
196 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -KPIC" \
197 { jalx-2-printf.s } \
200 [list "Dummy external function for JALX test 2" \
201 "-r -melf32btsmip" "" \
202 "-G0 -EB -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
206 [list "MIPS JALX test 2" \
207 "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r -melf32btsmip" "" \
208 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
210 { { objdump -d jalx-2.dd } } \
214 run_dump_test "jalx-addend" [list [list ld $abi_ldflags(o32)]]
215 run_dump_test "jalx-local" [list [list ld $abi_ldflags(o32)]]
216 run_dump_test "bal-jalx-addend" [list [list ld $abi_ldflags(o32)]]
217 run_dump_test "bal-jalx-local" [list [list ld $abi_ldflags(o32)]]
218 run_dump_test "bal-jalx-pic" [list [list ld $abi_ldflags(o32)]]
220 run_dump_test "jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
221 run_dump_test "jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
222 run_dump_test "bal-jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
223 run_dump_test "bal-jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
224 run_dump_test "bal-jalx-pic-n32" [list [list ld $abi_ldflags(n32)]]
225 run_dump_test "jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
226 run_dump_test "jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
227 run_dump_test "bal-jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
228 run_dump_test "bal-jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
229 run_dump_test "bal-jalx-pic-n64" [list [list ld $abi_ldflags(n64)]]
232 run_dump_test "unaligned-jalx-0" [list [list ld $abi_ldflags(o32)]]
233 run_dump_test "unaligned-jalx-1" [list [list ld $abi_ldflags(o32)]]
234 run_dump_test "unaligned-jalx-2" [list [list ld $abi_ldflags(o32)]]
235 run_dump_test "unaligned-jalx-3" [list [list ld $abi_ldflags(o32)]]
236 run_dump_test "unaligned-jalx-mips16-0" [list [list ld $abi_ldflags(o32)]]
237 run_dump_test "unaligned-jalx-mips16-1" [list [list ld $abi_ldflags(o32)]]
238 run_dump_test "unaligned-jalx-micromips-0" [list [list ld $abi_ldflags(o32)]]
239 run_dump_test "unaligned-jalx-micromips-1" [list [list ld $abi_ldflags(o32)]]
242 run_dump_test "unaligned-jalx-addend-0" \
243 [list [list ld $abi_ldflags(n32)]]
244 run_dump_test "unaligned-jalx-addend-1" \
245 [list [list ld $abi_ldflags(n32)]]
246 run_dump_test "unaligned-jalx-addend-2" \
247 [list [list ld $abi_ldflags(n32)]]
248 run_dump_test "unaligned-jalx-addend-3" \
249 [list [list ld $abi_ldflags(n32)]]
250 run_dump_test "unaligned-jalx-addend-mips16-0" \
251 [list [list ld $abi_ldflags(n32)]]
252 run_dump_test "unaligned-jalx-addend-mips16-1" \
253 [list [list ld $abi_ldflags(n32)]]
254 run_dump_test "unaligned-jalx-addend-micromips-0" \
255 [list [list ld $abi_ldflags(n32)]]
256 run_dump_test "unaligned-jalx-addend-micromips-1" \
257 [list [list ld $abi_ldflags(n32)]]
260 run_dump_test "unaligned-branch" [list [list ld $abi_ldflags(o32)]]
263 run_dump_test "unaligned-branch-2" \
264 [list [list ld $abi_ldflags(n32)]]
265 run_dump_test "unaligned-branch-r6-1" \
266 [list [list ld $abi_ldflags(n32)]]
267 run_dump_test "unaligned-branch-r6-2" \
268 [list [list ld $abi_ldflags(n32)]]
269 run_dump_test "unaligned-branch-mips16" \
270 [list [list ld $abi_ldflags(n32)]]
271 run_dump_test "unaligned-branch-micromips" \
272 [list [list ld $abi_ldflags(n32)]]
273 run_dump_test "unaligned-jump" \
274 [list [list ld $abi_ldflags(n32)]]
275 run_dump_test "unaligned-jump-mips16" \
276 [list [list ld $abi_ldflags(n32)]]
277 run_dump_test "unaligned-jump-micromips" \
278 [list [list ld $abi_ldflags(n32)]]
281 run_dump_test "unaligned-lwpc-0" [list [list ld $abi_ldflags(o32)]]
282 run_dump_test "unaligned-lwpc-1" [list [list ld $abi_ldflags(o32)]]
283 run_dump_test "unaligned-ldpc-0" [list [list ld $abi_ldflags(o32)]]
284 run_dump_test "unaligned-ldpc-1" [list [list ld $abi_ldflags(o32)]]
286 # Test multi-got link. We only do this on GNU/Linux because it requires
287 # the "traditional" emulations.
289 run_dump_test "multi-got-1"
290 run_dump_test "multi-got-no-shared"
291 run_dump_test "multi-got-hidden-1"
292 run_dump_test "multi-got-hidden-2"
295 # Test __gnu_local_gp accesses
297 run_dump_test "no-shared-1-o32"
299 run_dump_test "no-shared-1-n32"
300 run_dump_test "no-shared-1-n64"
304 # Test PIE debug dynamic tags
306 run_dump_test "pie-o32"
308 run_dump_test "pie-n32"
309 run_dump_test "pie-n64"
314 if { $embedded_elf } {
315 run_dump_test "elf-rel-got-n32-embed" \
316 [list [list ld $abi_ldflags(n32)]]
317 run_dump_test "elf-rel-xgot-n32-embed" \
318 [list [list ld $abi_ldflags(n32)]]
320 run_dump_test "elf-rel-got-n32" [list [list ld $abi_ldflags(n32)]]
321 run_dump_test "elf-rel-xgot-n32" [list [list ld $abi_ldflags(n32)]]
324 run_dump_test "elf-rel-got-n64-linux" \
325 [list [list ld $abi_ldflags(n64)]]
326 run_dump_test "elf-rel-xgot-n64-linux" \
327 [list [list ld $abi_ldflags(n64)]]
328 } elseif { $embedded_elf } {
329 run_dump_test "elf-rel-got-n64-embed" \
330 [list [list ld $abi_ldflags(n64)]]
331 run_dump_test "elf-rel-xgot-n64-embed" \
332 [list [list ld $abi_ldflags(n64)]]
334 run_dump_test "elf-rel-got-n64" [list [list ld $abi_ldflags(n64)]]
335 run_dump_test "elf-rel-xgot-n64" [list [list ld $abi_ldflags(n64)]]
338 run_dump_test "relax-jalr-n32"
339 run_dump_test "relax-jalr-n32-shared"
340 run_dump_test "relax-jalr-n64"
341 run_dump_test "relax-jalr-n64-shared"
345 run_dump_test "rel32-o32"
347 run_dump_test "rel32-n32"
348 run_dump_test "rel64"
350 # The first test checks that a mixed PIC/non-PIC relocatable link
351 # will not introduce any stubs itself, but will flag PIC functions
352 # for the final link.
354 # The second test checks that we insert stubs for calls from
355 # non-PIC functions to PIC functions when linking the original
356 # two objects together.
358 # The third test checks that we do the same when linking the
359 # result of the first link (with no other source files).
361 {"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip" ""
362 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
363 {{objdump -dr pic-and-nonpic-1-rel.dd}
364 {readelf --symbols pic-and-nonpic-1-rel.nd}}
365 "pic-and-nonpic-1-rel.o"}
366 {"PIC and non-PIC test 1 (static 1)"
367 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
368 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
369 {{objdump -dr pic-and-nonpic-1.dd}
370 {readelf --symbols pic-and-nonpic-1.nd}}
371 "pic-and-nonpic-1-static1.o"}
372 {"PIC and non-PIC test 1 (static 2)"
373 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o" ""
375 {{objdump -dr pic-and-nonpic-1.dd}
376 {readelf --symbols pic-and-nonpic-1.nd}}
377 "pic-and-nonpic-1-static2.o"}
379 run_dump_test "pic-and-nonpic-2"
381 {"PIC and non-PIC test 3 (shared library)"
382 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
383 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
384 {{readelf --segments pic-and-nonpic-3a.sd}
385 {readelf -A pic-and-nonpic-3a.gd}
386 {objdump -dr pic-and-nonpic-3a.dd}}
387 "pic-and-nonpic-3a.so"}
388 {"PIC and non-PIC test 3 (executable)"
389 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so" ""
390 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
391 {{readelf --segments pic-and-nonpic-3b.sd}
392 {objdump -dr pic-and-nonpic-3b.dd}
393 {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
394 {readelf -A pic-and-nonpic-3b.gd}
395 {readelf --relocs pic-and-nonpic-3b.rd}
396 {readelf --symbols pic-and-nonpic-3b.nd}
397 {readelf -d pic-and-nonpic-3b.ad}}
400 run_dump_test "pic-and-nonpic-3-error"
402 {"PIC and non-PIC test 4 (shared library)"
403 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
404 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
406 "pic-and-nonpic-4a.so"}
407 {"PIC and non-PIC test 4 (executable)"
408 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so" ""
409 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
410 {{readelf --segments pic-and-nonpic-4b.sd}
411 {objdump -dr pic-and-nonpic-4b.dd}
412 {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
413 {readelf --relocs pic-and-nonpic-4b.rd}
414 {readelf --symbols pic-and-nonpic-4b.nd}
415 {readelf -d pic-and-nonpic-4b.ad}}
418 run_dump_test "pic-and-nonpic-4-error"
420 {"PIC and non-PIC test 5 (executable)"
421 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so" ""
422 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
423 {{readelf --segments pic-and-nonpic-5b.sd}
424 {objdump -dr pic-and-nonpic-5b.dd}
425 {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
426 {readelf -A pic-and-nonpic-5b.gd}
427 {readelf --relocs pic-and-nonpic-5b.rd}
428 {readelf --symbols pic-and-nonpic-5b.nd}
429 {readelf -d pic-and-nonpic-5b.ad}}
432 set abis { o32 -32 elf32btsmip }
434 lappend abis n32 -n32 elf32btsmipn32
435 lappend abis n64 -64 elf64btsmip
437 foreach { abi flag emul } $abis {
438 run_ld_link_tests [list \
439 [list "PIC and non-PIC test 6 ($abi shared library)" \
440 "-m$emul -shared -Tpic-and-nonpic-3a.ld" "" \
442 [list "pic-and-nonpic-6-${abi}a.s"] {} \
443 "pic-and-nonpic-6-${abi}.so"] \
444 [list "PIC and non-PIC test 6 ($abi executable)" \
445 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" "" \
447 [list "pic-and-nonpic-6-${abi}b.s" \
448 "pic-and-nonpic-6-${abi}c.s"] \
449 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
450 "objdump -dr pic-and-nonpic-6-${abi}.dd" \
451 "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
452 "readelf -A pic-and-nonpic-6-${abi}.gd" \
453 "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
454 "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
455 "readelf -d pic-and-nonpic-6-${abi}.ad"] \
456 "pic-and-nonpic-6-${abi}"]]
458 # This checks whether our linker scripts get the scope of _gp right,
459 # and must therefore use default scripts. If they don't, then -- in
460 # addition to dumps failing to match -- the final link fails with:
462 # ld: gp-hidden.o: undefined reference to symbol '_gp'
463 # ld: note: '_gp' is defined in DSO ./tmpdir/gp-hidden-lib-${abi}.so
464 # so try adding it to the linker command line
466 set suff64 [string map {o32 "" n32 "" n64 -64} $abi]
467 run_ld_link_tests [list \
469 "_gp scope test ($abi shared library)" \
470 "$abi_ldflags($abi) -shared" "" \
471 "$abi_asflags($abi) -KPIC" \
472 { gp-hidden-lib.s } \
474 "readelf --relocs gp-hidden-lib${suff64}.rd" \
475 "readelf --syms gp-hidden.sd"] \
476 "gp-hidden-lib-${abi}.so"] \
478 "_gp scope test ($abi versioned library)" \
479 "$abi_ldflags($abi) -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \
480 "$abi_asflags($abi) -KPIC" \
481 { gp-hidden-ver.s } \
483 "readelf --relocs gp-hidden-ver${suff64}.rd" \
484 "readelf --syms gp-hidden.sd"] \
485 "gp-hidden-ver-${abi}.so"] \
487 "_gp scope test ($abi executable)" \
488 "$abi_ldflags($abi) -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \
489 "$abi_asflags($abi) -call_nonpic" \
492 "readelf --relocs gp-hidden${suff64}.rd" \
493 "readelf --syms gp-hidden.sd"] \
498 if { $embedded_elf } {
499 run_dump_test "region1"
503 # This could work on other targets too, but would need the appropriate
505 run_dump_test "reloc-1-rel"
508 run_dump_test "reloc-1-n32" [list [list ld $abi_ldflags(n32)]]
509 run_dump_test "reloc-1-n64" [list [list ld $abi_ldflags(n64)]]
511 run_dump_test "reloc-2"
512 run_dump_test "reloc-merge-lo16"
513 run_dump_test "reloc-3"
515 run_dump_test "reloc-3-n32"
517 run_dump_test "reloc-4"
518 run_dump_test "reloc-5"
520 run_ld_link_tests [list \
523 "-shared $abi_ldflags(n32)" "" \
524 "$abi_asflags(n32)" \
530 "$abi_ldflags(n32) tmpdir/reloc-6a.so" "" \
531 "$abi_asflags(n32)" \
537 run_dump_test "reloc-local-overflow" [list [list ld $abi_ldflags(o32)]]
539 if {$has_newabi && $linux_gnu} {
540 run_dump_test "eh-frame1-n32"
541 run_dump_test "eh-frame1-n64"
542 run_dump_test "eh-frame2-n32"
543 run_dump_test "eh-frame2-n64"
546 run_dump_test "eh-frame3"
547 run_dump_test "eh-frame4"
552 "-melf32btsmip -shared -Teh-frame5.ld" ""
555 {{readelf {--relocs -wf} eh-frame5.d}}
558 run_ld_link_tests $eh_frame5_test
562 run_dump_test "compact-eh1"
563 run_dump_test "compact-eh2"
564 run_dump_test "compact-eh3"
568 run_dump_test "compact-eh4"
569 run_dump_test "compact-eh5"
570 run_dump_test "compact-eh6"
573 run_dump_test "jaloverflow"
574 run_dump_test "jaloverflow-2"
576 run_dump_test "jal-global-overflow-0" [list [list ld $abi_ldflags(o32)]]
577 run_dump_test "jal-global-overflow-1" [list [list ld $abi_ldflags(o32)]]
578 run_dump_test "jal-local-overflow-0" [list [list ld $abi_ldflags(o32)]]
579 run_dump_test "jal-local-overflow-1" [list [list ld $abi_ldflags(o32)]]
581 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(o32)] \
582 [list ld $abi_ldflags(o32)]]
585 run_dump_test "undefweak-overflow" [list [list name (n32)] \
586 [list as $abi_asflags(n32)] \
587 [list ld $abi_ldflags(n32)]]
588 run_dump_test "undefweak-overflow" [list [list name (n64)] \
589 [list as $abi_asflags(n64)] \
590 [list ld $abi_ldflags(n64)]]
594 run_dump_test "jalbal" [list [list ld $abi_ldflags(n32)]]
597 run_dump_test "mode-change-error-1"
599 run_dump_test "mips16-hilo"
601 run_dump_test "mips16-hilo-n32"
606 run_dump_test "textrel-1"
608 run_dump_test "got-page-1"
610 run_dump_test "got-page-2"
611 run_dump_test "dyn-sec64"
613 run_dump_test "got-page-3"
614 run_ld_link_tests [subst {
615 {"GOT page 4 (one file)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
616 "" "$abi_asflags(o32) -mips2" {got-page-4b.s}
617 {{objdump -dr got-page-4a.d}
618 {readelf -A got-page-4a.got}}
620 {"GOT page 4 (two files)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
621 "" "$abi_asflags(o32) -mips2" {got-page-4a.s got-page-4b.s}
622 {{objdump -dr got-page-4b.d}
623 {readelf -A got-page-4b.got}}
627 run_ld_link_tests [subst {
628 {"GOT page 5" "-shared $abi_ldflags(n32) -T got-page-1.ld"
629 "" "$abi_asflags(n32)" {got-page-5.s}
630 {{objdump -dr got-page-5.d}
631 {readelf -A got-page-5.got}}
633 {"GOT page 6" "-shared $abi_ldflags(n32) -T got-page-1.ld"
634 "" "$abi_asflags(n32)" {got-page-6.s}
635 {{objdump -dr got-page-6.d}
636 {readelf -A got-page-6.got}}
638 {"GOT page 7 (order 1)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
639 "" "$abi_asflags(n32)"
640 {got-page-7a.s got-page-7b.s got-page-7c.s got-page-7d.s
642 {{objdump -dr got-page-7.d}
643 {readelf -A got-page-7.got}}
645 {"GOT page 7 (order 2)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
646 "" "$abi_asflags(n32)"
647 {got-page-7e.s got-page-7a.s got-page-7b.s got-page-7c.s
649 {{objdump -dr got-page-7.d}
650 {readelf -A got-page-7.got}}
654 run_dump_test "got-dump-1"
656 run_dump_test "got-dump-2"
658 run_dump_test "reloc-estimate-1"
662 run_dump_test "emit-relocs-1"
665 run_dump_test "hash1a"
666 run_dump_test "hash1b"
667 run_dump_test "hash1c"
669 if {[istarget mips*-*-linux*]} {
670 # The number of symbols that are always included in the symbol table
671 # for these tests. The 4 are:
673 # the null symbol entry
674 # the .MIPS.stubs section symbol
676 foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
679 "Stub for dynsym 0x$dynsym" \
680 "-shared -melf32btsmip -T stub-dynsym-1.ld" "" \
682 "-EB -march=mips1 -32 -KPIC" \
683 "--defsym base_syms=$base_syms" \
684 "--defsym dynsym=0x$dynsym"] \
685 [list "stub-dynsym-1.s"] \
688 "stub-dynsym-1-$dynsym.d"]] \
689 "stub-dynsym-1-$dynsym"]]
693 # For tests which may involve multiple files, use run_ld_link_tests.
695 # List contains test-items with 3 items followed by 2 lists:
696 # 0:name 1:ld early options 2:ld late options 3:assembler options
697 # 4:filenames of assembler files 5: action and options. 6: name of output file
700 # objdump: Apply objdump options on result. Compare with regex (last arg).
701 # nm: Apply nm options on result. Compare with regex (last arg).
702 # readelf: Apply readelf options on result. Compare with regex (last arg).
705 {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld" ""
706 "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
707 {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
709 {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld" ""
710 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
711 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
713 {"Dynamic executable with TLS"
714 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so" ""
715 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
716 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
718 {"Shared library with multiple GOTs and TLS"
719 "-shared -melf32btsmip -T mips-lib.ld" ""
720 "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
721 {{readelf {-d -r} tls-multi-got-1.r}
722 {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
723 {objdump -Rsj.got tls-multi-got-1.got}}
725 {"Shared library with TLS and versioning"
726 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver" ""
727 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
728 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
730 {"Dynamic executable with TLS and versioning"
731 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so" ""
732 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
733 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
734 "tls-dynamic-o32-ver"}
735 {"Dynamic executable with TLS and versioning (order 2)"
736 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o" ""
737 "-EB -march=mips1 -32 -KPIC" {}
738 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
739 "tls-dynamic-o32-ver-2"}
740 {"Dynamic executable with TLS and versioning (order 3)"
741 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o" ""
742 "-EB -march=mips1 -32 -KPIC" {}
743 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
744 "tls-dynamic-o32-ver-3"}
745 {"Shared library with TLS and hidden symbols"
746 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver" ""
747 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
748 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
749 "tlslib-o32-hidden.so"}
750 {"Shared library with TLS and hidden symbols (2)"
751 "-shared -melf32btsmip -T mips-lib.ld" ""
752 "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
753 {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
755 {"Shared library with TLS and hidden symbols (3)"
756 "-shared -melf32btsmip -T tls-hidden3.ld" ""
757 "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
758 {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
759 {readelf --relocs tls-hidden3.r}}
761 {"Shared library with TLS and hidden symbols (4)"
762 "-shared -melf32btsmip -T tls-hidden3.ld" ""
763 "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
764 {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
768 if {[istarget mips*-*-linux*]} {
769 run_ld_link_tests $mips_tls_tests
772 set mips16_call_global_test [list \
773 [list "Global calls from mips16" \
774 "$abi_ldflags(o32) -T no-shared-1.ld" "" \
775 "$abi_asflags(o32) -mips32r2" \
776 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
777 {{objdump -dr mips16-call-global.d}} \
778 "mips16-call-global"]]
780 run_ld_link_tests $mips16_call_global_test
782 set mips16_intermix_test [list \
783 [list "Intermixing mips32 and mips16 functions" \
784 "$abi_ldflags(o32)" "" \
785 "$abi_asflags(o32) -mips32r2" \
786 {mips16-intermix-1.s mips16-intermix-2.s} \
787 {{objdump -t mips16-intermix.d}} \
790 run_ld_link_tests $mips16_intermix_test
792 run_dump_test "mips16-local-stubs-1"
794 set mips16_fp_stub_test [list \
795 [list "Floating-point stub for mips16 functions" \
796 "$abi_ldflags(o32)" "" \
797 "$abi_asflags(o32) -mips32r2" \
798 {mips16-fp-stub-1.s mips16-fp-stub-2.s} \
799 {{readelf --debug-dump=frames mips16-fp-stub.d}} \
802 run_ld_link_tests $mips16_fp_stub_test
804 set o32flagslist [list [list as $abi_asflags(o32)] [list ld $abi_ldflags(o32)]]
806 foreach firstfpabi [list 0 1 2 3 4 5 6 7 ] {
807 foreach secondfpabi [list 4 5 6 7 ] {
808 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
811 foreach firstfpabi [list 4 5 6 7 ] {
812 foreach secondfpabi [list 0 1 2 3 8 9] {
813 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
816 foreach firstfpabi [list 0 1 2 3 ] {
817 foreach secondfpabi [list 0 1 2 3 8 9] {
818 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}"
822 run_dump_test "attr-gnu-4-81"
824 run_dump_test "attr-gnu-8-00"
825 run_dump_test "attr-gnu-8-01"
826 run_dump_test "attr-gnu-8-02"
827 run_dump_test "attr-gnu-8-10"
828 run_dump_test "attr-gnu-8-11"
829 run_dump_test "attr-gnu-8-12"
830 run_dump_test "attr-gnu-8-20"
831 run_dump_test "attr-gnu-8-21"
832 run_dump_test "attr-gnu-8-22"
834 run_dump_test "attr-gnu-4-0-ph" $o32flagslist
835 run_dump_test "attr-gnu-4-1-ph" $o32flagslist
836 run_dump_test "attr-gnu-4-2-ph" $o32flagslist
837 run_dump_test "attr-gnu-4-3-ph" $o32flagslist
838 run_dump_test "attr-gnu-4-4-ph" $o32flagslist
839 run_dump_test "attr-gnu-4-5-ph" $o32flagslist
840 run_dump_test "attr-gnu-4-6-ph" $o32flagslist
841 run_dump_test "attr-gnu-4-7-ph" $o32flagslist
844 run_dump_test "attr-gnu-4-0-n32-ph"
845 run_dump_test "attr-gnu-4-1-n32-ph"
846 run_dump_test "attr-gnu-4-2-n32-ph"
847 run_dump_test "attr-gnu-4-3-n32-ph"
848 run_dump_test "attr-gnu-4-0-n64-ph"
849 run_dump_test "attr-gnu-4-1-n64-ph"
850 run_dump_test "attr-gnu-4-2-n64-ph"
851 run_dump_test "attr-gnu-4-3-n64-ph"
854 run_dump_test "abiflags-strip1-ph" $o32flagslist
855 run_dump_test "abiflags-strip2-ph" $o32flagslist
856 run_dump_test "abiflags-strip3-ph" $o32flagslist
857 run_dump_test "abiflags-strip4-ph" $o32flagslist
858 run_dump_test "abiflags-strip5-ph" $o32flagslist
859 run_dump_test "abiflags-strip6-ph" $o32flagslist
860 run_dump_test "abiflags-strip7-ph" $o32flagslist
861 run_dump_test "abiflags-strip8-ph" $o32flagslist
862 run_dump_test "abiflags-strip9-ph" $o32flagslist
863 run_dump_test "abiflags-strip10-ph" $o32flagslist
865 run_dump_test "nan-legacy"
866 run_dump_test "nan-2008"
867 run_dump_test "nan-mixed-1"
868 run_dump_test "nan-mixed-2"
872 {"GOT and versioning 1"
873 "-shared -melf32btsmip --version-script got-vers-1.ver" ""
874 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
875 {{readelf -d got-vers-1.dd}
876 {readelf --symbols got-vers-1.sd}
877 {readelf --relocs got-vers-1.rd}}
882 run_dump_test "undefined"
884 # Test the conversion from jr to b
886 run_dump_test "jr-to-b-1"
887 run_dump_test "jr-to-b-2"
890 # MIPS16 and microMIPS interlinking test.
891 run_dump_test "mips16-and-micromips"
893 # Export class call relocation tests.
894 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
895 foreach { abi } $abis {
896 set loadaddr [string map \
897 {o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
899 [expr { [istarget *-*-irix*] \
900 ? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
902 run_ld_link_tests [list \
904 "MIPS export class call relocation test ($abi)" \
905 "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
906 "$abi_asflags($abi) -mips3 -KPIC" \
907 [list export-class-call16-${abi}.s export-class-call16-def.s] \
909 "objdump -d export-class-call16-${suff}.dd" \
910 "readelf -A export-class-call16-${abi}.gd"] \
911 "export-class-call16-${abi}.so"]]
914 # Magic __ehdr_start symbol tests.
915 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
916 foreach { abi } $abis {
917 set suff [string map {o32 o32 n32 new n64 new} $abi]
918 run_ld_link_tests [list \
920 "MIPS magic __ehdr_start symbol test 1 ($abi)" \
921 "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
922 "$abi_asflags($abi)" \
923 [list ehdr_start-${suff}.s] \
924 [list "readelf -s ehdr_start-1.nd"] \
925 "ehdr_start-1-${abi}"]]
926 if [regexp "(?:n32|n64)" "$abi"] {
927 setup_kfail "mips*-*-*" "ld/15428"
929 run_ld_link_tests [list \
931 "MIPS magic __ehdr_start symbol test 2 ($abi)" \
932 "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
933 "$abi_asflags($abi)" \
934 [list ehdr_start-${suff}.s] \
935 [list "readelf -s ehdr_start-2.nd"] \
936 "ehdr_start-2-${abi}"]]
939 # R_MIPS_JALR reloc tests.
940 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
941 foreach { abi } $abis {
942 run_ld_link_tests [list \
944 "MIPS JALR reloc test ($abi)" \
945 "$abi_ldflags($abi) -T jalr3.ld" "" \
946 "$abi_asflags($abi)" \
947 [list ../../../gas/testsuite/gas/mips/jalr3.s] \
948 [list "objdump -d jalr3.dd"] \
952 proc build_mips_plt_lib { abi } {
956 run_ld_link_tests [list \
957 [list "Shared $abi library for compressed PLT tests" \
958 "-shared $abi_ldflags($abi)" "" \
959 "$abi_asflags($abi)" \
960 { compressed-plt-1-dyn.s } \
962 "compressed-plt-1-${abi}-dyn.so"]]
965 proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
969 set as_flags "$abi_asflags($abi) --defsym filter=$filter"
970 append as_flags " --defsym micromips=$micromips --defsym $abi=1"
971 if {[string equal $abi o32]} {
972 append as_flags " -march=mips2"
974 set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
975 set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
978 lappend files compressed-plt-1a.s
980 if { $filter & 56 } {
981 lappend files compressed-plt-1b.s
983 if { $filter & 64 } {
984 lappend files compressed-plt-1c.s
986 eval [list lappend files] $extra
987 set readelf_flags "-A --syms --relocs -d"
988 if { [string match "*word*" $suffix] } {
989 append readelf_flags " -x.data"
991 set objdump_flags "-d -Mgpr-names=numeric"
992 set basename "compressed-plt-1-${abi}-${suffix}"
993 run_ld_link_tests [list \
994 [list "$name" $ld_flags $dynobj \
996 [list [list readelf $readelf_flags ${basename}.rd] \
997 [list objdump $objdump_flags ${basename}.od]] \
1002 build_mips_plt_lib o32
1003 run_mips_plt_test "o32 PLTs for standard encoding" o32 104 0 se
1004 run_mips_plt_test "o32 PLTs for standard branches" o32 16 0 branch
1005 run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 69 0 mips16-only
1006 run_mips_plt_test "o32 PLTs for MIPS16 branches" o32 2 0 mips16-bronly
1007 run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 69 1 umips-only
1008 run_mips_plt_test "o32 PLTs for microMIPS branches" o32 2 1 umips-bronly
1009 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
1011 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 branches" \
1012 o32 18 0 mips16-branch
1013 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
1014 o32 109 0 mips16-got compressed-plt-1d.s
1015 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
1016 o32 109 0 mips16-word compressed-plt-1e.s
1017 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
1019 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS branches" \
1020 o32 18 1 umips-branch
1021 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
1022 o32 109 1 umips-got compressed-plt-1d.s
1023 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
1024 o32 109 1 umips-word compressed-plt-1e.s
1027 build_mips_plt_lib n32
1028 run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
1030 run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
1035 # PR ld/19908 export class tests.
1037 run_ld_link_tests [list \
1038 [list "Shared library for MIPS export class symbol reference tests" \
1039 "$abi_ldflags(o32) -shared" "" \
1040 "$abi_asflags(o32)" \
1041 { export-class-ref-f2.s } \
1042 { { readelf --dyn-syms export-class-ref-lib.sd } } \
1043 "export-class-ref-lib.so"]]
1044 foreach { class flag } { internal 1 hidden 2 protected 3 } {
1045 run_ld_link_tests [list \
1046 [list "MIPS $class symbol reference test 1" \
1047 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
1048 "$abi_asflags(o32) --defsym defv=$flag" \
1049 { export-class-ref-f0.s export-class-ref-f1.s } \
1050 [list [list readelf --dyn-syms export-$class-ref.sd] \
1051 [list readelf --dyn-syms export-local-ref.sd]] \
1052 "export-$class-ref"] \
1053 [list "MIPS $class symbol reference test 2" \
1054 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
1055 "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
1056 { export-class-ref-f0.s export-class-ref-f1.s } \
1057 [list [list readelf --dyn-syms export-$class-ref.sd] \
1058 [list readelf --dyn-syms export-local-ref.sd]] \
1059 "export-$class-ref"]]