Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for LD selective linking tests |
8c5fc800 JM |
2 | # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, |
3 | # 2010, 2011 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 | 25 | # Only ELF based ports support selective linking |
4a89cbfc | 26 | if { ![is_elf_format] || ![check_gc_sections_available] } { |
0fb33ef4 L |
27 | return |
28 | } | |
29 | ||
d63083ef HPN |
30 | # List contains test-items with three items followed by four lists: |
31 | # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags | |
32 | # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets. | |
33 | # | |
34 | # If a must(-not)-have symbol is a list, then that list must have two | |
35 | # items; the symbol name and a value the symbol must (not) have. | |
36 | # | |
37 | # Note: ld_nm trims leading `_' from _start | |
38 | # | |
39 | # FIXME: Instead of table, read settings from each source-file. | |
40 | set seltests { | |
031d7588 | 41 | {selective1 C 1.c {} {} {dropme1 dropme2} {}} |
8c991f18 TS |
42 | {selective2 C 2.c {} {} {foo} {}} |
43 | {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}} | |
031d7588 AM |
44 | {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {mips*-*}} |
45 | {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {mips*-*}} | |
453abe31 | 46 | {selective6 C++ 5.cc {} {start a A::bar()} |
067f2074 | 47 | {A::foo() B::foo() dropme1() dropme2()} {*-*-*}} |
d63083ef | 48 | } |
252b5132 | 49 | |
44df2f94 | 50 | set cflags "-w -O -ffunction-sections -fdata-sections" |
1d62840f | 51 | set cxxflags "-fno-exceptions -fno-rtti" |
252b5132 RH |
52 | set ldflags "--gc-sections -Bstatic" |
53 | ||
8c991f18 TS |
54 | if [istarget mips*-*] { |
55 | # MIPS16 doesn't support PIC code. | |
56 | set cflags "-mno-abicalls $cflags" | |
57 | # MIPS ELF uses __start by default, we override it. | |
58 | set ldflags "-e _start $ldflags" | |
59 | } | |
60 | ||
1b19eb81 AO |
61 | if [istarget sh64*-*-elf] { |
62 | # This is what gcc passes to ld by default, plus switch to the | |
63 | # "usual" ELF _start (shelf32 normally uses just `start' for COFF | |
64 | # compatibility) | |
65 | set ldflags "-e _start -mshelf32 $ldflags" | |
66 | } | |
67 | ||
d63083ef | 68 | # If we don't have g++ for the target, mark all tests as untested. |
7f6a71ff | 69 | if { ![is_remote host] && [which $CXX] == 0 } { |
d63083ef | 70 | foreach testitem $seltests { |
4291c3fa | 71 | untested "[lindex $testitem 0]" |
252b5132 | 72 | } |
252b5132 RH |
73 | return |
74 | } | |
75 | ||
d63083ef HPN |
76 | foreach testitem $seltests { |
77 | set testname [lindex $testitem 0] | |
78 | set testtype [lindex $testitem 1] | |
79 | set testfile [lindex $testitem 2] | |
80 | set objfile "tmpdir/[file rootname $testfile].o" | |
81 | set ldfile "tmpdir/[file rootname $testfile].x" | |
82 | set failed 0 | |
83 | ||
84 | set ldargs [lindex $testitem 3] | |
85 | set mustsyms [lindex $testitem 4] | |
86 | set mustnotsyms [lindex $testitem 5] | |
87 | set xfails [lindex $testitem 6] | |
88 | ||
89 | foreach xfail_target $xfails { | |
90 | setup_xfail $xfail_target | |
3017ff0e | 91 | } |
252b5132 | 92 | |
d63083ef HPN |
93 | # It's either C or C++ at the moment. |
94 | if { $testtype == "C++" } { | |
6182869c | 95 | set compiler "$CXX" |
466a53e0 AM |
96 | # Starting with 3.4.0, -fvtable-gc is no longer supported and thus |
97 | # the functionality we try to test for cannot be expected to work. | |
98 | set version [remote_exec host "$CXX -dumpversion"] | |
99 | set version [lindex $version 1] | |
100 | if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] { | |
1d62840f | 101 | set testflags "$cflags $cxxflags" |
466a53e0 | 102 | setup_xfail {*-*-*} |
1d62840f L |
103 | } else { |
104 | set testflags "$cflags $cxxflags -fvtable-gc" | |
23a75657 | 105 | } |
466a53e0 | 106 | } else { |
d63083ef | 107 | set testflags "$cflags" |
6182869c | 108 | set compiler "$CC" |
d63083ef | 109 | } |
252b5132 | 110 | |
d63083ef HPN |
111 | # Note that we do not actually *use* CXX; we just add cxxflags for C++ |
112 | # tests. It might have been a buglet originally; now I think better | |
113 | # leave as is. | |
6182869c | 114 | if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } { |
d63083ef | 115 | unresolved $testname |
453abe31 | 116 | continue |
3017ff0e | 117 | } |
252b5132 | 118 | |
f6673641 NC |
119 | # V850 targets need libgcc.a |
120 | if [istarget v850*-*-elf] { | |
6182869c | 121 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
122 | set libgcc [lindex $libgcc 1] |
123 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
6db74b6f | 124 | set objfile "$objfile $libgcc" |
f6673641 | 125 | } |
4f70f93f | 126 | |
8f2a6955 | 127 | # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided |
8c5fc800 | 128 | if {[istarget arm-*-*]} { |
6182869c | 129 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
130 | set libgcc [lindex $libgcc 1] |
131 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
6db74b6f | 132 | set objfile "$objfile $libgcc" |
8f2a6955 | 133 | } |
4f70f93f AM |
134 | |
135 | # HPPA linux targets need libgcc.a for millicode routines ($$dyncall). | |
136 | if [istarget hppa*-*-linux*] { | |
6182869c | 137 | set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] |
7f6a71ff JM |
138 | set libgcc [lindex $libgcc 1] |
139 | regsub -all "\[\r\n\]" $libgcc "" libgcc | |
4f70f93f AM |
140 | set objfile "$objfile $libgcc" |
141 | } | |
142 | ||
fef67c28 | 143 | # m6811/m6812 code has references to soft registers. |
32d79e68 | 144 | if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} { |
fef67c28 SC |
145 | set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0" |
146 | set objfile "$objfile --defsym _.d2=0" | |
147 | } | |
148 | ||
d63083ef HPN |
149 | if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] { |
150 | fail $testname | |
151 | continue | |
152 | } | |
252b5132 | 153 | |
067f2074 | 154 | if ![ld_nm $nm --demangle $ldfile] { |
d63083ef HPN |
155 | unresolved $testname |
156 | continue | |
157 | } | |
252b5132 | 158 | |
067f2074 AM |
159 | # Must make V2 demangled names look like V3 |
160 | foreach nm_output_key [array names nm_output] { | |
161 | if [regsub \\(void\\) $nm_output_key () new_nm_output_key] { | |
162 | set nm_output($new_nm_output_key) nm_output($nm_output_key) | |
163 | } | |
164 | } | |
165 | ||
4f70f93f | 166 | # Check each mandated symbol and optionally mandated values. |
d63083ef HPN |
167 | foreach mustsym $mustsyms { |
168 | if { [llength [concat $mustsym]] == 1 } { | |
169 | if { ![info exists nm_output($mustsym)] } { | |
170 | verbose -log "$testname: missing $mustsym" | |
171 | fail $testname | |
172 | set failed 1 | |
173 | break | |
174 | } | |
175 | } { | |
176 | set mustsymname [lindex $mustsym 0] | |
177 | set mustsymvalue [lindex $mustsym 1] | |
178 | if { ![info exists nm_output($mustsymname)] } { | |
179 | verbose -log "$testname: missing $mustsymname" | |
180 | fail $testname | |
181 | set failed 1 | |
182 | break | |
183 | } { | |
184 | if { $nm_output($mustsymname) != $mustsymvalue } { | |
185 | verbose -log "$testname: $mustsymname != $mustsymvalue" | |
186 | verbose -log "is instead $nm_output($mustsymname)" | |
187 | fail $testname | |
188 | set failed 1 | |
189 | break | |
e76e4c91 AM |
190 | } |
191 | } | |
3017ff0e AM |
192 | } |
193 | } | |
252b5132 | 194 | |
d63083ef HPN |
195 | if { $failed != 0 } { |
196 | continue | |
197 | } | |
252b5132 | 198 | |
d63083ef HPN |
199 | # Check each unwanted symbol, or that symbols do not have specific |
200 | # values. | |
201 | foreach mustnotsym $mustnotsyms { | |
202 | if { [llength [concat $mustnotsym]] == 1 } { | |
203 | if { [info exists nm_output($mustnotsym)] } { | |
204 | verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)" | |
205 | fail $testname | |
206 | set failed 1 | |
207 | break | |
208 | } | |
209 | } { | |
210 | set mustnotsymname [lindex $mustnotsym 0] | |
211 | set mustnotsymvalue [lindex $mustnotsym 1] | |
212 | if { [info exists nm_output($mustnotsymname)] \ | |
213 | && $nm_output($mustnotsymname) == $mustnotsymvalue} { | |
214 | verbose -log "$testname: $mustnotsymname == $mustnotsymvalue" | |
215 | fail $testname | |
216 | set failed 1 | |
217 | break | |
3017ff0e | 218 | } |
252b5132 RH |
219 | } |
220 | } | |
bd0110a3 | 221 | |
d63083ef HPN |
222 | if { $failed == 0 } { |
223 | pass $testname | |
bd0110a3 HPN |
224 | } |
225 | } |