+
+# Export class call relocation tests.
+set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
+foreach { abi } $abis {
+ set loadaddr [string map \
+ {o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
+ set suff [subst \
+ [expr { [istarget *-*-irix*] \
+ ? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
+ : $abi }]]
+ run_ld_link_tests [list \
+ [list \
+ "MIPS export class call relocation test ($abi)" \
+ "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
+ "$abi_asflags($abi) -mips3 -KPIC" \
+ [list export-class-call16-${abi}.s export-class-call16-def.s] \
+ [list \
+ "objdump -d export-class-call16-${suff}.dd" \
+ "readelf -A export-class-call16-${abi}.gd"] \
+ "export-class-call16-${abi}.so"]]
+}
+
+# Magic __ehdr_start symbol tests.
+set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
+foreach { abi } $abis {
+ set suff [string map {o32 o32 n32 new n64 new} $abi]
+ run_ld_link_tests [list \
+ [list \
+ "MIPS magic __ehdr_start symbol test 1 ($abi)" \
+ "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
+ "$abi_asflags($abi)" \
+ [list ehdr_start-${suff}.s] \
+ [list "readelf -s ehdr_start-1.nd"] \
+ "ehdr_start-1-${abi}"]]
+ if [regexp "(?:n32|n64)" "$abi"] {
+ setup_kfail "mips*-*-*" "ld/15428"
+ }
+ run_ld_link_tests [list \
+ [list \
+ "MIPS magic __ehdr_start symbol test 2 ($abi)" \
+ "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
+ "$abi_asflags($abi)" \
+ [list ehdr_start-${suff}.s] \
+ [list "readelf -s ehdr_start-2.nd"] \
+ "ehdr_start-2-${abi}"]]
+}
+
+# R_MIPS_JALR reloc tests.
+set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
+foreach { abi } $abis {
+ run_ld_link_tests [list \
+ [list \
+ "MIPS JALR reloc test ($abi)" \
+ "$abi_ldflags($abi) -T jalr3.ld" "" \
+ "$abi_asflags($abi)" \
+ [list ../../../gas/testsuite/gas/mips/jalr3.s] \
+ [list "objdump -d jalr3.dd"] \
+ "jalr3-${abi}"]]
+}
+
+proc build_mips_plt_lib { abi } {
+ global abi_asflags
+ global abi_ldflags
+
+ run_ld_link_tests [list \
+ [list "Shared $abi library for compressed PLT tests" \
+ "-shared $abi_ldflags($abi)" "" \
+ "$abi_asflags($abi)" \
+ { compressed-plt-1-dyn.s } \
+ {} \
+ "compressed-plt-1-${abi}-dyn.so"]]
+}
+
+proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
+ global abi_asflags
+ global abi_ldflags
+
+ set as_flags "$abi_asflags($abi) --defsym filter=$filter"
+ append as_flags " --defsym micromips=$micromips --defsym $abi=1"
+ if {[string equal $abi o32]} {
+ append as_flags " -march=mips2"
+ }
+ set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
+ set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
+ set files [list]
+ if { $filter & 3 } {
+ lappend files compressed-plt-1a.s
+ }
+ if { $filter & 12 } {
+ lappend files compressed-plt-1b.s
+ }
+ if { $filter & 16 } {
+ lappend files compressed-plt-1c.s
+ }
+ eval [list lappend files] $extra
+ set readelf_flags "-A --syms --relocs -d"
+ if { [string match "*word*" $suffix] } {
+ append readelf_flags " -x.data"
+ }
+ set objdump_flags "-d -Mgpr-names=numeric"
+ set basename "compressed-plt-1-${abi}-${suffix}"
+ run_ld_link_tests [list \
+ [list "$name" $ld_flags $dynobj \
+ "$as_flags" $files \
+ [list [list readelf $readelf_flags ${basename}.rd] \
+ [list objdump $objdump_flags ${basename}.od]] \
+ $basename]]
+}
+
+if { $linux_gnu } {
+ build_mips_plt_lib o32
+ run_mips_plt_test "o32 PLTs for standard encoding" o32 28 0 se
+ run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 19 0 mips16-only
+ run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 19 1 umips-only
+ run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
+ o32 -1 0 mips16
+ run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
+ o32 -1 0 mips16-got compressed-plt-1d.s
+ run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
+ o32 -1 0 mips16-word compressed-plt-1e.s
+ run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
+ o32 -1 1 umips
+ run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
+ o32 -1 1 umips-got compressed-plt-1d.s
+ run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
+ o32 -1 1 umips-word compressed-plt-1e.s
+
+ if $has_newabi {
+ build_mips_plt_lib n32
+ run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
+ n32 -1 0 mips16
+ run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
+ n32 -1 1 umips
+ }
+}
+
+# PR ld/19908 export class tests.
+if { $linux_gnu } {
+ run_ld_link_tests [list \
+ [list "Shared library for MIPS export class symbol reference tests" \
+ "$abi_ldflags(o32) -shared" "" \
+ "$abi_asflags(o32)" \
+ { export-class-ref-f2.s } \
+ { { readelf --dyn-syms export-class-ref-lib.sd } } \
+ "export-class-ref-lib.so"]]
+ foreach { class flag } { internal 1 hidden 2 protected 3 } {
+ run_ld_link_tests [list \
+ [list "MIPS $class symbol reference test 1" \
+ "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
+ "$abi_asflags(o32) --defsym defv=$flag" \
+ { export-class-ref-f0.s export-class-ref-f1.s } \
+ [list [list readelf --dyn-syms export-$class-ref.sd] \
+ [list readelf --dyn-syms export-local-ref.sd]] \
+ "export-$class-ref"] \
+ [list "MIPS $class symbol reference test 2" \
+ "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
+ "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
+ { export-class-ref-f0.s export-class-ref-f1.s } \
+ [list [list readelf --dyn-syms export-$class-ref.sd] \
+ [list readelf --dyn-syms export-local-ref.sd]] \
+ "export-$class-ref"]]
+ }
+}