diff options
author | Richard Henderson <rth@redhat.com> | 1999-05-03 07:29:11 +0000 |
---|---|---|
committer | Richard Henderson <rth@redhat.com> | 1999-05-03 07:29:11 +0000 |
commit | 252b5132c753830d5fd56823373aed85f2a0db63 (patch) | |
tree | 1af963bfd8d3e55167b81def4207f175eaff3a56 /ld/testsuite/ld-selective | |
download | gdb-252b5132c753830d5fd56823373aed85f2a0db63.zip gdb-252b5132c753830d5fd56823373aed85f2a0db63.tar.gz gdb-252b5132c753830d5fd56823373aed85f2a0db63.tar.bz2 |
19990502 sourceware importbinu_ss_19990502
Diffstat (limited to 'ld/testsuite/ld-selective')
-rw-r--r-- | ld/testsuite/ld-selective/1.c | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-selective/2.c | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-selective/3.cc | 33 | ||||
-rw-r--r-- | ld/testsuite/ld-selective/4.cc | 28 | ||||
-rw-r--r-- | ld/testsuite/ld-selective/5.cc | 32 | ||||
-rw-r--r-- | ld/testsuite/ld-selective/selective.exp | 208 |
6 files changed, 332 insertions, 0 deletions
diff --git a/ld/testsuite/ld-selective/1.c b/ld/testsuite/ld-selective/1.c new file mode 100644 index 0000000..1202367 --- /dev/null +++ b/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/ld/testsuite/ld-selective/2.c b/ld/testsuite/ld-selective/2.c new file mode 100644 index 0000000..7295887 --- /dev/null +++ b/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/ld/testsuite/ld-selective/3.cc b/ld/testsuite/ld-selective/3.cc new file mode 100644 index 0000000..852bc5d --- /dev/null +++ b/ld/testsuite/ld-selective/3.cc @@ -0,0 +1,33 @@ +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // keep +void A::bar() { } // loose + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // keep + +void _start() __asm__("_start"); // keep + +A a; // keep +B b; +A *getme() { return &a; } // keep + +void _start() +{ + getme()->foo(); +} + +// 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/ld/testsuite/ld-selective/4.cc b/ld/testsuite/ld-selective/4.cc new file mode 100644 index 0000000..9df26ac --- /dev/null +++ b/ld/testsuite/ld-selective/4.cc @@ -0,0 +1,28 @@ +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // loose +void A::bar() { } // keep + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // loose + +void _start() __asm__("_start"); // keep + +A a; // keep +B b; +A *getme() { return &a; } // keep + +void _start() +{ + getme()->bar(); +} + +extern "C" void __main() { } diff --git a/ld/testsuite/ld-selective/5.cc b/ld/testsuite/ld-selective/5.cc new file mode 100644 index 0000000..5179d91 --- /dev/null +++ b/ld/testsuite/ld-selective/5.cc @@ -0,0 +1,32 @@ +// This test currently fails because the C++ front end emits `A' as +// the base class called rather than `B' as it ought. At least it +// is erroring on the safe side... + +struct A +{ + virtual void foo(); + virtual void bar(); +}; + +void A::foo() { } // loose +void A::bar() { } // loose + +struct B : public A +{ + virtual void foo(); +}; + +void B::foo() { } // keep + +void _start() __asm__("_start"); // keep + +A a; +B b; // keep +B *getme() { return &b; } // keep + +void _start() +{ + getme()->foo(); +} + +extern "C" void __main() { } diff --git a/ld/testsuite/ld-selective/selective.exp b/ld/testsuite/ld-selective/selective.exp new file mode 100644 index 0000000..e6a9d97 --- /dev/null +++ b/ld/testsuite/ld-selective/selective.exp @@ -0,0 +1,208 @@ +# Expect script for LD selective linking tests +# Copyright (C) 1998, 1999 Free Software Foundation +# +# This file 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Written by Catherine Moore (clm@cygnus.com) +# Make sure that constructors are handled correctly. + + +# COFF based ports do not support selective linking +if {[istarget "*-*-coff" "*-*-pe"]} { + return +} + +set test1 "selective1" +set test2 "selective2" +set test3 "selective3" +set test4 "selective4" +set test5 "selective5" +set test6 "selective6" + +set cflags "-w -O2 -ffunction-sections -fdata-sections" +set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti" +set ldflags "--gc-sections -Bstatic" + +if { [which $CXX] == 0 } { + untested $test1 + untested $test2 + untested $test3 + untested $test4 + untested $test5 + untested $test6 + return +} + +if { ![ld_compile "$CC $cflags" $srcdir/$subdir/1.c tmpdir/1.o]} { + unresolved $test1 + return +} + +if ![ld_simple_link $ld tmpdir/1.x "$ldflags tmpdir/1.o"] { + fail $test1 +} else { + if ![ld_nm $nm tmpdir/1.x] { + unresolved $test1 + } else { + if {[info exists nm_output(dropme1)]} { + send_log "dropme1 == $nm_output(dropme1)\n" + verbose "dropme1 == $nm_output(dropme1)" + fail $test1 + } else { + if {[info exists nm_output(dropme2)]} { + send_log "dropme2 == $nm_output(dropme2)\n" + verbose "dropme2 == $nm_output(dropme2)" + fail $test1 + } else { + pass $test1 + } + } + } + } + +if { ![ld_compile "$CC $cflags" $srcdir/$subdir/2.c tmpdir/2.o]} { + unresolved $test2 + return +} + +if ![ld_simple_link $ld tmpdir/2.x "$ldflags tmpdir/2.o"] { + fail $test2 +} else { + if ![ld_nm $nm tmpdir/2.x] { + unresolved $test2 + } else { + if {[info exists nm_output(foo)] } { + send_log "foo == $nm_output(foo)\n" + verbose "foo== $nm_output(foo)" + fail $test2 + } else { + pass $test2 + } + } + } + +if { ![ld_compile "$CC $cflags" $srcdir/$subdir/2.c tmpdir/2.o]} { + unresolved $test3 + return +} + +if ![ld_simple_link $ld tmpdir/2.x "$ldflags -u foo tmpdir/2.o"] { + fail $test3 +} else { + if ![ld_nm $nm tmpdir/2.x] { + unresolved $test3 + } else { + if {![info exists nm_output(foo)] } { + send_log "bad output from nm\n" + verbose "bad output from nm" + fail $test3 + } else { + if {$nm_output(foo) == 0} { + send_log "foo == $nm_output(foo)\n" + verbose "foo== $nm_output(foo)" + fail $test3 + } else { + pass $test3 + } + } + } +} + +setup_xfail "v850*-*-elf" + +if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/3.cc tmpdir/3.o]} { + unresolved $test4 + return +} + +setup_xfail "v850*-*-elf" + +if ![ld_simple_link $ld tmpdir/3.x "$ldflags tmpdir/3.o"] { + fail $test4 +} else { + if ![ld_nm $nm tmpdir/3.x] { + unresolved $test4 + } else { + if {[info exists nm_output(foo__1B)]} { + send_log "foo__1B == $nm_output(foo__1B)\n" + verbose "foo__1B == $nm_output(foo__1B)" + fail $test4 + } else { + if {[ info exists nm_output(bar__1A)]} { + send_log "bar__1A== $nm_output(_bar__1A)\n" + verbose "bar__1A == $nm_output(_bar__1A)" + fail $test4 + } else { + pass $test4 + } + } + } +} + +if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/4.cc tmpdir/4.o]} { + unresolved $test5 + return +} + +if ![ld_simple_link $ld tmpdir/4.x "$ldflags tmpdir/4.o"] { + fail $test5 +} else { + if ![ld_nm $nm tmpdir/4.x] { + unresolved $test5 + } else { + if {[info exists nm_output(foo__1B)]} { + send_log "foo__1B == $nm_output(foo__1B)\n" + verbose "foo__1B == $nm_output(foo__1B)" + fail $test5 + } else { + if {[info exists nm_output(foo__1A)]} { + send_log "foo__1A== $nm_output(foo__1A)\n" + verbose "foo__1A == $nm_output(foo__1A)" + fail $test5 + } else { + pass $test5 + } + } + } +} + +setup_xfail "v850*-*-elf" + +if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/5.cc tmpdir/5.o]} { + unresolved $test6 + return +} + +if ![ld_simple_link $ld tmpdir/5.x "$ldflags tmpdir/5.o"] { + fail $test6 +} else { + if ![ld_nm $nm tmpdir/5.x] { + unresolved $test6 + } else { + if {[info exists nm_output(foo__1B)] } { + send_log "foo__1B == $nm_output(foo__1B)\n" + verbose "foo__1B == $nm_output(foo__1B)" + fail $test6 + } else { + if { [info exists nm_output(foo__1A)]} { + send_log "foo__1A== $nm_output(foo__1A)\n" + verbose "foo__1A == $nm_output(foo__1A)" + fail $test6 + } else { + pass $test6 + } + } + } +} |