diff --git a/gold/script-sections.cc b/gold/script-sections.cc index bf25391..f35ecc1 100644 --- a/gold/script-sections.cc +++ b/gold/script-sections.cc @@ -3538,6 +3538,7 @@ Script_sections::output_section_name( *output_section_slot = NULL; *psection_type = Script_sections::ST_NONE; + *keep = false; return section_name; } diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index f9f707e..2a7228b 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -220,6 +220,16 @@ pr14265: pr14265.o pr14265.stdout: pr14265 $(TEST_NM) --format=bsd --numeric-sort $< > $@ +check_SCRIPTS += pr20717.sh +check_DATA += pr20717.stdout +MOSTLYCLEANFILES += pr20717 +pr20717.o: pr20717.c + $(COMPILE) -O0 -ffunction-sections -c -o $@ $< +pr20717: pr20717.o gcctestdir/ld $(srcdir)/pr20717.t + $(LINK) -Bgcctestdir/ -Wl,--gc-sections -Wl,-T,$(srcdir)/pr20717.t -o $@ $< +pr20717.stdout: pr20717 + $(TEST_NM) $< > $@ + check_SCRIPTS += gc_dynamic_list_test.sh check_DATA += gc_dynamic_list_test.stdout MOSTLYCLEANFILES += gc_dynamic_list_test diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index a200540..a07fd22 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -76,7 +76,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = incremental_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_comdat_test.sh gc_tls_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr14265.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr14265.sh pr20717.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_dynamic_list_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.sh \ @@ -95,7 +95,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_comdat_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_tls_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr14265.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr14265.stdout pr20717.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_dynamic_list_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_test.map \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.stdout \ @@ -120,8 +120,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ incremental_test.cmdline \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_comdat_test gc_tls_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test pr14265 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_dynamic_list_test icf_test \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_test.map \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr20717 gc_dynamic_list_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_test icf_test.map \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test icf_safe_test.map \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test \ @@ -4989,6 +4989,8 @@ gc_orphan_section_test.sh.log: gc_orphan_section_test.sh @p='gc_orphan_section_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) pr14265.sh.log: pr14265.sh @p='pr14265.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +pr20717.sh.log: pr20717.sh + @p='pr20717.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) gc_dynamic_list_test.sh.log: gc_dynamic_list_test.sh @p='gc_dynamic_list_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) icf_test.sh.log: icf_test.sh @@ -5754,6 +5756,12 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,--gc-sections -Wl,-T,$(srcdir)/pr14265.t -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@pr14265.stdout: pr14265 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) --format=bsd --numeric-sort $< > $@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20717.o: pr20717.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -ffunction-sections -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20717: pr20717.o gcctestdir/ld $(srcdir)/pr20717.t +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,--gc-sections -Wl,-T,$(srcdir)/pr20717.t -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20717.stdout: pr20717 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) $< > $@ @GCC_TRUE@@NATIVE_LINKER_TRUE@gc_dynamic_list_test.o: gc_dynamic_list_test.c @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -ffunction-sections -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@gc_dynamic_list_test: gc_dynamic_list_test.o gcctestdir/ld $(srcdir)/gc_dynamic_list_test.t diff --git a/gold/testsuite/pr20717.c b/gold/testsuite/pr20717.c new file mode 100644 index 0000000..d571916 --- /dev/null +++ b/gold/testsuite/pr20717.c @@ -0,0 +1,3 @@ +void unused(void); +void unused(void) {} +int main(void) {return 0;} diff --git a/gold/testsuite/pr20717.sh b/gold/testsuite/pr20717.sh new file mode 100755 index 0000000..f7ab1a4 --- /dev/null +++ b/gold/testsuite/pr20717.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# pr20717.sh -- test --gc-sections for an unused orphan section +# when the last section in the linker script has a KEEP statement. + +# Copyright (C) 2016 Free Software Foundation, Inc. +# Written by Igor Kudrin + +# This file is part of gold. + +# 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. + + +check() +{ + file=$1 + pattern=$2 + if grep -q "$pattern" "$file" + then + echo "Garbage collection failed to collect :" + echo " $pattern" + exit 1 + fi +} + +check pr20717.stdout "unused" + diff --git a/gold/testsuite/pr20717.t b/gold/testsuite/pr20717.t new file mode 100644 index 0000000..ddb3500 --- /dev/null +++ b/gold/testsuite/pr20717.t @@ -0,0 +1,4 @@ +SECTIONS +{ + .dummy : { KEEP (*(.dummy)) } +}