1 # Expect script
for LD selective linking tests
2 # Copyright
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009,
3 #
2010, 2011 Free Software Foundation
, Inc.
5 # This file is part of the GNU Binutils.
7 # This
program is free software
; you can redistribute it and
/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation
; either version
3 of the License
, or
10 #
(at your option
) any later version.
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.
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
19 # Foundation
, Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
,
22 # Written by Catherine Moore
(clm@cygnus.com
)
23 # Make sure that constructors are handled correctly.
25 # Only ELF based ports support selective linking
26 if { ![is_elf_format
] ||
![check_gc_sections_available
] } {
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.
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.
37 # Note
: ld_nm trims leading `_
' from _start
39 # FIXME: Instead of table, read settings from each source-file.
41 {selective1 C 1.c {} {} {dropme1 dropme2} {}}
42 {selective2 C 2.c {} {} {foo} {}}
43 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
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*-*}}
46 {selective6 C++ 5.cc {} {start a A::bar()}
47 {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
50 set cflags "-w -O -ffunction-sections -fdata-sections"
51 set cxxflags "-fno-exceptions -fno-rtti"
52 set ldflags "--gc-sections -Bstatic"
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"
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
65 set ldflags
"-e _start -mshelf32 $ldflags"
68 #
If we don
't have g++ for the target, mark all tests as untested.
69 if { ![is_remote host] && [which $CXX] == 0 } {
70 foreach testitem $seltests {
71 untested "[lindex $testitem 0]"
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"
84 set ldargs [lindex $testitem 3]
85 set mustsyms [lindex $testitem 4]
86 set mustnotsyms [lindex $testitem 5]
87 set xfails [lindex $testitem 6]
89 foreach xfail_target $xfails {
90 setup_xfail $xfail_target
93 # It's either C or C
++ at the moment.
94 if { $testtype
== "C++" } {
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] {
101 set testflags
"$cflags $cxxflags"
104 set testflags
"$cflags $cxxflags -fvtable-gc"
107 set testflags
"$cflags"
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
114 if { ![ld_compile
"$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } {
119 # V850 targets need libgcc.a
120 if [istarget v850
*-*-elf
] {
121 set libgcc
[remote_exec host
"$compiler -print-libgcc-file-name"]
122 set libgcc
[lindex $libgcc
1]
123 regsub
-all
"\[\r\n\]" $libgcc "" libgcc
124 set objfile
"$objfile $libgcc"
127 # ARM targets need libgcc.a in THUMB
mode so that __call_via_r3 is provided
128 if {[istarget arm
-*-*]} {
129 set libgcc
[remote_exec host
"$compiler -print-libgcc-file-name"]
130 set libgcc
[lindex $libgcc
1]
131 regsub
-all
"\[\r\n\]" $libgcc "" libgcc
132 set objfile
"$objfile $libgcc"
135 # HPPA linux targets need libgcc.a
for millicode routines
($$dyncall
).
136 if [istarget hppa
*-*-linux
*] {
137 set libgcc
[remote_exec host
"$compiler -print-libgcc-file-name"]
138 set libgcc
[lindex $libgcc
1]
139 regsub
-all
"\[\r\n\]" $libgcc "" libgcc
140 set objfile
"$objfile $libgcc"
143 # m6811
/m6812 code has references to soft registers.
144 if {[istarget m6811
-*-*] ||
[istarget m6812
-*-*] ||
[istarget m68hc1
*-*-*]} {
145 set objfile
"$objfile --defsym _.frame=0 --defsym _.d1=0"
146 set objfile
"$objfile --defsym _.d2=0"
149 if ![ld_simple_link $
ld $ldfile
"$ldflags [join $ldargs] $objfile"] {
154 if ![ld_nm $nm
--demangle $ldfile
] {
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
)
166 # Check each mandated symbol and optionally mandated
values.
167 foreach mustsym $mustsyms
{
168 if { [llength
[concat $mustsym
]] == 1 } {
169 if { ![info exists nm_output
($mustsym
)] } {
170 verbose
-log "$testname: missing $mustsym"
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"
184 if { $nm_output
($mustsymname
) != $mustsymvalue
} {
185 verbose
-log "$testname: $mustsymname != $mustsymvalue"
186 verbose
-log "is instead $nm_output($mustsymname)"
195 if { $failed
!= 0 } {
199 # Check each unwanted symbol
, or that symbols
do not have specific
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)"
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"
222 if { $failed
== 0 } {