bfd/
[binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf-flags.exp
1 # Copyright 2003, 2007 Free Software Foundation, Inc.
2 #
3 # This file is part of the GNU Binutils.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18 # MA 02110-1301, USA.
19
20 if {![istarget mips*-*-*] || ![is_elf_format]} {
21 return
22 }
23
24 global ldemul
25 if {[istarget mips*-*-irix6*]} {
26 set ldemul "-melf32bsmip"
27 } elseif {[istarget mips*el-*-linux*]} {
28 set ldemul "-melf32ltsmip"
29 } elseif {[istarget mips*-*-linux*]} {
30 set ldemul "-melf32btsmip"
31 } else {
32 set ldemul ""
33 }
34
35 # Assemble jr.s using each of the argument lists in ARGLIST. Return the
36 # list of object files on success and an empty list on failure.
37 proc assemble_for_flags {arglist} {
38 global as srcdir subdir
39
40 set objs {}
41 set index 1
42
43 foreach args $arglist {
44 set obj "tmpdir/mips-flags-${index}.o"
45 if {![ld_assemble $as "$args $srcdir/$subdir/jr.s" $obj]} {
46 return ""
47 }
48 lappend objs $obj
49 incr index
50 }
51 return $objs
52 }
53
54 # Assemble a file using each set of arguments in ARGLIST. Check that
55 # the objects can be linked together and that the readelf output
56 # includes each flag named in FLAGS.
57 proc good_combination {arglist flags} {
58 global ld ldemul READELF
59
60 set finalobj "tmpdir/mips-flags.o"
61 set testname "MIPS compatible objects: $arglist"
62 set objs [assemble_for_flags $arglist]
63
64 if {$objs == ""} {
65 unresolved $testname
66 } elseif {![ld_simple_link "$ld $ldemul" $finalobj "-r $objs"]} {
67 fail $testname
68 } else {
69 catch "exec $READELF --headers $finalobj" output
70 if {![regexp "Flags: *(\[^\n\]*)" $output full gotflags]} {
71 unresolved $testname
72 } else {
73 set failed 0
74
75 # GOTFLAGS is a list of flags separated by ", ".
76 # Convert it to a tcl list.
77 regsub -all ", " $gotflags "," gotflags
78 set gotflags [split $gotflags ","]
79
80 foreach flag $flags {
81 if {[lsearch -exact $gotflags $flag] < 0} {
82 set failed 1
83 }
84 }
85 if {$failed} {
86 fail $testname
87 } else {
88 pass $testname
89 }
90 }
91 }
92 }
93
94 # Like good_combination, but check that the objects can't be linked
95 # together successfully and that the output includes MESSAGE.
96 proc bad_combination {arglist message} {
97 global link_output ld ldemul
98
99 set finalobj "tmpdir/mips-flags.o"
100 set testname "MIPS incompatible objects: $arglist"
101 set objs [assemble_for_flags $arglist]
102
103 if {$objs == ""} {
104 unresolved $testname
105 } elseif {[ld_simple_link "$ld $ldemul" $finalobj "-r $objs"]
106 || [string first $message $link_output] < 0} {
107 fail $testname
108 } else {
109 pass $testname
110 }
111 }
112
113 # Routines to check for various kinds of incompatibility.
114
115 proc abi_conflict {arglist firstabi secondabi} {
116 bad_combination $arglist \
117 "linking $secondabi module with previous $firstabi modules"
118 }
119
120 proc isa_conflict {arglist firstisa secondisa} {
121 bad_combination $arglist \
122 "linking mips:$secondisa module with previous mips:$firstisa modules"
123 }
124
125 proc regsize_conflict {arglist} {
126 bad_combination $arglist \
127 "linking 32-bit code with 64-bit code"
128 }
129
130 abi_conflict { "-mabi=eabi -mgp32" "-mips4 -mabi=32" } EABI32 O32
131 abi_conflict { "-mips4 -mabi=o64" "-mips3 -mabi=eabi" } O64 EABI64
132
133 isa_conflict { "-march=vr5500 -32" "-march=sb1 -32" } 5500 sb1
134 isa_conflict { "-march=vr5400 -32" "-march=4120 -32" } 5400 4120
135 isa_conflict { "-march=r3900 -32" "-march=r6000 -32" } 3900 6000
136 isa_conflict { "-march=r4010 -32" "-march=r4650 -32" } 4010 4650
137 isa_conflict { "-mips3 -mgp32 -32" "-mips32 -32" } 4000 isa32
138 isa_conflict { "-march=sb1 -mgp32 -32" "-mips32r2 -32" } sb1 isa32r2
139 isa_conflict { "-march=sb1 -32" "-mips64r2 -32" } sb1 isa64r2
140
141 regsize_conflict { "-mips4 -mgp64 -mabi=o64" "-mips2 -32" }
142 regsize_conflict { "-mips4 -mabi=o64" "-mips4 -mabi=32" }
143 regsize_conflict { "-mips4 -mabi=eabi -mgp32" "-mips4 -mabi=eabi -mgp64" }
144 regsize_conflict { "-march=vr5000 -mgp64 -mabi=o64" "-march=vr5000 -mgp32 -32" }
145 regsize_conflict { "-mips32 -32" "-mips64 -mabi=o64" }
146 regsize_conflict { "-mips32r2 -32" "-mips64 -mabi=o64" }
147 regsize_conflict { "-mips32r2 -32" "-mips64r2 -mabi=o64" }
148
149 good_combination { "-mips4 -mgp32 -32" "-mips2 -32" } { mips4 o32 }
150 good_combination { "-mips4 -mabi=32" "-mips2 -32" } { mips4 o32 }
151 good_combination { "-mips2 -32" "-mips4 -mabi=32" } { mips4 o32 }
152 good_combination { "-mips2 -mabi=eabi" "-mips4 -mabi=eabi -mgp32" } { mips4 eabi32 }
153 good_combination { "-mips2 -32" "-mips32 -32" "-mips32r2 -32" } { mips32r2 }
154 good_combination { "-mips1 -32" "-mips32r2 -32" "-mips32 -32" } { mips32r2 }
155
156 good_combination { "-march=vr4100 -32" "-march=vr4120 -32" } { 4120 }
157 good_combination { "-march=vr5400 -32" "-march=vr5500 -32" "-mips4 -32" } { 5500 }
158 good_combination { "-mips3 -32" "-mips4 -32" "-march=sb1 -32" "-mips5 -32" } { sb1 }
159 good_combination { "-mips1 -32" "-march=3900 -32" } { 3900 }
160 good_combination { "-mips3 -32" "-mips64r2 -32" "-mips64 -32" } { mips64r2 }
161
162 good_combination { "-march=vr4120 -mabi=32" "-mips3 -mabi=32" } { 4120 o32 }
163 good_combination { "-march=sb1 -mgp32 -32" "-march=4000 -mgp32 -32" } { sb1 o32 }
164 good_combination { "-mips32 -mabi=32" "-march=sb1 -mabi=32" } { sb1 o32 }
165 good_combination { "-mips64r2 -mabi=32" "-mips32 -mabi=32" } { mips64r2 o32 }
166 good_combination { "-mips5 -mabi=o64" "-mips64r2 -mabi=o64" } { mips64r2 o64 }