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.
This commit is contained in:
parent
7dda2462a7
commit
ac69cbc672
11
ld/ChangeLog
11
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>
|
2008-01-10 Daniel Jacobowitz <drow@sources.redhat.com>
|
||||||
|
|
||||||
PR ld/5533
|
PR ld/5533
|
||||||
|
@ -8,7 +8,9 @@ source_em()
|
|||||||
}
|
}
|
||||||
fragment()
|
fragment()
|
||||||
{
|
{
|
||||||
local lineno=$[${BASH_LINENO[0]} + 1]
|
if [ ${BASH_VERSINFO[3]} -ge 3 ]; then
|
||||||
echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
|
local lineno=$[${BASH_LINENO[0]} + 1]
|
||||||
|
echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
|
||||||
|
fi
|
||||||
cat >> e${EMULATION_NAME}.c
|
cat >> e${EMULATION_NAME}.c
|
||||||
}
|
}
|
||||||
|
@ -1280,8 +1280,7 @@ it ends in a @code{.exe} suffix.
|
|||||||
@item --gc-sections
|
@item --gc-sections
|
||||||
@itemx --no-gc-sections
|
@itemx --no-gc-sections
|
||||||
Enable garbage collection of unused input sections. It is ignored on
|
Enable garbage collection of unused input sections. It is ignored on
|
||||||
targets that do not support this option. This option is not compatible
|
targets that do not support this option. The default behaviour (of not
|
||||||
with @samp{-r} or @samp{--emit-relocs}. The default behaviour (of not
|
|
||||||
performing this garbage collection) can be restored by specifying
|
performing this garbage collection) can be restored by specifying
|
||||||
@samp{--no-gc-sections} on the command line.
|
@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
|
the linker recursively marks as used any section referenced by their
|
||||||
relocations. See @samp{--entry} and @samp{--undefined}.
|
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 --print-gc-sections
|
||||||
@kindex --no-print-gc-sections
|
@kindex --no-print-gc-sections
|
||||||
@cindex garbage collection
|
@cindex garbage collection
|
||||||
|
11
ld/ldlang.c
11
ld/ldlang.c
@ -5077,11 +5077,20 @@ lang_end (void)
|
|||||||
struct bfd_link_hash_entry *h;
|
struct bfd_link_hash_entry *h;
|
||||||
bfd_boolean warn;
|
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;
|
warn = entry_from_cmdline;
|
||||||
else
|
else
|
||||||
warn = TRUE;
|
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)
|
if (entry_symbol.name == NULL)
|
||||||
{
|
{
|
||||||
/* No entry has been specified. Look for the default entry, but
|
/* No entry has been specified. Look for the default entry, but
|
||||||
|
@ -292,9 +292,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
if (link_info.relocatable)
|
if (link_info.relocatable)
|
||||||
{
|
{
|
||||||
if (link_info.gc_sections)
|
if (command_line.relax)
|
||||||
einfo ("%P%F: --gc-sections and -r may not be used together\n");
|
|
||||||
else if (command_line.relax)
|
|
||||||
einfo (_("%P%F: --relax and -r may not be used together\n"));
|
einfo (_("%P%F: --relax and -r may not be used together\n"));
|
||||||
if (link_info.shared)
|
if (link_info.shared)
|
||||||
einfo (_("%P%F: -r and -shared may not be used together\n"));
|
einfo (_("%P%F: -r and -shared may not be used together\n"));
|
||||||
|
@ -250,7 +250,7 @@ cat <<EOF
|
|||||||
OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
|
OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
|
||||||
"${LITTLE_OUTPUT_FORMAT}")
|
"${LITTLE_OUTPUT_FORMAT}")
|
||||||
OUTPUT_ARCH(${OUTPUT_ARCH})
|
OUTPUT_ARCH(${OUTPUT_ARCH})
|
||||||
ENTRY(${ENTRY})
|
${RELOCATING+ENTRY(${ENTRY})}
|
||||||
|
|
||||||
${RELOCATING+${LIB_SEARCH_DIRS}}
|
${RELOCATING+${LIB_SEARCH_DIRS}}
|
||||||
${RELOCATING+${EXECUTABLE_SYMBOLS}}
|
${RELOCATING+${EXECUTABLE_SYMBOLS}}
|
||||||
|
@ -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>
|
2008-01-09 Richard Sandiford <rsandifo@nildram.co.uk>
|
||||||
|
|
||||||
PR ld/5526
|
PR ld/5526
|
||||||
|
20
ld/testsuite/ld-gc/gc.c
Normal file
20
ld/testsuite/ld-gc/gc.c
Normal file
@ -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);
|
||||||
|
}
|
71
ld/testsuite/ld-gc/gc.exp
Normal file
71
ld/testsuite/ld-gc/gc.exp
Normal file
@ -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"
|
3
ld/testsuite/ld-gc/noent.d
Normal file
3
ld/testsuite/ld-gc/noent.d
Normal file
@ -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
|
4
ld/testsuite/ld-gc/noent.s
Normal file
4
ld/testsuite/ld-gc/noent.s
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.text
|
||||||
|
.globl entry
|
||||||
|
entry:
|
||||||
|
.long 0
|
@ -1559,14 +1559,6 @@ proc check_gc_sections_available { } {
|
|||||||
return 0
|
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.
|
# Check if the ld used by gcc supports --gc-sections.
|
||||||
set ld_output [remote_exec host $ld "--help"]
|
set ld_output [remote_exec host $ld "--help"]
|
||||||
if { [ string first "--gc-sections" $ld_output ] >= 0 } {
|
if { [ string first "--gc-sections" $ld_output ] >= 0 } {
|
||||||
|
Loading…
Reference in New Issue
Block a user