2010-05-26 Rafael Espindola <espindola@google.com>
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Wed, 26 May 2010 15:47:39 +0000 (15:47 +0000)
committerRafael Ávila de Espíndola <respindola@mozilla.com>
Wed, 26 May 2010 15:47:39 +0000 (15:47 +0000)
       PR 11604
* gold/object.cc(Sized_relobj::do_layout_deferred_sections): Avoid
adding sections the garbage collector removed.
* gold/testsuite/Makefile.am: Add test.
* gold/testsuite/Makefile.in: Regenerate.
* gold/testsuite/plugin_test_7.sh: New.
* gold/testsuite/plugin_test_7_1.c: New.
* gold/testsuite/plugin_test_7_2.c: New.

gold/ChangeLog
gold/object.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/plugin_test_7.sh [new file with mode: 0755]
gold/testsuite/plugin_test_7_1.c [new file with mode: 0644]
gold/testsuite/plugin_test_7_2.c [new file with mode: 0644]

index 899170d14e7d5f51e23c5c70a247133704f50068..3dba1975d7829b3b1c418602932835196a1e0187 100644 (file)
@@ -1,3 +1,14 @@
+2010-05-26  Rafael Espindola  <espindola@google.com>
+
+       PR 11604
+       * gold/object.cc(Sized_relobj::do_layout_deferred_sections): Avoid
+       adding sections the garbage collector removed.
+       * gold/testsuite/Makefile.am: Add test.
+       * gold/testsuite/Makefile.in: Regenerate.
+       * gold/testsuite/plugin_test_7.sh: New.
+       * gold/testsuite/plugin_test_7_1.c: New.
+       * gold/testsuite/plugin_test_7_2.c: New.
+
 2010-05-26  Rafael Espindola  <espindola@google.com>
 
        * script-sections.cc (Output_section_definition::set_section_addresses):
index 8751d550f1f2845fa8dfa001ffc8951aa94754bd..9581fd8774daef1a7190b2fa695ada09b0d01438 100644 (file)
@@ -1461,6 +1461,11 @@ Sized_relobj<size, big_endian>::do_layout_deferred_sections(Layout* layout)
        ++deferred)
     {
       typename This::Shdr shdr(deferred->shdr_data_);
+      // If the section is not included, it is because the garbage collector
+      // decided it is not needed.  Avoid reverting that decision.
+      if (!this->is_section_included(deferred->shndx_))
+        continue;
+
       this->layout_section(layout, deferred->shndx_, deferred->name_.c_str(),
                            shdr, deferred->reloc_shndx_, deferred->reloc_type_);
     }
index 4cd69ac4bf074d3ea1e865e3c82c1de533e53361..afb704d15544120364dacf78ff6212847cdfeb89 100644 (file)
@@ -1284,6 +1284,24 @@ plugin_test_6: plugin_common_test_1.syms plugin_common_test_2.syms gcctestdir/ld
 plugin_test_6.err: plugin_test_6
        @touch plugin_test_6.err
 
+check_PROGRAMS += plugin_test_7
+check_SCRIPTS += plugin_test_7.sh
+check_DATA += plugin_test_7.err plugin_test_7.syms
+MOSTLYCLEANFILES += plugin_test_7.err
+plugin_test_7: plugin_test_7_1.o plugin_test_7_1.syms plugin_test_7_2.o gcctestdir/ld plugin_test.so
+       $(LINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--gc-sections,--print-gc-sections plugin_test_7_1.syms plugin_test_7_2.o 2>plugin_test_7.err
+plugin_test_7.syms: plugin_test_7
+       $(TEST_READELF) -sW $< >$@ 2>/dev/null
+plugin_test_7_1.o: plugin_test_7_1.c
+       $(COMPILE) -DLTO -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+plugin_test_7_1_orig.o: plugin_test_7_1.c
+       $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+plugin_test_7_1.syms: plugin_test_7_1_orig.o
+       $(TEST_READELF) -sW $< >$@ 2>/dev/null
+plugin_test_7_2.o: plugin_test_7_2.c
+       $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+plugin_test_7.err: plugin_test_7
+
 plugin_test.so: plugin_test.o
        $(LINK) -Bgcctestdir/ -shared plugin_test.o
 plugin_test.o: plugin_test.c
index d5aec9070d865746823e1be001bd087e555728c9..4470580f1162e237ec5d74ada23fe0280ee40a47 100644 (file)
@@ -253,19 +253,23 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_3 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_5 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_23 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_1.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_2.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_3.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7.sh
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_24 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_1.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_2.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_3.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4.err \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7.syms
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_25 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_1.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_2.err \
@@ -273,6 +277,7 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   unused.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = exclude_libs_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test \
@@ -490,7 +495,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_3$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_4$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_5$(EXEEXT) \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_6$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   plugin_test_7$(EXEEXT)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_17 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ exclude_libs_test$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test$(EXEEXT) \
@@ -742,6 +748,12 @@ plugin_test_6_LDADD = $(LDADD)
 plugin_test_6_DEPENDENCIES = libgoldtest.a ../libgold.a \
        ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+plugin_test_7_SOURCES = plugin_test_7.c
+plugin_test_7_OBJECTS = plugin_test_7.$(OBJEXT)
+plugin_test_7_LDADD = $(LDADD)
+plugin_test_7_DEPENDENCIES = libgoldtest.a ../libgold.a \
+       ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+       $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am_protected_1_OBJECTS =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_1.$(OBJEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_2.$(OBJEXT) \
@@ -1104,12 +1116,12 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
        many_sections_r_test.c $(many_sections_test_SOURCES) \
        $(object_unittest_SOURCES) permission_test.c plugin_test_1.c \
        plugin_test_2.c plugin_test_3.c plugin_test_4.c \
-       plugin_test_5.c plugin_test_6.c $(protected_1_SOURCES) \
-       $(protected_2_SOURCES) $(relro_script_test_SOURCES) \
-       $(relro_test_SOURCES) $(script_test_1_SOURCES) \
-       $(script_test_2_SOURCES) script_test_3.c \
-       $(searched_file_test_SOURCES) $(thin_archive_test_1_SOURCES) \
-       $(thin_archive_test_2_SOURCES) \
+       plugin_test_5.c plugin_test_6.c plugin_test_7.c \
+       $(protected_1_SOURCES) $(protected_2_SOURCES) \
+       $(relro_script_test_SOURCES) $(relro_test_SOURCES) \
+       $(script_test_1_SOURCES) $(script_test_2_SOURCES) \
+       script_test_3.c $(searched_file_test_SOURCES) \
+       $(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \
        $(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \
        tls_pie_pic_test.c tls_pie_test.c $(tls_script_test_SOURCES) \
        $(tls_shared_gd_to_ie_test_SOURCES) \
@@ -1934,6 +1946,15 @@ object_unittest$(EXEEXT): $(object_unittest_OBJECTS) $(object_unittest_DEPENDENC
 @PLUGINS_FALSE@plugin_test_6$(EXEEXT): $(plugin_test_6_OBJECTS) $(plugin_test_6_DEPENDENCIES) 
 @PLUGINS_FALSE@        @rm -f plugin_test_6$(EXEEXT)
 @PLUGINS_FALSE@        $(LINK) $(plugin_test_6_OBJECTS) $(plugin_test_6_LDADD) $(LIBS)
+@GCC_FALSE@plugin_test_7$(EXEEXT): $(plugin_test_7_OBJECTS) $(plugin_test_7_DEPENDENCIES) 
+@GCC_FALSE@    @rm -f plugin_test_7$(EXEEXT)
+@GCC_FALSE@    $(LINK) $(plugin_test_7_OBJECTS) $(plugin_test_7_LDADD) $(LIBS)
+@NATIVE_LINKER_FALSE@plugin_test_7$(EXEEXT): $(plugin_test_7_OBJECTS) $(plugin_test_7_DEPENDENCIES) 
+@NATIVE_LINKER_FALSE@  @rm -f plugin_test_7$(EXEEXT)
+@NATIVE_LINKER_FALSE@  $(LINK) $(plugin_test_7_OBJECTS) $(plugin_test_7_LDADD) $(LIBS)
+@PLUGINS_FALSE@plugin_test_7$(EXEEXT): $(plugin_test_7_OBJECTS) $(plugin_test_7_DEPENDENCIES) 
+@PLUGINS_FALSE@        @rm -f plugin_test_7$(EXEEXT)
+@PLUGINS_FALSE@        $(LINK) $(plugin_test_7_OBJECTS) $(plugin_test_7_LDADD) $(LIBS)
 protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES) 
        @rm -f protected_1$(EXEEXT)
        $(protected_1_LINK) $(protected_1_OBJECTS) $(protected_1_LDADD) $(LIBS)
@@ -2166,6 +2187,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_4.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_5.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_6.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_7.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_3.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@
@@ -3030,6 +3052,19 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so" plugin_common_test_1.syms plugin_common_test_2.syms 2>plugin_test_6.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_6.err: plugin_test_6
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   @touch plugin_test_6.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7: plugin_test_7_1.o plugin_test_7_1.syms plugin_test_7_2.o gcctestdir/ld plugin_test.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(LINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--gc-sections,--print-gc-sections plugin_test_7_1.syms plugin_test_7_2.o 2>plugin_test_7.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7.syms: plugin_test_7
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7_1.o: plugin_test_7_1.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(COMPILE) -DLTO -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7_1_orig.o: plugin_test_7_1.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7_1.syms: plugin_test_7_1_orig.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(TEST_READELF) -sW $< >$@ 2>/dev/null
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7_2.o: plugin_test_7_2.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7.err: plugin_test_7
 
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test.so: plugin_test.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@   $(LINK) -Bgcctestdir/ -shared plugin_test.o
diff --git a/gold/testsuite/plugin_test_7.sh b/gold/testsuite/plugin_test_7.sh
new file mode 100755 (executable)
index 0000000..27723f9
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# plugin_test_7.sh -- a test case for the plugin API with GC.
+
+# Copyright 2010 Free Software Foundation, Inc.
+# Written by Rafael Avila de Espindola <espindola@google.com>.
+
+# 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()
+{
+    if ! grep -q "$2" "$1"
+    then
+       echo "Did not find expected output in $1:"
+       echo "   $2"
+       echo ""
+       echo "Actual output below:"
+       cat "$1"
+       exit 1
+    fi
+}
+
+check_not()
+{
+    if grep -q "$2" "$1"
+    then
+       echo "Found unexpected output in $1:"
+       echo "   $2"
+       echo ""
+       echo "Actual output below:"
+       cat "$1"
+       exit 1
+    fi
+}
+
+
+check plugin_test_7.err "set_x: PREVAILING_DEF_IRONLY"
+check plugin_test_7.err "fun2: RESOLVED_EXEC"
+check plugin_test_7.err "fun1: PREVAILING_DEF_REG"
+check plugin_test_7.err "removing unused section from '.text.fun2' in file 'plugin_test_7_2.o'"
+check_not plugin_test_7.syms "fun2"
diff --git a/gold/testsuite/plugin_test_7_1.c b/gold/testsuite/plugin_test_7_1.c
new file mode 100644 (file)
index 0000000..5f4c4f3
--- /dev/null
@@ -0,0 +1,43 @@
+/* plugin_test_7_1.c -- a test case for the plugin API with GC.
+
+   Copyright 2010 Free Software Foundation, Inc.
+   Written by Rafael Avila de Espindola <espindola@google.com>.
+
+   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.  */
+
+int fun1(void);
+int fun2(void);
+void set_x(int y);
+
+#ifndef LTO
+static int x = 0;
+
+void set_x(int y)
+{
+  x = y;
+}
+#endif
+
+int fun1(void)
+{
+#ifndef LTO
+  if (x)
+    return fun2();
+#endif
+  return 0;
+}
diff --git a/gold/testsuite/plugin_test_7_2.c b/gold/testsuite/plugin_test_7_2.c
new file mode 100644 (file)
index 0000000..06b7676
--- /dev/null
@@ -0,0 +1,33 @@
+/* plugin_test_7_1.c -- a test case for the plugin API with GC.
+
+   Copyright 2010 Free Software Foundation, Inc.
+   Written by Rafael Avila de Espindola <espindola@google.com>.
+
+   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.  */
+
+int fun1(void);
+void fun2(void);
+
+void fun2(void)
+{
+}
+
+int main(void)
+{
+  return fun1();
+}