Support single digit GCC version
[deliverable/binutils-gdb.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 # Copyright (C) 1998-2017 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
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.
15 #
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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21 # Written by Catherine Moore (clm@cygnus.com)
22 # Make sure that constructors are handled correctly.
23
24 # Only ELF based ports support selective linking
25 if { ![is_elf_format] || ![check_gc_sections_available] } {
26 return
27 }
28
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 {
40 {selective1 C 1.c {} {} {dropme1 dropme2} {}}
41 {selective2 C 2.c {} {} {foo} {}}
42 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
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*-*}}
45 {selective6 C++ 5.cc {} {start a A::bar()}
46 {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
47 }
48
49 set cflags "-w -O -ffunction-sections -fdata-sections"
50 set cxxflags "-fno-exceptions -fno-rtti"
51 set ldflags "--gc-sections -Bstatic"
52
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
60 if [istarget sh64*-*-elf] {
61 # This is what gcc passes to ld by default, plus switch to the
62 # "usual" ELF _start (shelf32 normally uses just `start' for COFF
63 # compatibility)
64 set ldflags "-e _start -mshelf32 $ldflags"
65 }
66
67 if [istarget avr-*-*] {
68 # Make .text start at a non-zero address, as some tests expect
69 # valid symbols to have non-zero values.
70 set ldflags "--section-start=.text=0x2 $ldflags"
71 }
72
73 # If we don't have g++ for the target, mark all tests as untested.
74 if { ![is_remote host] && [which $CXX] == 0 } {
75 foreach testitem $seltests {
76 untested "[lindex $testitem 0]"
77 }
78 return
79 }
80
81 foreach testitem $seltests {
82 set testname [lindex $testitem 0]
83 set testtype [lindex $testitem 1]
84 set testfile [lindex $testitem 2]
85 set objfile "tmpdir/[file rootname $testfile].o"
86 set ldfile "tmpdir/[file rootname $testfile].x"
87 set failed 0
88
89 set ldargs [lindex $testitem 3]
90 set mustsyms [lindex $testitem 4]
91 set mustnotsyms [lindex $testitem 5]
92 set xfails [lindex $testitem 6]
93
94 foreach xfail_target $xfails {
95 setup_xfail $xfail_target
96 }
97
98 # It's either C or C++ at the moment.
99 if { $testtype == "C++" } {
100 set compiler "$CXX"
101 # Starting with 3.4.0, -fvtable-gc is no longer supported and thus
102 # the functionality we try to test for cannot be expected to work.
103 set version [remote_exec host "$CXX -dumpversion"]
104 set version [lindex $version 1]
105 if { [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+))\\." $version] \
106 || [regexp "^(\[1-9\]\[0-9\]+|\[4-9\])" $version] } {
107 set testflags "$cflags $cxxflags"
108 setup_xfail {*-*-*}
109 } else {
110 set testflags "$cflags $cxxflags -fvtable-gc"
111 }
112 } else {
113 set testflags "$cflags"
114 set compiler "$CC"
115 }
116
117 # Note that we do not actually *use* CXX; we just add cxxflags for C++
118 # tests. It might have been a buglet originally; now I think better
119 # leave as is.
120 if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } {
121 unresolved $testname
122 continue
123 }
124
125 # V850 targets need libgcc.a
126 if [istarget v850*-*-elf] {
127 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
128 set libgcc [lindex $libgcc 1]
129 regsub -all "\[\r\n\]" $libgcc "" libgcc
130 set objfile "$objfile $libgcc"
131 }
132
133 # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
134 if {[istarget arm-*-*]} {
135 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
136 set libgcc [lindex $libgcc 1]
137 regsub -all "\[\r\n\]" $libgcc "" libgcc
138 set objfile "$objfile $libgcc"
139 }
140
141 # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
142 if [istarget hppa*-*-linux*] {
143 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
144 set libgcc [lindex $libgcc 1]
145 regsub -all "\[\r\n\]" $libgcc "" libgcc
146 set objfile "$objfile $libgcc"
147 }
148
149 # m6811/m6812 code has references to soft registers.
150 if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} {
151 set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
152 set objfile "$objfile --defsym _.d2=0"
153 }
154
155 if ![ld_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
156 fail $testname
157 continue
158 }
159
160 if ![ld_nm $nm --demangle $ldfile] {
161 unresolved $testname
162 continue
163 }
164
165 # Must make V2 demangled names look like V3
166 foreach nm_output_key [array names nm_output] {
167 if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
168 set nm_output($new_nm_output_key) nm_output($nm_output_key)
169 }
170 }
171
172 # Check each mandated symbol and optionally mandated values.
173 foreach mustsym $mustsyms {
174 if { [llength [concat $mustsym]] == 1 } {
175 if { ![info exists nm_output($mustsym)] } {
176 verbose -log "$testname: missing $mustsym"
177 fail $testname
178 set failed 1
179 break
180 }
181 } {
182 set mustsymname [lindex $mustsym 0]
183 set mustsymvalue [lindex $mustsym 1]
184 if { ![info exists nm_output($mustsymname)] } {
185 verbose -log "$testname: missing $mustsymname"
186 fail $testname
187 set failed 1
188 break
189 } {
190 if { $nm_output($mustsymname) != $mustsymvalue } {
191 verbose -log "$testname: $mustsymname != $mustsymvalue"
192 verbose -log "is instead $nm_output($mustsymname)"
193 fail $testname
194 set failed 1
195 break
196 }
197 }
198 }
199 }
200
201 if { $failed != 0 } {
202 continue
203 }
204
205 # Check each unwanted symbol, or that symbols do not have specific
206 # values.
207 foreach mustnotsym $mustnotsyms {
208 if { [llength [concat $mustnotsym]] == 1 } {
209 if { [info exists nm_output($mustnotsym)] } {
210 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
211 fail $testname
212 set failed 1
213 break
214 }
215 } {
216 set mustnotsymname [lindex $mustnotsym 0]
217 set mustnotsymvalue [lindex $mustnotsym 1]
218 if { [info exists nm_output($mustnotsymname)] \
219 && $nm_output($mustnotsymname) == $mustnotsymvalue} {
220 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
221 fail $testname
222 set failed 1
223 break
224 }
225 }
226 }
227
228 if { $failed == 0 } {
229 pass $testname
230 }
231 }
This page took 0.035938 seconds and 4 git commands to generate.