aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-gc
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2008-01-11 09:11:18 +0000
committerTristan Gingold <gingold@adacore.com>2008-01-11 09:11:18 +0000
commitac69cbc672a0702152d34bac2da436dcee2e5346 (patch)
tree6ffc8a7b8272f96af39210413806e543b28c186b /ld/testsuite/ld-gc
parent7dda2462a7035e0c9cc9706abfda31861c551b14 (diff)
downloadgdb-ac69cbc672a0702152d34bac2da436dcee2e5346.zip
gdb-ac69cbc672a0702152d34bac2da436dcee2e5346.tar.gz
gdb-ac69cbc672a0702152d34bac2da436dcee2e5346.tar.bz2
ld:
2008-01-11 Tristan Gingold <gingold@adacore.com> Eric Botcazou <ebotcazou@adacore.com> * ldlang.c (lang_end): Warns if the entry point is not found when --gc-sections. Emit an error if no root is specified when --gc-sections -r. * ld.texinfo (Options): Document that --gc-sections is compatible with -r and -q. * ldmain.c (main): Do not error out if -r and --gc-sections. * scripttempl/elf.sc: Emit ENTRY command only if relocating. ld/testsuite: 2008-01-11 Tristan Gingold <gingold@adacore.com> * lib/ld-lib.exp (check_gc_sections_available): Now available on VxWorks. * ld-gc: New directory for testing --gc-sections. * ld-gc/gc.c: New file. * ld-gc/gc.exp: New file. * ld-gc/noent.s: New file. * ld-gc/noent.d: New file.
Diffstat (limited to 'ld/testsuite/ld-gc')
-rw-r--r--ld/testsuite/ld-gc/gc.c20
-rw-r--r--ld/testsuite/ld-gc/gc.exp71
-rw-r--r--ld/testsuite/ld-gc/noent.d3
-rw-r--r--ld/testsuite/ld-gc/noent.s4
4 files changed, 98 insertions, 0 deletions
diff --git a/ld/testsuite/ld-gc/gc.c b/ld/testsuite/ld-gc/gc.c
new file mode 100644
index 0000000..c662f72
--- /dev/null
+++ b/ld/testsuite/ld-gc/gc.c
@@ -0,0 +1,20 @@
+int unused_var = 7;
+int used_var = 7;
+
+int
+unused_func (int v)
+{
+ return 3 * unused_var;
+}
+
+int
+used_func (int v)
+{
+ return 2 * used_var;
+}
+
+int
+main (void)
+{
+ return used_func (5);
+}
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
new file mode 100644
index 0000000..68a0ba1
--- /dev/null
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -0,0 +1,71 @@
+# Expect script for ld-gc tests
+# Copyright 2008
+# 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.
+
+# These tests require --gc-sections
+if ![check_gc_sections_available] {
+ return
+}
+
+set cflags "-ffunction-sections -fdata-sections"
+set objfile "tmpdir/gc.o"
+
+ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/gc.c $objfile
+
+proc test_gc { testname filename linker ldflags} {
+ global nm
+ global srcdir
+ global subdir
+ global nm_output
+ global objfile
+
+ set outfile "tmpdir/$filename"
+
+ if ![ld_simple_link $linker $outfile "-L$srcdir/$subdir $ldflags $objfile"] {
+ fail $testname
+ return
+ }
+ if ![ld_nm $nm "" $outfile] {
+ unresolved $testname
+ return
+ }
+ if {![info exists nm_output(used_func)] \
+ || ![info exists nm_output(used_var)]} {
+ send_log "used sections do not exist\n"
+ verbose "used sections do not exist"
+ fail $testname
+ return
+ }
+ if {[info exists nm_output(unused_func)] \
+ || [info exists nm_output(unused_var)]} {
+ send_log "unused section still here\n"
+ verbose "unused section still here"
+ fail $testname
+ return
+ }
+ pass $testname
+}
+
+test_gc "Check --gc-section" "gcexe" $ld "--gc-sections -e main"
+test_gc "Check --gc-section/-q" "gcrexe" $ld "--gc-sections -q -e main"
+test_gc "Check --gc-section/-r/-e" "gcrel" $ld "-r --gc-sections -e main"
+test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
+
+run_dump_test "noent"
diff --git a/ld/testsuite/ld-gc/noent.d b/ld/testsuite/ld-gc/noent.d
new file mode 100644
index 0000000..1741a74
--- /dev/null
+++ b/ld/testsuite/ld-gc/noent.d
@@ -0,0 +1,3 @@
+# name: --gc-sections -r without -e
+# ld: --gc-sections -r
+# error: gc-sections requires either an entry or an undefined symbol
diff --git a/ld/testsuite/ld-gc/noent.s b/ld/testsuite/ld-gc/noent.s
new file mode 100644
index 0000000..ea74bf4
--- /dev/null
+++ b/ld/testsuite/ld-gc/noent.s
@@ -0,0 +1,4 @@
+ .text
+ .globl entry
+entry:
+ .long 0