]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-selective/selective.exp
ld: Pass -fno-sanitize=all to tests with linker
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-selective / selective.exp
CommitLineData
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 25if { ![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.
39set 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
49global NOSANTIZE_CFLAGS
50set cflags "-w -O -ffunction-sections -fdata-sections $NOSANTIZE_CFLAGS"
51set cxxflags "-fno-exceptions -fno-rtti $NOSANTIZE_CFLAGS"
252b5132
RH
52set ldflags "--gc-sections -Bstatic"
53
8c991f18
TS
54if [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
4a85cc09
SKS
61if [istarget avr-*-*] {
62 # Make .text start at a non-zero address, as some tests expect
63 # valid symbols to have non-zero values.
64 set ldflags "--section-start=.text=0x2 $ldflags"
65}
66
d63083ef 67# If we don't have g++ for the target, mark all tests as untested.
7f6a71ff 68if { ![is_remote host] && [which $CXX] == 0 } {
d63083ef 69 foreach testitem $seltests {
4291c3fa 70 untested "[lindex $testitem 0]"
252b5132 71 }
252b5132
RH
72 return
73}
74
d63083ef
HPN
75foreach testitem $seltests {
76 set testname [lindex $testitem 0]
77 set testtype [lindex $testitem 1]
78 set testfile [lindex $testitem 2]
79 set objfile "tmpdir/[file rootname $testfile].o"
80 set ldfile "tmpdir/[file rootname $testfile].x"
81 set failed 0
82
83 set ldargs [lindex $testitem 3]
84 set mustsyms [lindex $testitem 4]
85 set mustnotsyms [lindex $testitem 5]
86 set xfails [lindex $testitem 6]
87
88 foreach xfail_target $xfails {
89 setup_xfail $xfail_target
3017ff0e 90 }
252b5132 91
d63083ef
HPN
92 # It's either C or C++ at the moment.
93 if { $testtype == "C++" } {
6182869c 94 set compiler "$CXX"
466a53e0
AM
95 # Starting with 3.4.0, -fvtable-gc is no longer supported and thus
96 # the functionality we try to test for cannot be expected to work.
97 set version [remote_exec host "$CXX -dumpversion"]
98 set version [lindex $version 1]
61a0857c
L
99 if { [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+))\\." $version] \
100 || [regexp "^(\[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
d9816402 149 if ![ld_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
d63083ef
HPN
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}