Home | History | Annotate | Download | only in ld-mips-elf
      1 # Expect script for MIPS ELF linker tests
      2 #   Copyright (C) 2002-2014 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 # Test multi-got link.  We only do this on GNU/Linux because it requires
    172 # the "traditional" emulations.
    173 if { $linux_gnu } {
    174     run_dump_test "multi-got-1"
    175     run_dump_test "multi-got-no-shared"
    176     run_dump_test "multi-got-hidden-1"
    177     run_dump_test "multi-got-hidden-2"
    178 }
    179 
    180 # Test __gnu_local_gp accesses
    181 if { $linux_gnu } {
    182     run_dump_test "no-shared-1-o32"
    183     if { $has_newabi } {
    184 	run_dump_test "no-shared-1-n32"
    185 	run_dump_test "no-shared-1-n64"
    186     }
    187 }
    188 
    189 # Test PIE debug dynamic tags
    190 if { $linux_gnu } {
    191     run_dump_test "pie-o32"
    192     if { $has_newabi } {
    193 	run_dump_test "pie-n32"
    194 	run_dump_test "pie-n64"
    195     }
    196 }
    197 
    198 if $has_newabi {
    199     if { $embedded_elf } {
    200 	run_dump_test "elf-rel-got-n32-embed" \
    201 					[list [list ld $abi_ldflags(n32)]]
    202 	run_dump_test "elf-rel-xgot-n32-embed" \
    203 					[list [list ld $abi_ldflags(n32)]]
    204     } else {
    205 	run_dump_test "elf-rel-got-n32" [list [list ld $abi_ldflags(n32)]]
    206 	run_dump_test "elf-rel-xgot-n32" [list [list ld $abi_ldflags(n32)]]
    207     }
    208     if { $linux_gnu } {
    209 	run_dump_test "elf-rel-got-n64-linux" \
    210 					[list [list ld $abi_ldflags(n64)]]
    211 	run_dump_test "elf-rel-xgot-n64-linux" \
    212 					[list [list ld $abi_ldflags(n64)]]
    213     } elseif { $embedded_elf } {
    214 	run_dump_test "elf-rel-got-n64-embed" \
    215 					[list [list ld $abi_ldflags(n64)]]
    216 	run_dump_test "elf-rel-xgot-n64-embed" \
    217 					[list [list ld $abi_ldflags(n64)]]
    218     } else {
    219 	run_dump_test "elf-rel-got-n64" [list [list ld $abi_ldflags(n64)]]
    220 	run_dump_test "elf-rel-xgot-n64" [list [list ld $abi_ldflags(n64)]]
    221     }
    222 
    223     run_dump_test "relax-jalr-n32"
    224     run_dump_test "relax-jalr-n32-shared"
    225     run_dump_test "relax-jalr-n64"
    226     run_dump_test "relax-jalr-n64-shared"
    227 }
    228 
    229 if { $linux_gnu } {
    230     run_dump_test "rel32-o32"
    231     if { $has_newabi } {
    232 	run_dump_test "rel32-n32"
    233 	run_dump_test "rel64"
    234     }
    235     # The first test checks that a mixed PIC/non-PIC relocatable link
    236     # will not introduce any stubs itself, but will flag PIC functions
    237     # for the final link.
    238     #
    239     # The second test checks that we insert stubs for calls from
    240     # non-PIC functions to PIC functions when linking the original
    241     # two objects together.
    242     #
    243     # The third test checks that we do the same when linking the
    244     # result of the first link (with no other source files).
    245     run_ld_link_tests {
    246 	{"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip" ""
    247 	 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
    248 	 {{objdump -dr pic-and-nonpic-1-rel.dd}
    249 	  {readelf --symbols pic-and-nonpic-1-rel.nd}}
    250 	 "pic-and-nonpic-1-rel.o"}
    251 	{"PIC and non-PIC test 1 (static 1)"
    252 	 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
    253 	 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
    254 	 {{objdump -dr pic-and-nonpic-1.dd}
    255 	  {readelf --symbols pic-and-nonpic-1.nd}}
    256 	 "pic-and-nonpic-1-static1.o"}
    257 	{"PIC and non-PIC test 1 (static 2)"
    258 	 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o" ""
    259 	 "" {}
    260 	 {{objdump -dr pic-and-nonpic-1.dd}
    261 	  {readelf --symbols pic-and-nonpic-1.nd}}
    262 	 "pic-and-nonpic-1-static2.o"}
    263     }
    264     run_dump_test "pic-and-nonpic-2"
    265     run_ld_link_tests {
    266 	{"PIC and non-PIC test 3 (shared library)"
    267 	 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
    268 	 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
    269 	 {{readelf --segments pic-and-nonpic-3a.sd}
    270 	  {readelf -A pic-and-nonpic-3a.gd}
    271 	  {objdump -dr pic-and-nonpic-3a.dd}}
    272 	 "pic-and-nonpic-3a.so"}
    273 	{"PIC and non-PIC test 3 (executable)"
    274 	 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so" ""
    275 	 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
    276 	 {{readelf --segments pic-and-nonpic-3b.sd}
    277 	  {objdump -dr pic-and-nonpic-3b.dd}
    278 	  {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
    279 	  {readelf -A pic-and-nonpic-3b.gd}
    280 	  {readelf --relocs pic-and-nonpic-3b.rd}
    281 	  {readelf --symbols pic-and-nonpic-3b.nd}
    282 	  {readelf -d pic-and-nonpic-3b.ad}}
    283 	 "pic-and-nonpic-3b"}
    284     }
    285     run_dump_test "pic-and-nonpic-3-error"
    286     run_ld_link_tests {
    287 	{"PIC and non-PIC test 4 (shared library)"
    288 	 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
    289 	 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
    290 	 {}
    291 	 "pic-and-nonpic-4a.so"}
    292 	{"PIC and non-PIC test 4 (executable)"
    293 	 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so" ""
    294 	 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
    295 	 {{readelf --segments pic-and-nonpic-4b.sd}
    296 	  {objdump -dr pic-and-nonpic-4b.dd}
    297 	  {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
    298 	  {readelf --relocs pic-and-nonpic-4b.rd}
    299 	  {readelf --symbols pic-and-nonpic-4b.nd}
    300 	  {readelf -d pic-and-nonpic-4b.ad}}
    301 	 "pic-and-nonpic-4b"}
    302     }
    303     run_dump_test "pic-and-nonpic-4-error"
    304     run_ld_link_tests {
    305 	{"PIC and non-PIC test 5 (executable)"
    306 	 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so" ""
    307 	 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
    308 	 {{readelf --segments pic-and-nonpic-5b.sd}
    309 	  {objdump -dr pic-and-nonpic-5b.dd}
    310 	  {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
    311 	  {readelf -A pic-and-nonpic-5b.gd}
    312 	  {readelf --relocs pic-and-nonpic-5b.rd}
    313 	  {readelf --symbols pic-and-nonpic-5b.nd}
    314 	  {readelf -d pic-and-nonpic-5b.ad}}
    315 	 "pic-and-nonpic-5b"}
    316     }
    317     set abis { o32 -32 elf32btsmip }
    318     if $has_newabi {
    319 	lappend abis n32 -n32 elf32btsmipn32
    320 	lappend abis n64 -64 elf64btsmip
    321     }
    322     foreach { abi flag emul } $abis {
    323 	run_ld_link_tests [list \
    324 	    [list "PIC and non-PIC test 6 ($abi shared library)" \
    325 		 "-m$emul -shared -Tpic-and-nonpic-3a.ld" "" \
    326 		 "$flag -EB -mips3" \
    327 		 [list "pic-and-nonpic-6-${abi}a.s"] {} \
    328 		 "pic-and-nonpic-6-${abi}.so"] \
    329 	    [list "PIC and non-PIC test 6 ($abi executable)" \
    330 		 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" "" \
    331 		 "$flag -EB -mips3" \
    332 		 [list "pic-and-nonpic-6-${abi}b.s" \
    333 		      "pic-and-nonpic-6-${abi}c.s"] \
    334 		 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
    335 		      "objdump -dr pic-and-nonpic-6-${abi}.dd" \
    336 		      "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
    337 		      "readelf -A pic-and-nonpic-6-${abi}.gd" \
    338 		      "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
    339 		      "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
    340 		      "readelf -d pic-and-nonpic-6-${abi}.ad"] \
    341 		 "pic-and-nonpic-6-${abi}"]]
    342 
    343 	# This checks whether our linker scripts get the scope of _gp right,
    344 	# and must therefore use default scripts.  If they don't, then -- in
    345 	# addition to dumps failing to match -- the final link fails with:
    346 	#
    347 	#  ld: gp-hidden.o: undefined reference to symbol '_gp'
    348 	#  ld: note: '_gp' is defined in DSO ./tmpdir/gp-hidden-lib-${abi}.so
    349 	#  so try adding it to the linker command line
    350 	#
    351 	set suff64 [string map {o32 "" n32 "" n64 -64} $abi]
    352 	run_ld_link_tests [list \
    353 	    [list \
    354 		"_gp scope test ($abi shared library)" \
    355 		"$abi_ldflags($abi) -shared" "" \
    356 		"$abi_asflags($abi) -KPIC" \
    357 		{ gp-hidden-lib.s } \
    358 		[list \
    359 		    "readelf --relocs gp-hidden-lib${suff64}.rd" \
    360 		    "readelf --syms gp-hidden.sd"] \
    361 		"gp-hidden-lib-${abi}.so"] \
    362 	    [list \
    363 		"_gp scope test ($abi versioned library)" \
    364 		"$abi_ldflags($abi) -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \
    365 		"$abi_asflags($abi) -KPIC" \
    366 		{ gp-hidden-ver.s } \
    367 		[list \
    368 		    "readelf --relocs gp-hidden-ver${suff64}.rd" \
    369 		    "readelf --syms gp-hidden.sd"] \
    370 		"gp-hidden-ver-${abi}.so"] \
    371 	    [list \
    372 		"_gp scope test ($abi executable)" \
    373 		"$abi_ldflags($abi) -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \
    374 		"$abi_asflags($abi) -call_nonpic" \
    375 		{ gp-hidden.s } \
    376 		[list \
    377 		    "readelf --relocs gp-hidden${suff64}.rd" \
    378 		    "readelf --syms gp-hidden.sd"] \
    379 		"gp-hidden-${abi}"]]
    380     }
    381 }
    382 
    383 if { $embedded_elf } {
    384     run_dump_test "region1"
    385 }
    386 
    387 if $embedded_elf {
    388     # This could work on other targets too, but would need the appropriate
    389     # ld -m switch.
    390     run_dump_test "reloc-1-rel"
    391 }
    392 if $has_newabi {
    393     run_dump_test "reloc-1-n32" [list [list ld $abi_ldflags(n32)]]
    394     run_dump_test "reloc-1-n64" [list [list ld $abi_ldflags(n64)]]
    395 }
    396 run_dump_test "reloc-2"
    397 run_dump_test "reloc-merge-lo16"
    398 run_dump_test "reloc-3"
    399 if {$has_newabi} {
    400     run_dump_test "reloc-3-n32"
    401 }
    402 run_dump_test "reloc-4"
    403 run_dump_test "reloc-5"
    404 if { $has_newabi } {
    405     run_ld_link_tests [list \
    406 	[list \
    407 	    "reloc test 6a" \
    408 	    "-shared $abi_ldflags(n32)" "" \
    409 	    "$abi_asflags(n32)" \
    410 	    "reloc-6a.s" \
    411 	    {} \
    412 	    "reloc-6a.so"] \
    413 	[list \
    414 	    "reloc test 6b" \
    415 	    "$abi_ldflags(n32) tmpdir/reloc-6a.so" "" \
    416 	    "$abi_asflags(n32)" \
    417 	    "reloc-6b.s" \
    418 	    {} \
    419 	    "reloc-6b"]]
    420 }
    421 
    422 if {$has_newabi && $linux_gnu} {
    423     run_dump_test "eh-frame1-n32"
    424     run_dump_test "eh-frame1-n64"
    425     run_dump_test "eh-frame2-n32"
    426     run_dump_test "eh-frame2-n64"
    427 }
    428 if {$embedded_elf} {
    429     run_dump_test "eh-frame3"
    430     run_dump_test "eh-frame4"
    431 }
    432 if {$linux_gnu} {
    433     set eh_frame5_test {
    434 	{"MIPS eh-frame 5"
    435 	 "-melf32btsmip -shared -Teh-frame5.ld" ""
    436 	 "-32 -EB"
    437 	 {eh-frame5.s}
    438 	 {{readelf {--relocs -wf} eh-frame5.d}}
    439 	 "eh-frame5.so"}
    440     }
    441     run_ld_link_tests $eh_frame5_test
    442 }
    443 
    444 run_dump_test "jaloverflow"
    445 run_dump_test "jaloverflow-2"
    446 run_dump_test "undefweak-overflow"
    447 
    448 if {$has_newabi} {
    449     run_dump_test "undefweak-overflow-n32"
    450     run_dump_test "undefweak-overflow-n64"
    451 }
    452 
    453 if {$has_newabi} {
    454     run_dump_test "jalbal" [list [list ld $abi_ldflags(n32)]]
    455 }
    456 
    457 run_dump_test "mode-change-error-1"
    458 
    459 run_dump_test "mips16-hilo"
    460 if {$has_newabi} {
    461     run_dump_test "mips16-hilo-n32"
    462 }
    463 
    464 if { $linux_gnu } {
    465     if { $has_newabi } {
    466 	run_dump_test "textrel-1"
    467     }
    468     run_dump_test "got-page-1"
    469     if $has_newabi {
    470 	run_dump_test "got-page-2"
    471 	run_dump_test "dyn-sec64"
    472     }
    473     run_dump_test "got-page-3"
    474     run_ld_link_tests [subst {
    475 	{"GOT page 4 (one file)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
    476 	 "" "$abi_asflags(o32) -mips2" {got-page-4b.s}
    477 	 {{objdump -dr got-page-4a.d}
    478 	  {readelf -A got-page-4a.got}}
    479 	 "got-page-4a.so"}
    480 	{"GOT page 4 (two files)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
    481 	 "" "$abi_asflags(o32) -mips2" {got-page-4a.s got-page-4b.s}
    482 	 {{objdump -dr got-page-4b.d}
    483 	  {readelf -A got-page-4b.got}}
    484 	 "got-page-4b.so"}
    485     }]
    486     if $has_newabi {
    487         run_ld_link_tests [subst {
    488 	    {"GOT page 5" "-shared $abi_ldflags(n32) -T got-page-1.ld"
    489 	     "" "$abi_asflags(n32)" {got-page-5.s}
    490 	     {{objdump -dr got-page-5.d}
    491 	      {readelf -A got-page-5.got}}
    492 	     "got-page-5.so"}
    493 	    {"GOT page 6" "-shared $abi_ldflags(n32) -T got-page-1.ld"
    494 	     "" "$abi_asflags(n32)" {got-page-6.s}
    495 	     {{objdump -dr got-page-6.d}
    496 	      {readelf -A got-page-6.got}}
    497 	     "got-page-6.so"}
    498 	    {"GOT page 7 (order 1)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
    499 	     "" "$abi_asflags(n32)"
    500 	     {got-page-7a.s got-page-7b.s got-page-7c.s got-page-7d.s
    501 	      got-page-7e.s}
    502 	     {{objdump -dr got-page-7.d}
    503 	      {readelf -A got-page-7.got}}
    504 	     "got-page-7a.so"}
    505 	    {"GOT page 7 (order 2)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
    506 	     "" "$abi_asflags(n32)"
    507 	     {got-page-7e.s got-page-7a.s got-page-7b.s got-page-7c.s
    508 	      got-page-7d.s}
    509 	     {{objdump -dr got-page-7.d}
    510 	      {readelf -A got-page-7.got}}
    511 	     "got-page-7b.so"}
    512 	}]
    513     }
    514     run_dump_test "got-dump-1"
    515     if $has_newabi {
    516 	run_dump_test "got-dump-2"
    517     }
    518     run_dump_test "reloc-estimate-1"
    519 }
    520 
    521 if $has_newabi {
    522     run_dump_test "emit-relocs-1"
    523 }
    524 
    525 run_dump_test "hash1a"
    526 run_dump_test "hash1b"
    527 run_dump_test "hash1c"
    528 
    529 if {[istarget mips*-*-linux*]} {
    530      # The number of symbols that are always included in the symbol table
    531      # for these tests.  The 4 are:
    532      #
    533      #     the null symbol entry
    534      #     the .MIPS.stubs section symbol
    535      set base_syms 2
    536      foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
    537 	 run_ld_link_tests \
    538 	     [list [list \
    539 			"Stub for dynsym 0x$dynsym" \
    540 			"-shared -melf32btsmip -T stub-dynsym-1.ld" "" \
    541 			[concat \
    542 			     "-EB -march=mips1 -32 -KPIC" \
    543 			     "--defsym base_syms=$base_syms" \
    544 			     "--defsym dynsym=0x$dynsym"] \
    545 			[list "stub-dynsym-1.s"] \
    546 			[list [list \
    547 				   "objdump" "-dz" \
    548 				   "stub-dynsym-1-$dynsym.d"]] \
    549 			"stub-dynsym-1-$dynsym"]]
    550      }
    551  }
    552 
    553 # For tests which may involve multiple files, use run_ld_link_tests.
    554 
    555 # List contains test-items with 3 items followed by 2 lists:
    556 # 0:name 1:ld early options 2:ld late options 3:assembler options
    557 # 4:filenames of assembler files 5: action and options. 6: name of output file
    558 
    559 # Actions:
    560 # objdump: Apply objdump options on result.  Compare with regex (last arg).
    561 # nm: Apply nm options on result.  Compare with regex (last arg).
    562 # readelf: Apply readelf options on result.  Compare with regex (last arg).
    563 
    564 set mips_tls_tests {
    565     {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld" ""
    566      "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
    567      {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
    568      "tls-static-o32"}
    569     {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld" ""
    570      "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
    571      {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
    572      "tlslib-o32.so"}
    573     {"Dynamic executable with TLS"
    574      "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so" ""
    575      "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
    576      {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
    577      "tls-dynamic-o32"}
    578     {"Shared library with multiple GOTs and TLS"
    579      "-shared -melf32btsmip -T mips-lib.ld" ""
    580      "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
    581      {{readelf {-d -r} tls-multi-got-1.r}
    582       {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
    583       {objdump -Rsj.got tls-multi-got-1.got}}
    584      "tlslib-multi.so"}
    585     {"Shared library with TLS and versioning"
    586      "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver" ""
    587      "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
    588      {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
    589      "tlslib-o32-ver.so"}
    590     {"Dynamic executable with TLS and versioning"
    591      "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so" ""
    592      "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
    593      {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
    594      "tls-dynamic-o32-ver"}
    595     {"Dynamic executable with TLS and versioning (order 2)"
    596      "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o" ""
    597      "-EB -march=mips1 -32 -KPIC" {}
    598      {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
    599      "tls-dynamic-o32-ver-2"}
    600     {"Dynamic executable with TLS and versioning (order 3)"
    601      "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o" ""
    602      "-EB -march=mips1 -32 -KPIC" {}
    603      {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
    604      "tls-dynamic-o32-ver-3"}
    605     {"Shared library with TLS and hidden symbols"
    606      "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver" ""
    607      "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
    608      {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
    609      "tlslib-o32-hidden.so"}
    610     {"Shared library with TLS and hidden symbols (2)"
    611      "-shared -melf32btsmip -T mips-lib.ld" ""
    612      "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
    613      {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
    614      "tls-hidden2.so"}
    615     {"Shared library with TLS and hidden symbols (3)"
    616      "-shared -melf32btsmip -T tls-hidden3.ld" ""
    617      "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
    618      {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
    619       {readelf --relocs tls-hidden3.r}}
    620      "tls-hidden3.so"}
    621     {"Shared library with TLS and hidden symbols (4)"
    622      "-shared -melf32btsmip -T tls-hidden3.ld" ""
    623      "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
    624      {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
    625      "tls-hidden4.so"}
    626 }
    627 
    628 if {[istarget mips*-*-linux*]} {
    629     run_ld_link_tests $mips_tls_tests
    630 }
    631 
    632 set mips16_call_global_test [list \
    633     [list "Global calls from mips16" \
    634 	 "$abi_ldflags(o32) -T no-shared-1.ld" "" \
    635 	 "$abi_asflags(o32) -mips32r2" \
    636 	 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
    637 	 {{objdump -dr mips16-call-global.d}} \
    638 	 "mips16-call-global"]]
    639 
    640 run_ld_link_tests $mips16_call_global_test
    641 
    642 set mips16_intermix_test [list \
    643     [list "Intermixing mips32 and mips16 functions" \
    644 	 "$abi_ldflags(o32)" "" \
    645 	 "$abi_asflags(o32) -mips32r2" \
    646 	 {mips16-intermix-1.s mips16-intermix-2.s} \
    647 	 {{objdump -t mips16-intermix.d}} \
    648 	 "mips16-intermix"]]
    649 
    650 run_ld_link_tests $mips16_intermix_test
    651 
    652 run_dump_test "mips16-local-stubs-1"
    653 
    654 set o32flagslist [list [list as $abi_asflags(o32)] [list ld $abi_ldflags(o32)]]
    655 
    656 foreach firstfpabi [list 0 1 2 3 4 5 6 7 ] {
    657   foreach secondfpabi [list 4 5 6 7 ] {
    658     run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
    659   }
    660 }
    661 foreach firstfpabi [list 4 5 6 7 ] {
    662   foreach secondfpabi [list 0 1 2 3 8] {
    663     run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
    664   }
    665 }
    666 foreach firstfpabi [list 0 1 2 3 ] {
    667   foreach secondfpabi [list 0 1 2 3 8] {
    668     run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}"
    669   }
    670 }
    671 
    672 run_dump_test "attr-gnu-4-81"
    673 
    674 run_dump_test "attr-gnu-8-00"
    675 run_dump_test "attr-gnu-8-01"
    676 run_dump_test "attr-gnu-8-02"
    677 run_dump_test "attr-gnu-8-10"
    678 run_dump_test "attr-gnu-8-11"
    679 run_dump_test "attr-gnu-8-12"
    680 run_dump_test "attr-gnu-8-20"
    681 run_dump_test "attr-gnu-8-21"
    682 run_dump_test "attr-gnu-8-22"
    683 
    684 run_dump_test "attr-gnu-4-0-ph" $o32flagslist
    685 run_dump_test "attr-gnu-4-1-ph" $o32flagslist
    686 run_dump_test "attr-gnu-4-2-ph" $o32flagslist
    687 run_dump_test "attr-gnu-4-3-ph" $o32flagslist
    688 run_dump_test "attr-gnu-4-4-ph" $o32flagslist
    689 run_dump_test "attr-gnu-4-5-ph" $o32flagslist
    690 run_dump_test "attr-gnu-4-6-ph" $o32flagslist
    691 run_dump_test "attr-gnu-4-7-ph" $o32flagslist
    692 
    693 if $has_newabi {
    694   run_dump_test "attr-gnu-4-0-n32-ph"
    695   run_dump_test "attr-gnu-4-1-n32-ph"
    696   run_dump_test "attr-gnu-4-2-n32-ph"
    697   run_dump_test "attr-gnu-4-3-n32-ph"
    698   run_dump_test "attr-gnu-4-0-n64-ph"
    699   run_dump_test "attr-gnu-4-1-n64-ph"
    700   run_dump_test "attr-gnu-4-2-n64-ph"
    701   run_dump_test "attr-gnu-4-3-n64-ph"
    702 }
    703 
    704 run_dump_test "abiflags-strip1-ph" $o32flagslist
    705 run_dump_test "abiflags-strip2-ph" $o32flagslist
    706 run_dump_test "abiflags-strip3-ph" $o32flagslist
    707 run_dump_test "abiflags-strip4-ph" $o32flagslist
    708 run_dump_test "abiflags-strip5-ph" $o32flagslist
    709 run_dump_test "abiflags-strip6-ph" $o32flagslist
    710 run_dump_test "abiflags-strip7-ph" $o32flagslist
    711 run_dump_test "abiflags-strip8-ph" $o32flagslist
    712 run_dump_test "abiflags-strip9-ph" $o32flagslist
    713 run_dump_test "abiflags-strip10-ph" $o32flagslist
    714 
    715 run_dump_test "nan-legacy"
    716 run_dump_test "nan-2008"
    717 run_dump_test "nan-mixed-1"
    718 run_dump_test "nan-mixed-2"
    719 
    720 if { $linux_gnu } {
    721     run_ld_link_tests {
    722 	{"GOT and versioning 1"
    723 	 "-shared -melf32btsmip --version-script got-vers-1.ver" ""
    724 	 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
    725 	 {{readelf -d got-vers-1.dd}
    726 	  {readelf --symbols got-vers-1.sd}
    727 	  {readelf --relocs got-vers-1.rd}}
    728 	 "got-vers-1.so"}
    729     }
    730 }
    731 
    732 run_dump_test "undefined"
    733 
    734 # Test the conversion from jr to b
    735 if { $linux_gnu } {
    736     run_dump_test "jr-to-b-1"
    737     run_dump_test "jr-to-b-2"
    738 }
    739 
    740 # MIPS16 and microMIPS interlinking test.
    741 run_dump_test "mips16-and-micromips"
    742 
    743 # Export class call relocation tests.
    744 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
    745 foreach { abi } $abis {
    746     set loadaddr [string map \
    747 	{o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
    748     set suff [subst \
    749 	[expr { [istarget *-*-irix*] \
    750 		? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
    751 		: $abi }]]
    752     run_ld_link_tests [list \
    753 	[list \
    754 	    "MIPS export class call relocation test ($abi)" \
    755 	    "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
    756 	    "$abi_asflags($abi) -mips3 -KPIC" \
    757 	    [list export-class-call16-${abi}.s export-class-call16-def.s] \
    758 	    [list \
    759 		"objdump -d export-class-call16-${suff}.dd" \
    760 		"readelf -A export-class-call16-${abi}.gd"] \
    761 	    "export-class-call16-${abi}.so"]]
    762 }
    763 
    764 # Magic __ehdr_start symbol tests.
    765 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
    766 foreach { abi } $abis {
    767     set suff [string map {o32 o32 n32 new n64 new} $abi]
    768     run_ld_link_tests [list \
    769         [list \
    770             "MIPS magic __ehdr_start symbol test 1 ($abi)" \
    771             "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
    772             "$abi_asflags($abi)" \
    773             [list ehdr_start-${suff}.s] \
    774             [list "readelf -s ehdr_start-1.nd"] \
    775             "ehdr_start-1-${abi}"]]
    776     if [regexp "(?:n32|n64)" "$abi"] {
    777 	setup_kfail "mips*-*-*" "ld/15428"
    778     }
    779     run_ld_link_tests [list \
    780         [list \
    781             "MIPS magic __ehdr_start symbol test 2 ($abi)" \
    782             "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
    783             "$abi_asflags($abi)" \
    784             [list ehdr_start-${suff}.s] \
    785             [list "readelf -s ehdr_start-2.nd"] \
    786             "ehdr_start-2-${abi}"]]
    787 }
    788 
    789 # R_MIPS_JALR reloc tests.
    790 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
    791 foreach { abi } $abis {
    792     run_ld_link_tests [list \
    793 	[list \
    794 	    "MIPS JALR reloc test ($abi)" \
    795 	    "$abi_ldflags($abi) -T jalr3.ld" "" \
    796 	    "$abi_asflags($abi)" \
    797 	    [list ../../../gas/testsuite/gas/mips/jalr3.s] \
    798 	    [list "objdump -d jalr3.dd"] \
    799 	    "jalr3-${abi}"]]
    800 }
    801 
    802 proc build_mips_plt_lib { abi } {
    803     global abi_asflags
    804     global abi_ldflags
    805 
    806     run_ld_link_tests [list \
    807 	[list "Shared $abi library for compressed PLT tests" \
    808 	      "-shared $abi_ldflags($abi)" "" \
    809 	      "$abi_asflags($abi)" \
    810 	      { compressed-plt-1-dyn.s } \
    811 	      {} \
    812 	      "compressed-plt-1-${abi}-dyn.so"]]
    813 }
    814 
    815 proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
    816     global abi_asflags
    817     global abi_ldflags
    818 
    819     set as_flags "$abi_asflags($abi) --defsym filter=$filter"
    820     append as_flags " --defsym micromips=$micromips --defsym $abi=1"
    821     if {[string equal $abi o32]} {
    822 	append as_flags " -march=mips2"
    823     }
    824     set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
    825     set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
    826     set files [list]
    827     if { $filter & 3 } {
    828 	lappend files compressed-plt-1a.s
    829     }
    830     if { $filter & 12 } {
    831 	lappend files compressed-plt-1b.s
    832     }
    833     if { $filter & 16 } {
    834 	lappend files compressed-plt-1c.s
    835     }
    836     eval [list lappend files] $extra
    837     set readelf_flags "-A --syms --relocs -d"
    838     if { [string match "*word*" $suffix] } {
    839 	append readelf_flags " -x.data"
    840     }
    841     set objdump_flags "-d -Mgpr-names=numeric"
    842     set basename "compressed-plt-1-${abi}-${suffix}"
    843     run_ld_link_tests [list \
    844 	[list "$name" $ld_flags $dynobj \
    845 	      "$as_flags" $files \
    846 	      [list [list readelf $readelf_flags ${basename}.rd] \
    847 		    [list objdump $objdump_flags ${basename}.od]] \
    848 	      $basename]]
    849 }
    850 
    851 if { $linux_gnu } {
    852     build_mips_plt_lib o32
    853     run_mips_plt_test "o32 PLTs for standard encoding" o32 28 0 se
    854     run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 19 0 mips16-only
    855     run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 19 1 umips-only
    856     run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
    857 	o32 -1 0 mips16
    858     run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
    859 	o32 -1 0 mips16-got compressed-plt-1d.s
    860     run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
    861 	o32 -1 0 mips16-word compressed-plt-1e.s
    862     run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
    863 	o32 -1 1 umips
    864     run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
    865 	o32 -1 1 umips-got compressed-plt-1d.s
    866     run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
    867 	o32 -1 1 umips-word compressed-plt-1e.s
    868 
    869     if $has_newabi {
    870 	build_mips_plt_lib n32
    871 	run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
    872 	    n32 -1 0 mips16
    873 	run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
    874 	    n32 -1 1 umips
    875     }
    876 }
    877