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