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 | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | if {![istarget mips*-*-*] || ![is_elf_format]} { | |
18 | return | |
19 | } | |
20 | ||
21 | # Assemble jr.s using each of the argument lists in ARGLIST. Return the | |
22 | # list of object files on success and an empty list on failure. | |
23 | proc assemble_for_flags {arglist} { | |
24 | global as srcdir subdir | |
25 | ||
26 | set objs {} | |
27 | set index 1 | |
28 | ||
29 | foreach args $arglist { | |
30 | set obj "tmpdir/mips-flags-${index}.o" | |
31 | if {![ld_assemble $as "$args $srcdir/$subdir/jr.s" $obj]} { | |
32 | return "" | |
33 | } | |
34 | lappend objs $obj | |
35 | incr index | |
36 | } | |
37 | return $objs | |
38 | } | |
39 | ||
40 | # Assemble a file using each set of arguments in ARGLIST. Check that | |
41 | # the objects can be linked together and that the readelf output | |
42 | # includes each flag named in FLAGS. | |
43 | proc good_combination {arglist flags} { | |
44 | global ld READELF | |
45 | ||
46 | set finalobj "tmpdir/mips-flags.o" | |
47 | set testname "MIPS compatible objects: $arglist" | |
48 | set objs [assemble_for_flags $arglist] | |
49 | ||
50 | if {$objs == ""} { | |
51 | unresolved $testname | |
52 | } elseif {![ld_simple_link $ld $finalobj "-r $objs"]} { | |
53 | fail $testname | |
54 | } else { | |
55 | catch "exec $READELF --headers $finalobj" output | |
56 | if {![regexp "Flags: *(\[^\n\]*)" $output full gotflags]} { | |
57 | unresolved $testname | |
58 | } else { | |
59 | set failed 0 | |
60 | ||
61 | # GOTFLAGS is a list of flags separated by ", ". | |
62 | # Convert it to a tcl list. | |
63 | regsub -all ", " $gotflags "," gotflags | |
64 | set gotflags [split $gotflags ","] | |
65 | ||
66 | foreach flag $flags { | |
67 | if {[lsearch -exact $gotflags $flag] < 0} { | |
68 | set failed 1 | |
69 | } | |
70 | } | |
71 | if {$failed} { | |
72 | fail $testname | |
73 | } else { | |
74 | pass $testname | |
75 | } | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | # Like good_combination, but check that the objects can't be linked | |
81 | # together successfully and that the output includes MESSAGE. | |
82 | proc bad_combination {arglist message} { | |
83 | global link_output ld | |
84 | ||
85 | set finalobj "tmpdir/mips-flags.o" | |
86 | set testname "MIPS incompatible objects: $arglist" | |
87 | set objs [assemble_for_flags $arglist] | |
88 | ||
89 | if {$objs == ""} { | |
90 | unresolved $testname | |
91 | } elseif {[ld_simple_link $ld $finalobj "-r $objs"] | |
92 | || [string first $message $link_output] < 0} { | |
93 | fail $testname | |
94 | } else { | |
95 | pass $testname | |
96 | } | |
97 | } | |
98 | ||
99 | # Routines to check for various kinds of incompatibility. | |
100 | ||
101 | proc abi_conflict {arglist firstabi secondabi} { | |
102 | bad_combination $arglist \ | |
103 | "linking $secondabi module with previous $firstabi modules" | |
104 | } | |
105 | ||
106 | proc isa_conflict {arglist firstisa secondisa} { | |
107 | bad_combination $arglist \ | |
108 | "linking mips:$secondisa module with previous mips:$firstisa modules" | |
109 | } | |
110 | ||
111 | proc regsize_conflict {arglist} { | |
112 | bad_combination $arglist \ | |
113 | "linking 32-bit code with 64-bit code" | |
114 | } | |
115 | ||
116 | abi_conflict { "-mabi=eabi -mgp32" "-mips4 -mabi=32" } EABI32 O32 | |
117 | abi_conflict { "-mips4 -mabi=o64" "-mips3 -mabi=eabi" } O64 EABI64 | |
118 | ||
119 | isa_conflict { "-march=vr5500" "-march=sb1" } 5500 sb1 | |
120 | isa_conflict { "-march=vr5400" "-march=4120" } 5400 4120 | |
121 | isa_conflict { "-march=r3900" "-march=r6000" } 3900 6000 | |
122 | isa_conflict { "-march=r4010" "-march=r4650" } 4010 4650 | |
123 | isa_conflict { "-mips3 -mgp32" "-mips32" } 4000 isa32 | |
124 | isa_conflict { "-march=sb1 -mgp32" "-mips32r2" } sb1 isa32r2 | |
125 | ||
126 | regsize_conflict { "-mips4 -mgp64" "-mips2" } | |
127 | regsize_conflict { "-mips4 -mabi=o64" "-mips4 -mabi=32" } | |
128 | regsize_conflict { "-mabi=eabi -mgp32" "-mabi=eabi -mgp64" } | |
129 | regsize_conflict { "-march=vr5000 -mgp64" "-march=vr5000 -mgp32" } | |
130 | regsize_conflict { "-mips32" "-mips64" } | |
131 | regsize_conflict { "-mips32r2" "-mips64" } | |
132 | ||
133 | good_combination { "-mips4 -mgp32" "-mips2" } { mips4 32bitmode } | |
134 | good_combination { "-mips4 -mabi=32" "-mips2" } { mips4 o32 } | |
135 | good_combination { "-mips2" "-mips4 -mabi=32" } { mips4 o32 } | |
136 | good_combination { "-mips2" "-mips4 -mabi=eabi -mgp32" } { mips4 eabi32 } | |
137 | good_combination { "-mips2" "-mips32" "-mips32r2" } { mips32r2 } | |
138 | good_combination { "-mips1" "-mips32r2" "-mips32" } { mips32r2 } | |
139 | ||
140 | good_combination { "-march=vr4100" "-march=vr4120" } { 4120 } | |
141 | good_combination { "-march=vr5400" "-march=vr5500" "-mips4" } { 5500 } | |
142 | good_combination { "-mips3" "-mips4" "-march=sb1" "-mips5" } { sb1 } | |
143 | good_combination { "-mips1" "-march=3900" } { 3900 } | |
144 | ||
145 | good_combination { "-march=vr4120 -mabi=32" "-mips3 -mabi=32" } { 4120 o32 } | |
146 | good_combination { "-march=sb1 -mgp32" "-march=4000 -mgp32" } { sb1 32bitmode } |