aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ld/ChangeLog11
-rw-r--r--ld/genscrba.sh6
-rw-r--r--ld/ld.texinfo8
-rw-r--r--ld/ldlang.c11
-rw-r--r--ld/ldmain.c4
-rw-r--r--ld/scripttempl/elf.sc2
-rw-r--r--ld/testsuite/ChangeLog10
-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
-rw-r--r--ld/testsuite/lib/ld-lib.exp8
12 files changed, 141 insertions, 17 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9ef8fb7..372422d 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,14 @@
+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.
+
2008-01-10 Daniel Jacobowitz <drow@sources.redhat.com>
PR ld/5533
diff --git a/ld/genscrba.sh b/ld/genscrba.sh
index 621de7a..030cb7d 100644
--- a/ld/genscrba.sh
+++ b/ld/genscrba.sh
@@ -8,7 +8,9 @@ source_em()
}
fragment()
{
- local lineno=$[${BASH_LINENO[0]} + 1]
- echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
+ if [ ${BASH_VERSINFO[3]} -ge 3 ]; then
+ local lineno=$[${BASH_LINENO[0]} + 1]
+ echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
+ fi
cat >> e${EMULATION_NAME}.c
}
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 7cbc26a..7d77d1c 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1280,8 +1280,7 @@ it ends in a @code{.exe} suffix.
@item --gc-sections
@itemx --no-gc-sections
Enable garbage collection of unused input sections. It is ignored on
-targets that do not support this option. This option is not compatible
-with @samp{-r} or @samp{--emit-relocs}. The default behaviour (of not
+targets that do not support this option. The default behaviour (of not
performing this garbage collection) can be restored by specifying
@samp{--no-gc-sections} on the command line.
@@ -1295,6 +1294,11 @@ referenced. Once this initial set of sections has been determined,
the linker recursively marks as used any section referenced by their
relocations. See @samp{--entry} and @samp{--undefined}.
+This option can be set when doing a partial link (enabled with option
+@samp{-r}). In this case the root of symbols kept must be explicitely
+specified either by an @samp{--entry} or @samp{--undefined} option or by
+a @code{ENTRY} command in the linker script.
+
@kindex --print-gc-sections
@kindex --no-print-gc-sections
@cindex garbage collection
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 9d3c513..63326e5 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5077,11 +5077,20 @@ lang_end (void)
struct bfd_link_hash_entry *h;
bfd_boolean warn;
- if (link_info.relocatable || link_info.shared)
+ if ((link_info.relocatable && !link_info.gc_sections)
+ || link_info.shared)
warn = entry_from_cmdline;
else
warn = TRUE;
+ /* Force the user to specify a root when generating a relocatable with
+ --gc-sections. */
+ if (link_info.gc_sections && link_info.relocatable
+ && (entry_symbol.name == NULL
+ && ldlang_undef_chain_list_head == NULL))
+ einfo (_("%P%F: gc-sections requires either an entry or "
+ "an undefined symbol\n"));
+
if (entry_symbol.name == NULL)
{
/* No entry has been specified. Look for the default entry, but
diff --git a/ld/ldmain.c b/ld/ldmain.c
index f1112cf..29f00d6 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -292,9 +292,7 @@ main (int argc, char **argv)
if (link_info.relocatable)
{
- if (link_info.gc_sections)
- einfo ("%P%F: --gc-sections and -r may not be used together\n");
- else if (command_line.relax)
+ if (command_line.relax)
einfo (_("%P%F: --relax and -r may not be used together\n"));
if (link_info.shared)
einfo (_("%P%F: -r and -shared may not be used together\n"));
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index 2f86d91..5c35e4f 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -250,7 +250,7 @@ cat <<EOF
OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
"${LITTLE_OUTPUT_FORMAT}")
OUTPUT_ARCH(${OUTPUT_ARCH})
-ENTRY(${ENTRY})
+${RELOCATING+ENTRY(${ENTRY})}
${RELOCATING+${LIB_SEARCH_DIRS}}
${RELOCATING+${EXECUTABLE_SYMBOLS}}
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 1eff242..c11355c 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2008-01-10 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.
+
2008-01-09 Richard Sandiford <rsandifo@nildram.co.uk>
PR ld/5526
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
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index f326478..4e8903c 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1559,14 +1559,6 @@ proc check_gc_sections_available { } {
return 0
}
- # VxWorks kernel modules are relocatable objects linked with -r,
- # while RTP executables are linked with -q (--emit-relocs).
- # Both of these options are incompatible with --gc-sections.
- if { [istarget *-*-vxworks*] } {
- set gc_sections_available_saved 0
- return 0
- }
-
# Check if the ld used by gcc supports --gc-sections.
set ld_output [remote_exec host $ld "--help"]
if { [ string first "--gc-sections" $ld_output ] >= 0 } {