diff options
Diffstat (limited to 'binutils-2.21/ld/testsuite/ld-selective')
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/1.c | 12 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/2.c | 19 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/3.cc | 46 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/4.cc | 34 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/5.cc | 38 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/keepdot.d | 9 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/keepdot.ld | 5 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/keepdot.s | 17 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/keepdot0.d | 11 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/keepdot0.ld | 6 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/sel-dump.exp | 35 | ||||
-rw-r--r-- | binutils-2.21/ld/testsuite/ld-selective/selective.exp | 239 |
12 files changed, 471 insertions, 0 deletions
diff --git a/binutils-2.21/ld/testsuite/ld-selective/1.c b/binutils-2.21/ld/testsuite/ld-selective/1.c new file mode 100644 index 0000000..1202367 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/1.c @@ -0,0 +1,12 @@ +/* _start should be the only thing left after GC. */ + +void _start() __asm__("_start"); +void _start() +{ +} + +void dropme1() +{ +} + +int dropme2[102] = { 0 }; diff --git a/binutils-2.21/ld/testsuite/ld-selective/2.c b/binutils-2.21/ld/testsuite/ld-selective/2.c new file mode 100644 index 0000000..7295887 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/2.c @@ -0,0 +1,19 @@ +/* Normally we should loose foo and keep _start and _init. + With -u foo, we should keep that as well. */ + +void _start() __asm__("_start"); +void _start() +{ +} + +void __attribute__((section(".init"))) +_init() +{ +} + +int foo() __asm__("foo"); +int foo() +{ + static int x = 1; + return x++; +} diff --git a/binutils-2.21/ld/testsuite/ld-selective/3.cc b/binutils-2.21/ld/testsuite/ld-selective/3.cc new file mode 100644 index 0000000..c40bf35 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/3.cc @@ -0,0 +1,46 @@ +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // keep +void A::bar() { } // lose + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // keep + +void _start() __asm__("_start"); // keep +void start() __asm__("start"); // some toolchains use this name. + +A a; // keep +B b; +A *getme() { return &a; } // keep + +void _start() +{ + getme()->foo(); +#ifdef __GNUC__ +#if (__GNUC__ == 2 && __GNUC_MINOR__ < 96) +// gcc-2.95.2 gets this test wrong, and loses B::foo(). +// Cheat. After all, we aren't trying to test the compiler here. + b.foo(); +#endif +#endif +} + +void start () +{ + _start (); +} + +// In addition, keep A's virtual table. + +// We'll wind up keeping `b' and thus B's virtual table because +// `a' and `b' are both referenced from the constructor function. + +extern "C" void __main() { } diff --git a/binutils-2.21/ld/testsuite/ld-selective/4.cc b/binutils-2.21/ld/testsuite/ld-selective/4.cc new file mode 100644 index 0000000..f4fc21c --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/4.cc @@ -0,0 +1,34 @@ +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // lose +void A::bar() { } // keep + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // lose + +void _start() __asm__("_start"); // keep +void start() __asm__("start"); // some toolchains use this name. + +A a; // keep +B b; +A *getme() { return &a; } // keep + +void _start() +{ + getme()->bar(); +} + +void start () +{ + _start (); +} + +extern "C" void __main() { } diff --git a/binutils-2.21/ld/testsuite/ld-selective/5.cc b/binutils-2.21/ld/testsuite/ld-selective/5.cc new file mode 100644 index 0000000..2c974d9 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/5.cc @@ -0,0 +1,38 @@ +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // lose +void A::bar() { } // keep + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // lose + +void _start() __asm__("_start"); // keep +void start() __asm__("start"); // some toolchains use this name. + +A a; // keep +B b; +A *getme() { return &a; } // keep + +extern B* dropme2(); +void dropme1() { dropme2()->foo(); } // lose +B *dropme2() { return &b; } // lose + +void _start() +{ + getme()->bar(); +} + +void start () +{ + _start (); +} + +extern "C" void __main() { } diff --git a/binutils-2.21/ld/testsuite/ld-selective/keepdot.d b/binutils-2.21/ld/testsuite/ld-selective/keepdot.d new file mode 100644 index 0000000..aadd5d4 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/keepdot.d @@ -0,0 +1,9 @@ +#ld: --gc-sections -Bstatic -e _start -T keepdot.ld +#name: Preserve default . = 0 +#objdump: -h + +# Check that GC:ing does not mess up the default value for dot. + +#... +[ ]+.[ ]+\.myinit[ ]+0+[48][ ]+0+[ ]+0+ .* +#pass diff --git a/binutils-2.21/ld/testsuite/ld-selective/keepdot.ld b/binutils-2.21/ld/testsuite/ld-selective/keepdot.ld new file mode 100644 index 0000000..d8a2b38 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/keepdot.ld @@ -0,0 +1,5 @@ +SECTIONS +{ + .myinit : { KEEP (*(.myinit)) } + .mytext : { *(.mytext*) *(.text*) } +} diff --git a/binutils-2.21/ld/testsuite/ld-selective/keepdot.s b/binutils-2.21/ld/testsuite/ld-selective/keepdot.s new file mode 100644 index 0000000..42176e2 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/keepdot.s @@ -0,0 +1,17 @@ + .text + .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0 + .stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0 + + .section .myinit,"ax" + .stabs "barxfoo:F(0,20)",36,0,2,_bar + .global _bar + .global _start +_start: +_bar: + .long 123 + + .section .mytext.baz,"ax" + .stabs "baz:F(0,20)",36,0,6,_baz + .global _baz +_baz: + .long 456 diff --git a/binutils-2.21/ld/testsuite/ld-selective/keepdot0.d b/binutils-2.21/ld/testsuite/ld-selective/keepdot0.d new file mode 100644 index 0000000..4432a01 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/keepdot0.d @@ -0,0 +1,11 @@ +#source: keepdot.s +#ld: --gc-sections -Bstatic -e _start -T keepdot0.ld +#name: Preserve explicit . = 0 +#objdump: -h + +# Check that GC:ing does not mess up the value for dot when specified +# as 0. + +#... +[ ]+.[ ]+\.myinit[ ]+0+[48][ ]+0+[ ]+0+ .* +#pass diff --git a/binutils-2.21/ld/testsuite/ld-selective/keepdot0.ld b/binutils-2.21/ld/testsuite/ld-selective/keepdot0.ld new file mode 100644 index 0000000..9f053d3 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/keepdot0.ld @@ -0,0 +1,6 @@ +SECTIONS +{ + . = 0x0; + .myinit : { KEEP (*(.myinit)) } + .mytext : { *(.mytext*) *(.text*) } +} diff --git a/binutils-2.21/ld/testsuite/ld-selective/sel-dump.exp b/binutils-2.21/ld/testsuite/ld-selective/sel-dump.exp new file mode 100644 index 0000000..5003d31 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/sel-dump.exp @@ -0,0 +1,35 @@ +# Expect script for ld selective linking tests running run_dump_test +# Copyright 2002, 2005, 2004, 2007 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +# Test for ELF here, so we don't have to qualify on ELF specifically +# in every .d-file. +if ![is_elf_format] { + return +} + +set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] +for { set i 0 } { $i < [llength $test_list] } { incr i } { + # We need to strip the ".d", but can leave the dirname. + verbose [file rootname [lindex $test_list $i]] + setup_xfail "alpha*-*" "am33*-*" "arc*-*" "d30v*-*" "dlx*-*" + setup_xfail "hppa*64-*-*" "i370*-*" "i860*-*" "i960*-*" "ia64*-*" + setup_xfail "m88*-*" "mn10200-*" "mep-*" "or32-*" "pj-*" + run_dump_test [file rootname [lindex $test_list $i]] +} diff --git a/binutils-2.21/ld/testsuite/ld-selective/selective.exp b/binutils-2.21/ld/testsuite/ld-selective/selective.exp new file mode 100644 index 0000000..81870c2 --- /dev/null +++ b/binutils-2.21/ld/testsuite/ld-selective/selective.exp @@ -0,0 +1,239 @@ +# Expect script for LD selective linking tests +# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +# Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# Written by Catherine Moore (clm@cygnus.com) +# Make sure that constructors are handled correctly. + +# Only ELF based ports support selective linking +if ![is_elf_format] { + return +} + +# These targets do not support selective linking +if {[istarget "alpha*-*-*"] || [istarget "am33*-*-*"] || + [istarget "arc-*-*"] || [istarget "d30v-*-*"] || + [istarget "dlx-*-*"] || [istarget "hppa*64*-*-*"] || + [istarget "i370-*-*"] || [istarget "i860-*-*"] || + [istarget "i960-*-*"] || [istarget "ia64-*-*"] || + [istarget "m88*-*-*"] || [istarget "mn10200-*-*"] || + [istarget "mep-*-*"] || [istarget "or32-*-*"] || + [istarget "pj*-*-*"]} { + return +} + +# List contains test-items with three items followed by four lists: +# 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags +# 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets. +# +# If a must(-not)-have symbol is a list, then that list must have two +# items; the symbol name and a value the symbol must (not) have. +# +# Note: ld_nm trims leading `_' from _start +# +# FIXME: Instead of table, read settings from each source-file. +set seltests { + {selective1 C 1.c {} {} {dropme1 dropme2} {}} + {selective2 C 2.c {} {} {foo} {}} + {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}} + {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {mips*-*}} + {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {mips*-*}} + {selective6 C++ 5.cc {} {start a A::bar()} + {A::foo() B::foo() dropme1() dropme2()} {*-*-*}} +} + +set cflags "-w -O -ffunction-sections -fdata-sections" +set cxxflags "-fno-exceptions -fno-rtti" +set ldflags "--gc-sections -Bstatic" + +if [istarget mips*-*] { + # MIPS16 doesn't support PIC code. + set cflags "-mno-abicalls $cflags" + # MIPS ELF uses __start by default, we override it. + set ldflags "-e _start $ldflags" +} + +if [istarget sh64*-*-elf] { + # This is what gcc passes to ld by default, plus switch to the + # "usual" ELF _start (shelf32 normally uses just `start' for COFF + # compatibility) + set ldflags "-e _start -mshelf32 $ldflags" +} + +# If we don't have g++ for the target, mark all tests as untested. +if { ![is_remote host] && [which $CXX] == 0 } { + foreach testitem $seltests { + untested "[lindex $testitem 0]" + } + return +} + +foreach testitem $seltests { + set testname [lindex $testitem 0] + set testtype [lindex $testitem 1] + set testfile [lindex $testitem 2] + set objfile "tmpdir/[file rootname $testfile].o" + set ldfile "tmpdir/[file rootname $testfile].x" + set failed 0 + + set ldargs [lindex $testitem 3] + set mustsyms [lindex $testitem 4] + set mustnotsyms [lindex $testitem 5] + set xfails [lindex $testitem 6] + + foreach xfail_target $xfails { + setup_xfail $xfail_target + } + setup_xfail "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*" + setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*" + + # It's either C or C++ at the moment. + if { $testtype == "C++" } { + set compiler "$CXX" + # Starting with 3.4.0, -fvtable-gc is no longer supported and thus + # the functionality we try to test for cannot be expected to work. + set version [remote_exec host "$CXX -dumpversion"] + set version [lindex $version 1] + if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] { + set testflags "$cflags $cxxflags" + setup_xfail {*-*-*} + } else { + set testflags "$cflags $cxxflags -fvtable-gc" + } + } else { + set testflags "$cflags" + set compiler "$CC" + } + + # Note that we do not actually *use* CXX; we just add cxxflags for C++ + # tests. It might have been a buglet originally; now I think better + # leave as is. + if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } { + unresolved $testname + continue + } + + # V850 targets need libgcc.a + if [istarget v850*-*-elf] { + set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] + set libgcc [lindex $libgcc 1] + regsub -all "\[\r\n\]" $libgcc "" libgcc + set objfile "$objfile $libgcc" + } + + # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided + if {[istarget arm-*-*] || [istarget xscale-*-*]} { + set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] + set libgcc [lindex $libgcc 1] + regsub -all "\[\r\n\]" $libgcc "" libgcc + set objfile "$objfile $libgcc" + } + + # HPPA linux targets need libgcc.a for millicode routines ($$dyncall). + if [istarget hppa*-*-linux*] { + set libgcc [remote_exec host "$compiler -print-libgcc-file-name"] + set libgcc [lindex $libgcc 1] + regsub -all "\[\r\n\]" $libgcc "" libgcc + set objfile "$objfile $libgcc" + } + + # m6811/m6812 code has references to soft registers. + if {[istarget m6811-*-*] || [istarget m6812-*-*]} { + set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0" + set objfile "$objfile --defsym _.d2=0" + } + + if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] { + fail $testname + continue + } + + if ![ld_nm $nm --demangle $ldfile] { + unresolved $testname + continue + } + + # Must make V2 demangled names look like V3 + foreach nm_output_key [array names nm_output] { + if [regsub \\(void\\) $nm_output_key () new_nm_output_key] { + set nm_output($new_nm_output_key) nm_output($nm_output_key) + } + } + + # Check each mandated symbol and optionally mandated values. + foreach mustsym $mustsyms { + if { [llength [concat $mustsym]] == 1 } { + if { ![info exists nm_output($mustsym)] } { + verbose -log "$testname: missing $mustsym" + fail $testname + set failed 1 + break + } + } { + set mustsymname [lindex $mustsym 0] + set mustsymvalue [lindex $mustsym 1] + if { ![info exists nm_output($mustsymname)] } { + verbose -log "$testname: missing $mustsymname" + fail $testname + set failed 1 + break + } { + if { $nm_output($mustsymname) != $mustsymvalue } { + verbose -log "$testname: $mustsymname != $mustsymvalue" + verbose -log "is instead $nm_output($mustsymname)" + fail $testname + set failed 1 + break + } + } + } + } + + if { $failed != 0 } { + continue + } + + # Check each unwanted symbol, or that symbols do not have specific + # values. + foreach mustnotsym $mustnotsyms { + if { [llength [concat $mustnotsym]] == 1 } { + if { [info exists nm_output($mustnotsym)] } { + verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)" + fail $testname + set failed 1 + break + } + } { + set mustnotsymname [lindex $mustnotsym 0] + set mustnotsymvalue [lindex $mustnotsym 1] + if { [info exists nm_output($mustnotsymname)] \ + && $nm_output($mustnotsymname) == $mustnotsymvalue} { + verbose -log "$testname: $mustnotsymname == $mustnotsymvalue" + fail $testname + set failed 1 + break + } + } + } + + if { $failed == 0 } { + pass $testname + } +} |