Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for LD selective linking tests |
f96b4a7b | 2 | # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007 |
6db74b6f | 3 | # Free Software Foundation, Inc. |
252b5132 | 4 | # |
f96b4a7b NC |
5 | # This file is part of the GNU Binutils. |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
252b5132 | 8 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 9 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 10 | # (at your option) any later version. |
4f70f93f | 11 | # |
252b5132 RH |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
4f70f93f | 16 | # |
252b5132 RH |
17 | # You should have received a copy of the GNU General Public License |
18 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | # MA 02110-1301, USA. | |
252b5132 RH |
21 | # |
22 | # Written by Catherine Moore (clm@cygnus.com) | |
23 | # Make sure that constructors are handled correctly. | |
24 | ||
031d7588 AM |
25 | # Only ELF based ports support selective linking |
26 | if ![is_elf_format] { | |
4648dfcf MS |
27 | return |
28 | } | |
29 | ||
0f02bbd9 AM |
30 | # These targets do not support selective linking |
31 | if {[istarget "alpha*-*-*"] || [istarget "am33*-*-*"] || | |
32 | [istarget "arc-*-*"] || [istarget "d30v-*-*"] || | |
33 | [istarget "dlx-*-*"] || [istarget "hppa*64*-*-*"] || | |
34 | [istarget "i370-*-*"] || [istarget "i860-*-*"] || | |
35 | [istarget "i960-*-*"] || [istarget "ia64-*-*"] || | |
36 | [istarget "m88*-*-*"] || [istarget "mn10200-*-*"] || | |
37 | [istarget "mep-*-*"] || [istarget "or32-*-*"] || | |
38 | [istarget "pj*-*-*"]} { | |
0fb33ef4 L |
39 | return |
40 | } | |
41 | ||
d63083ef HPN |
42 | # List contains test-items with three items followed by four lists: |
43 | # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags | |
44 | # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets. | |
45 | # | |
46 | # If a must(-not)-have symbol is a list, then that list must have two | |
47 | # items; the symbol name and a value the symbol must (not) have. | |
48 | # | |
49 | # Note: ld_nm trims leading `_' from _start | |
50 | # | |
51 | # FIXME: Instead of table, read settings from each source-file. | |
52 | set seltests { | |
031d7588 | 53 | {selective1 C 1.c {} {} {dropme1 dropme2} {}} |
8c991f18 TS |
54 | {selective2 C 2.c {} {} {foo} {}} |
55 | {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}} | |
031d7588 AM |
56 | {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {mips*-*}} |
57 | {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {mips*-*}} | |
453abe31 | 58 | {selective6 C++ 5.cc {} {start a A::bar()} |
067f2074 | 59 | {A::foo() B::foo() dropme1() dropme2()} {*-*-*}} |
d63083ef | 60 | } |
252b5132 | 61 | |
44df2f94 | 62 | set cflags "-w -O -ffunction-sections -fdata-sections" |
252b5132 RH |
63 | set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti" |
64 | set ldflags "--gc-sections -Bstatic" | |
65 | ||
8c991f18 TS |
66 | if [istarget mips*-*] { |
67 | # MIPS16 doesn't support PIC code. | |
68 | set cflags "-mno-abicalls $cflags" | |
69 | # MIPS ELF uses __start by default, we override it. | |
70 | set ldflags "-e _start $ldflags" | |
71 | } | |
72 | ||
1b19eb81 AO |
73 | if [istarget sh64*-*-elf] { |
74 | # This is what gcc passes to ld by default, plus switch to the | |
75 | # "usual" ELF _start (shelf32 normally uses just `start' for COFF | |
76 | # compatibility) | |
77 | set ldflags "-e _start -mshelf32 $ldflags" | |
78 | } | |
79 | ||
d63083ef | 80 | # If we don't have g++ for the target, mark all tests as untested. |
7f6a71ff | 81 | if { ![is_remote host] && [which $CXX] == 0 } { |
d63083ef | 82 | foreach testitem $seltests { |
4291c3fa | 83 | untested "[lindex $testitem 0]" |
252b5132 | 84 | } |
252b5132 RH |
85 | return |
86 | } | |
87 | ||
d63083ef HPN |
88 | foreach testitem $seltests { |
89 | set testname [lindex $testitem 0] | |
90 | set testtype [lindex $testitem 1] | |
91 | set testfile [lindex $testitem 2] | |
92 | set objfile "tmpdir/[file rootname $testfile].o" | |
93 | set ldfile "tmpdir/[file rootname $testfile].x" | |
94 | set failed 0 | |
95 | ||
96 | set ldargs [lindex $testitem 3] | |
97 | set mustsyms [lindex $testitem 4] | |
98 | set mustnotsyms [lindex $testitem 5] | |
99 | set xfails [lindex $testitem 6] | |
100 | ||
101 | foreach xfail_target $xfails { | |
102 | setup_xfail $xfail_target | |
3017ff0e | 103 | } |
175ac043 | 104 | setup_xfail "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*" |
40937810 | 105 | setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*" |
252b5132 | 106 | |
d63083ef HPN |
107 | # It's either C or C++ at the moment. |
108 | if { $testtype == "C++" } { | |
109 | set testflags "$cflags $cxxflags" | |
6182869c | 110 | set compiler "$CXX" |
23a75657 NC |
111 | if [string match "*gcc*" [lindex $CC 0]] { |
112 | # Starting with 3.4.0, -fvtable-gc is no longer supported and thus | |
113 | # the functionality we try to test for cannot be expected to work. | |
7f6a71ff JM |
114 | set version [remote_exec host "$CC -dumpversion"] |
115 | set version [lindex $version 1] | |
23a75657 NC |
116 | if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] { |
117 | setup_xfail {*-*-*} | |
118 | } | |
119 | } | |
d63083ef HPN |
120 | } { |
121 | set testflags "$cflags" | |
6182869c | 122 | set compiler "$CC" |
d63083ef | 123 | } |
252b5132 | 124 | |
d63083ef HPN |
125 | # Note that we do not actually *use* CXX; we just add cxxflags for C++ |
126 | # tests. It might have been a buglet originally; now I think better | |
127 | # leave as is. | |
6182869c | 128 | if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } { |
d63083ef | 129 | unresolved $testname |
453abe31 | 130 | continue |
3017ff0e | 131 | } |
252b5132 | 132 | |
f6673641 NC |
133 | # V850 targets need libgcc.a |
134 | if [istarget v850*-*-elf] { | |
6182869c | 135 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
136 | set libgcc [lindex $libgcc 1] |
137 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
6db74b6f | 138 | set objfile "$objfile $libgcc" |
f6673641 | 139 | } |
4f70f93f | 140 | |
8f2a6955 NC |
141 | # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided |
142 | if {[istarget arm-*-*] || [istarget xscale-*-*]} { | |
6182869c | 143 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
144 | set libgcc [lindex $libgcc 1] |
145 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
6db74b6f | 146 | set objfile "$objfile $libgcc" |
8f2a6955 | 147 | } |
4f70f93f AM |
148 | |
149 | # HPPA linux targets need libgcc.a for millicode routines ($$dyncall). | |
150 | if [istarget hppa*-*-linux*] { | |
6182869c | 151 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
152 | set libgcc [lindex $libgcc 1] |
153 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
4f70f93f AM |
154 | set objfile "$objfile $libgcc" |
155 | } | |
156 | ||
fef67c28 SC |
157 | # m6811/m6812 code has references to soft registers. |
158 | if {[istarget m6811-*-*] || [istarget m6812-*-*]} { | |
159 | set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0" | |
160 | set objfile "$objfile --defsym _.d2=0" | |
161 | } | |
162 | ||
d63083ef HPN |
163 | if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] { |
164 | fail $testname | |
165 | continue | |
166 | } | |
252b5132 | 167 | |
067f2074 | 168 | if ![ld_nm $nm --demangle $ldfile] { |
d63083ef HPN |
169 | unresolved $testname |
170 | continue | |
171 | } | |
252b5132 | 172 | |
067f2074 AM |
173 | # Must make V2 demangled names look like V3 |
174 | foreach nm_output_key [array names nm_output] { | |
175 | if [regsub \\(void\\) $nm_output_key () new_nm_output_key] { | |
176 | set nm_output($new_nm_output_key) nm_output($nm_output_key) | |
177 | } | |
178 | } | |
179 | ||
4f70f93f | 180 | # Check each mandated symbol and optionally mandated values. |
d63083ef HPN |
181 | foreach mustsym $mustsyms { |
182 | if { [llength [concat $mustsym]] == 1 } { | |
183 | if { ![info exists nm_output($mustsym)] } { | |
184 | verbose -log "$testname: missing $mustsym" | |
185 | fail $testname | |
186 | set failed 1 | |
187 | break | |
188 | } | |
189 | } { | |
190 | set mustsymname [lindex $mustsym 0] | |
191 | set mustsymvalue [lindex $mustsym 1] | |
192 | if { ![info exists nm_output($mustsymname)] } { | |
193 | verbose -log "$testname: missing $mustsymname" | |
194 | fail $testname | |
195 | set failed 1 | |
196 | break | |
197 | } { | |
198 | if { $nm_output($mustsymname) != $mustsymvalue } { | |
199 | verbose -log "$testname: $mustsymname != $mustsymvalue" | |
200 | verbose -log "is instead $nm_output($mustsymname)" | |
201 | fail $testname | |
202 | set failed 1 | |
203 | break | |
e76e4c91 AM |
204 | } |
205 | } | |
3017ff0e AM |
206 | } |
207 | } | |
252b5132 | 208 | |
d63083ef HPN |
209 | if { $failed != 0 } { |
210 | continue | |
211 | } | |
252b5132 | 212 | |
d63083ef HPN |
213 | # Check each unwanted symbol, or that symbols do not have specific |
214 | # values. | |
215 | foreach mustnotsym $mustnotsyms { | |
216 | if { [llength [concat $mustnotsym]] == 1 } { | |
217 | if { [info exists nm_output($mustnotsym)] } { | |
218 | verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)" | |
219 | fail $testname | |
220 | set failed 1 | |
221 | break | |
222 | } | |
223 | } { | |
224 | set mustnotsymname [lindex $mustnotsym 0] | |
225 | set mustnotsymvalue [lindex $mustnotsym 1] | |
226 | if { [info exists nm_output($mustnotsymname)] \ | |
227 | && $nm_output($mustnotsymname) == $mustnotsymvalue} { | |
228 | verbose -log "$testname: $mustnotsymname == $mustnotsymvalue" | |
229 | fail $testname | |
230 | set failed 1 | |
231 | break | |
3017ff0e | 232 | } |
252b5132 RH |
233 | } |
234 | } | |
bd0110a3 | 235 | |
d63083ef HPN |
236 | if { $failed == 0 } { |
237 | pass $testname | |
bd0110a3 HPN |
238 | } |
239 | } |