1 # Expect script for LD selective linking tests
2 # Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Written by Catherine Moore (clm@cygnus.com)
19 # Make sure that constructors are handled correctly.
22 # AOUT based ports do not support selective linking
23 if {[istarget "*-*-*aout*"] \
24 || [istarget "*-*-*bout*"] \
25 || [istarget "vax-*-ultrix*"]} {
29 # COFF based ports do not support selective linking
30 if {[istarget "*-*-coff"]} {
33 if {[istarget "*-*-pe"]} {
37 # Alpha does not support selective linking
38 if {[istarget "alpha*-*-*"]} {
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.
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.
49 # Note: ld_nm trims leading `_' from _start
51 # FIXME: Instead of table, read settings from each source-file.
53 {selective1 C 1.c {} {} {dropme1 dropme2} {alpha*-*}}
54 {selective2 C 2.c {} {} {foo} {alpha*-* mips*-*}}
55 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {mips*-*}}
56 {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {alpha*-* mips*-*}}
57 {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {alpha*-* mips*-*}}
58 {selective6 C++ 5.cc {} {start a A::bar()}
59 {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
62 set cflags "-w -O -ffunction-sections -fdata-sections"
63 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
64 set ldflags "--gc-sections -Bstatic"
66 if [istarget sh64*-*-elf] {
67 # This is what gcc passes to ld by default, plus switch to the
68 # "usual" ELF _start (shelf32 normally uses just `start' for COFF
70 set ldflags "-e _start -mshelf32 $ldflags"
73 # If we don't have g++ for the target, mark all tests as untested.
74 if { [which $CXX] == 0 } {
75 foreach testitem $seltests {
76 untested "[lindex $testitem 0]"
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"
89 set ldargs [lindex $testitem 3]
90 set mustsyms [lindex $testitem 4]
91 set mustnotsyms [lindex $testitem 5]
92 set xfails [lindex $testitem 6]
94 foreach xfail_target $xfails {
95 setup_xfail $xfail_target
98 # It's either C or C++ at the moment.
99 if { $testtype == "C++" } {
100 set testflags "$cflags $cxxflags"
102 set testflags "$cflags"
105 # Note that we do not actually *use* CXX; we just add cxxflags for C++
106 # tests. It might have been a buglet originally; now I think better
108 if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
113 # V850 targets need libgcc.a
114 # FIXME: This does not work with installed toolchains!
115 if [istarget v850*-*-elf] {
116 set objfile "$objfile -L ../gcc -lgcc"
119 # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
120 # FIXME: This does not work with installed toolchains!
121 if {[istarget arm-*-*] || [istarget xscale-*-*]} {
122 set objfile "$objfile -L ../gcc -lgcc"
125 # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
126 if [istarget hppa*-*-linux*] {
127 catch "exec $CC -print-libgcc-file-name" libgcc
128 set objfile "$objfile $libgcc"
131 # m6811/m6812 code has references to soft registers.
132 if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
133 set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
134 set objfile "$objfile --defsym _.d2=0"
137 if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
142 if ![ld_nm $nm --demangle $ldfile] {
147 # Must make V2 demangled names look like V3
148 foreach nm_output_key [array names nm_output] {
149 if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
150 set nm_output($new_nm_output_key) nm_output($nm_output_key)
154 # Check each mandated symbol and optionally mandated values.
155 foreach mustsym $mustsyms {
156 if { [llength [concat $mustsym]] == 1 } {
157 if { ![info exists nm_output($mustsym)] } {
158 verbose -log "$testname: missing $mustsym"
164 set mustsymname [lindex $mustsym 0]
165 set mustsymvalue [lindex $mustsym 1]
166 if { ![info exists nm_output($mustsymname)] } {
167 verbose -log "$testname: missing $mustsymname"
172 if { $nm_output($mustsymname) != $mustsymvalue } {
173 verbose -log "$testname: $mustsymname != $mustsymvalue"
174 verbose -log "is instead $nm_output($mustsymname)"
183 if { $failed != 0 } {
187 # Check each unwanted symbol, or that symbols do not have specific
189 foreach mustnotsym $mustnotsyms {
190 if { [llength [concat $mustnotsym]] == 1 } {
191 if { [info exists nm_output($mustnotsym)] } {
192 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
198 set mustnotsymname [lindex $mustnotsym 0]
199 set mustnotsymvalue [lindex $mustnotsym 1]
200 if { [info exists nm_output($mustnotsymname)] \
201 && $nm_output($mustnotsymname) == $mustnotsymvalue} {
202 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
210 if { $failed == 0 } {