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