1 # Expect script for MIPS ELF linker tests
2 # Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 # Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 if {[istarget "mips*-*-vxworks"]} {
25 {"VxWorks shared library test 1" "-shared -Tvxworks1.ld"
26 "-mips2" {vxworks1-lib.s}
27 {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
28 {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
30 {"VxWorks executable test 1 (dynamic)" \
31 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic"
33 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
35 {"VxWorks executable test 2 (dynamic)" \
36 "-Tvxworks1.ld -q --force-dynamic"
38 {{readelf --segments vxworks2.sd}}
40 {"VxWorks executable test 2 (static)"
43 {{readelf --segments vxworks2-static.sd}}
46 run_ld_link_tests $mipsvxtests
47 run_dump_test "vxworks1-static"
48 run_dump_test "vxworks-forced-local-1"
52 if {![istarget mips*-*-*] || ![is_elf_format]} {
56 set has_newabi [expr [istarget *-*-irix6*] || [istarget mips64*-*-linux*]]
57 set linux_gnu [expr [istarget mips*-*-linux*]]
58 set embedded_elf [expr [istarget mips*-*-elf]]
61 run_ld_link_tests [list \
62 [list "Dummy shared library for MIPS16 PIC test 1" \
63 "-shared -melf32btsmip" \
65 { mips16-pic-1-dummy.s } \
67 "mips16-pic-1-dummy.so"] \
68 [list "MIPS16 PIC test 1" \
69 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" \
70 "-EB -32 -mips1 -I $srcdir/$subdir" \
71 { mips16-pic-1a.s mips16-pic-1b.s } \
72 { { objdump { -dr -j.text } mips16-pic-1.dd }
73 { readelf -A mips16-pic-1.gd } } \
75 [list "MIPS16 PIC test 2" \
76 "-melf32btsmip -T mips16-pic-1.ld -shared" \
77 "-EB -32 -mips1 -I $srcdir/$subdir" \
78 { mips16-pic-2a.s mips16-pic-2b.s } \
79 { { objdump { -dr -j.text } mips16-pic-2.dd } \
80 { readelf -A mips16-pic-2.gd } \
81 { readelf --symbols mips16-pic-2.nd } \
82 { readelf --relocs mips16-pic-2.rd } \
83 { readelf -d mips16-pic-2.ad } } \
85 [list "MIPS16 PIC test 3" \
86 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" \
87 "-EB -32 -mips1 -I $srcdir/$subdir" \
88 { mips16-pic-3a.s mips16-pic-3b.s } \
89 { { objdump -dr mips16-pic-3.dd } \
90 { readelf --relocs mips16-pic-3.rd } \
91 { readelf -A mips16-pic-3.gd } } \
93 [list "MIPS16 PIC test 4 (shared library)" \
94 "-shared -melf32btsmip -T mips16-pic-1.ld --version-script mips16-pic-4.ver" \
96 { mips16-pic-4a.s mips16-pic-4b.s } \
97 { { objdump -dr mips16-pic-4a.dd } \
98 { readelf --symbols mips16-pic-4a.nd } \
99 { readelf -A mips16-pic-4a.gd } } \
101 [list "MIPS16 PIC test 4 (executable)" \
102 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-4.so" \
104 { mips16-pic-4c.s } \
105 { { objdump -dr mips16-pic-4b.dd } } \
109 if { [istarget mips64*-linux-gnu] } {
110 set o32_as_flags "-32 -EB"
111 set o32_ld_flags "-melf32btsmip"
112 } elseif { [istarget mips64*-*freebsd*] } {
113 set o32_as_flags "-32 -EB"
114 set o32_ld_flags "-melf32btsmip_fbsd"
120 # Check MIPS16 markings being passed through link.
121 run_dump_test "mips16-1"
123 # MIPS branch offset final link checking.
124 run_dump_test "branch-misc-1"
126 # Test multi-got link. We only do this on GNU/Linux because it requires
127 # the "traditional" emulations.
129 run_dump_test "multi-got-1"
130 run_dump_test "multi-got-no-shared"
131 run_dump_test "multi-got-hidden-1"
132 run_dump_test "multi-got-hidden-2"
135 # Test __gnu_local_gp accesses
137 run_dump_test "no-shared-1-o32"
139 run_dump_test "no-shared-1-n32"
140 run_dump_test "no-shared-1-n64"
145 run_dump_test "elf-rel-got-n32"
146 run_dump_test "elf-rel-xgot-n32"
148 run_dump_test "elf-rel-got-n64-linux"
149 run_dump_test "elf-rel-xgot-n64-linux"
151 run_dump_test "elf-rel-got-n64"
152 run_dump_test "elf-rel-xgot-n64"
155 run_dump_test "relax-jalr-n32"
156 run_dump_test "relax-jalr-n32-shared"
157 run_dump_test "relax-jalr-n64"
158 run_dump_test "relax-jalr-n64-shared"
162 run_dump_test "rel32-o32"
163 run_dump_test "rel32-n32"
164 run_dump_test "rel64"
165 # The first test checks that a mixed PIC/non-PIC relocatable link
166 # will not introduce any stubs itself, but will flag PIC functions
167 # for the final link.
169 # The second test checks that we insert stubs for calls from
170 # non-PIC functions to PIC functions when linking the original
171 # two objects together.
173 # The third test checks that we do the same when linking the
174 # result of the first link (with no other source files).
176 {"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip"
177 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
178 {{objdump -dr pic-and-nonpic-1-rel.dd}
179 {readelf --symbols pic-and-nonpic-1-rel.nd}}
180 "pic-and-nonpic-1-rel.o"}
181 {"PIC and non-PIC test 1 (static 1)"
182 "-melf32btsmip -Tpic-and-nonpic-1.ld"
183 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
184 {{objdump -dr pic-and-nonpic-1.dd}
185 {readelf --symbols pic-and-nonpic-1.nd}}
186 "pic-and-nonpic-1-static1.o"}
187 {"PIC and non-PIC test 1 (static 2)"
188 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o"
190 {{objdump -dr pic-and-nonpic-1.dd}
191 {readelf --symbols pic-and-nonpic-1.nd}}
192 "pic-and-nonpic-1-static2.o"}
194 run_dump_test "pic-and-nonpic-2"
196 {"PIC and non-PIC test 3 (shared library)"
197 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld"
198 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
199 {{readelf --segments pic-and-nonpic-3a.sd}
200 {readelf -A pic-and-nonpic-3a.gd}
201 {objdump -dr pic-and-nonpic-3a.dd}}
202 "pic-and-nonpic-3a.so"}
203 {"PIC and non-PIC test 3 (executable)"
204 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so"
205 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
206 {{readelf --segments pic-and-nonpic-3b.sd}
207 {objdump -dr pic-and-nonpic-3b.dd}
208 {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
209 {readelf -A pic-and-nonpic-3b.gd}
210 {readelf --relocs pic-and-nonpic-3b.rd}
211 {readelf --symbols pic-and-nonpic-3b.nd}
212 {readelf -d pic-and-nonpic-3b.ad}}
215 run_dump_test "pic-and-nonpic-3-error"
217 {"PIC and non-PIC test 4 (shared library)"
218 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld"
219 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
221 "pic-and-nonpic-4a.so"}
222 {"PIC and non-PIC test 4 (executable)"
223 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so"
224 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
225 {{readelf --segments pic-and-nonpic-4b.sd}
226 {objdump -dr pic-and-nonpic-4b.dd}
227 {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
228 {readelf --relocs pic-and-nonpic-4b.rd}
229 {readelf --symbols pic-and-nonpic-4b.nd}
230 {readelf -d pic-and-nonpic-4b.ad}}
233 run_dump_test "pic-and-nonpic-4-error"
235 {"PIC and non-PIC test 5 (executable)"
236 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so"
237 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
238 {{readelf --segments pic-and-nonpic-5b.sd}
239 {objdump -dr pic-and-nonpic-5b.dd}
240 {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
241 {readelf -A pic-and-nonpic-5b.gd}
242 {readelf --relocs pic-and-nonpic-5b.rd}
243 {readelf --symbols pic-and-nonpic-5b.nd}
244 {readelf -d pic-and-nonpic-5b.ad}}
247 set abis { o32 -32 elf32btsmip }
249 lappend abis n32 -n32 elf32btsmipn32
250 lappend abis n64 -64 elf64btsmip
252 foreach { abi flag emul } $abis {
253 run_ld_link_tests [list \
254 [list "PIC and non-PIC test 6 ($abi shared library)" \
255 "-m$emul -shared -Tpic-and-nonpic-3a.ld" \
257 [list "pic-and-nonpic-6-${abi}a.s"] {} \
258 "pic-and-nonpic-6-${abi}.so"] \
259 [list "PIC and non-PIC test 6 ($abi executable)" \
260 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" \
262 [list "pic-and-nonpic-6-${abi}b.s" \
263 "pic-and-nonpic-6-${abi}c.s"] \
264 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
265 "objdump -dr pic-and-nonpic-6-${abi}.dd" \
266 "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
267 "readelf -A pic-and-nonpic-6-${abi}.gd" \
268 "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
269 "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
270 "readelf -d pic-and-nonpic-6-${abi}.ad"] \
271 "pic-and-nonpic-6-${abi}"]]
275 if { $embedded_elf } {
276 run_dump_test "region1"
280 # This could work on other targets too, but would need the appropriate
282 run_dump_test "reloc-1-rel"
285 run_dump_test "reloc-1-n32"
287 # Uses a linux-specific ld -m switch
288 run_dump_test "reloc-1-n64"
291 run_dump_test "reloc-2"
292 run_dump_test "reloc-merge-lo16"
293 run_dump_test "reloc-3"
295 run_dump_test "reloc-3-n32"
297 run_dump_test "reloc-4"
298 run_dump_test "reloc-5"
300 if {$has_newabi && $linux_gnu} {
301 run_dump_test "eh-frame1-n32"
302 run_dump_test "eh-frame1-n64"
303 run_dump_test "eh-frame2-n32"
304 run_dump_test "eh-frame2-n64"
307 run_dump_test "eh-frame3"
308 run_dump_test "eh-frame4"
313 "-melf32btsmip -shared -Teh-frame5.ld"
316 {{readelf {--relocs -wf} eh-frame5.d}}
319 run_ld_link_tests $eh_frame5_test
322 run_dump_test "jaloverflow"
323 run_dump_test "jaloverflow-2"
325 run_dump_test "jalbal"
328 run_dump_test "mode-change-error-1"
330 run_dump_test "mips16-hilo"
332 run_dump_test "mips16-hilo-n32"
336 run_dump_test "textrel-1"
337 run_dump_test "got-page-1"
339 run_dump_test "got-page-2"
340 run_dump_test "dyn-sec64"
342 run_dump_test "got-page-3"
343 run_dump_test "got-dump-1"
345 run_dump_test "got-dump-2"
347 run_dump_test "reloc-estimate-1"
351 run_dump_test "emit-relocs-1"
354 run_dump_test "hash1a"
355 run_dump_test "hash1b"
356 run_dump_test "hash1c"
358 if {[istarget mips*-*-linux*]} {
359 # The number of symbols that are always included in the symbol table
360 # for these tests. The 4 are:
362 # the null symbol entry
363 # the .MIPS.stubs section symbol
365 # _GLOBAL_OFFSET_TABLE_
367 foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
370 "Stub for dynsym 0x$dynsym" \
371 "-shared -melf32btsmip -T stub-dynsym-1.ld" \
373 "-EB -march=mips1 -32 -KPIC" \
374 "--defsym base_syms=$base_syms" \
375 "--defsym dynsym=0x$dynsym"] \
376 [list "stub-dynsym-1.s"] \
379 "stub-dynsym-1-$dynsym.d"]] \
380 "stub-dynsym-1-$dynsym"]]
384 # For tests which may involve multiple files, use run_ld_link_tests.
386 # List contains test-items with 3 items followed by 2 lists:
387 # 0:name 1:ld options 2:assembler options
388 # 3:filenames of assembler files 4: action and options. 5: name of output file
391 # objdump: Apply objdump options on result. Compare with regex (last arg).
392 # nm: Apply nm options on result. Compare with regex (last arg).
393 # readelf: Apply readelf options on result. Compare with regex (last arg).
396 {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld"
397 "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
398 {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
400 {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld"
401 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
402 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
404 {"Dynamic executable with TLS"
405 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so"
406 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
407 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
409 {"Shared library with multiple GOTs and TLS"
410 "-shared -melf32btsmip -T mips-lib.ld"
411 "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
412 {{readelf {-d -r} tls-multi-got-1.r}
413 {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
414 {objdump -Rsj.got tls-multi-got-1.got}}
416 {"Shared library with TLS and versioning"
417 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver"
418 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
419 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
421 {"Dynamic executable with TLS and versioning"
422 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so"
423 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
424 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
425 "tls-dynamic-o32-ver"}
426 {"Dynamic executable with TLS and versioning (order 2)"
427 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o"
428 "-EB -march=mips1 -32 -KPIC" {}
429 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
430 "tls-dynamic-o32-ver-2"}
431 {"Dynamic executable with TLS and versioning (order 3)"
432 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o"
433 "-EB -march=mips1 -32 -KPIC" {}
434 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
435 "tls-dynamic-o32-ver-3"}
436 {"Shared library with TLS and hidden symbols"
437 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver"
438 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
439 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
440 "tlslib-o32-hidden.so"}
441 {"Shared library with TLS and hidden symbols (2)"
442 "-shared -melf32btsmip -T mips-lib.ld"
443 "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
444 {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
446 {"Shared library with TLS and hidden symbols (3)"
447 "-shared -melf32btsmip -T tls-hidden3.ld"
448 "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
449 {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
450 {readelf --relocs tls-hidden3.r}}
452 {"Shared library with TLS and hidden symbols (4)"
453 "-shared -melf32btsmip -T tls-hidden3.ld"
454 "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
455 {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
459 if {[istarget mips*-*-linux*]} {
460 run_ld_link_tests $mips_tls_tests
463 set mips16_call_global_test [list \
464 [list "Global calls from mips16" \
466 "$o32_as_flags -mips32r2" \
467 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
468 {{objdump -dr mips16-call-global.d}} \
469 "mips16-call-global"]]
471 run_ld_link_tests $mips16_call_global_test
473 set mips16_intermix_test [list \
474 [list "Intermixing mips32 and mips16 functions" \
476 "$o32_as_flags -mips32r2" \
477 {mips16-intermix-1.s mips16-intermix-2.s} \
478 {{objdump -t mips16-intermix.d}} \
481 run_ld_link_tests $mips16_intermix_test
483 run_dump_test "mips16-local-stubs-1"
485 run_dump_test "attr-gnu-4-00"
486 run_dump_test "attr-gnu-4-01"
487 run_dump_test "attr-gnu-4-02"
488 run_dump_test "attr-gnu-4-03"
489 run_dump_test "attr-gnu-4-04"
490 run_dump_test "attr-gnu-4-05"
491 run_dump_test "attr-gnu-4-10"
492 run_dump_test "attr-gnu-4-11"
493 run_dump_test "attr-gnu-4-12"
494 run_dump_test "attr-gnu-4-13"
495 run_dump_test "attr-gnu-4-14"
496 run_dump_test "attr-gnu-4-15"
497 run_dump_test "attr-gnu-4-20"
498 run_dump_test "attr-gnu-4-21"
499 run_dump_test "attr-gnu-4-22"
500 run_dump_test "attr-gnu-4-23"
501 run_dump_test "attr-gnu-4-24"
502 run_dump_test "attr-gnu-4-25"
503 run_dump_test "attr-gnu-4-30"
504 run_dump_test "attr-gnu-4-31"
505 run_dump_test "attr-gnu-4-32"
506 run_dump_test "attr-gnu-4-33"
507 run_dump_test "attr-gnu-4-34"
508 run_dump_test "attr-gnu-4-35"
509 run_dump_test "attr-gnu-4-40"
510 run_dump_test "attr-gnu-4-41"
511 run_dump_test "attr-gnu-4-42"
512 run_dump_test "attr-gnu-4-43"
513 run_dump_test "attr-gnu-4-44"
514 run_dump_test "attr-gnu-4-45"
515 run_dump_test "attr-gnu-4-51"
519 {"GOT and versioning 1"
520 "-shared -melf32btsmip --version-script got-vers-1.ver"
521 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
522 {{readelf -d got-vers-1.dd}
523 {readelf --symbols got-vers-1.sd}
524 {readelf --relocs got-vers-1.rd}}
529 run_dump_test "undefined"
531 # Test the conversion from jr to b
533 run_dump_test "jr-to-b-1"
534 run_dump_test "jr-to-b-2"