This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch][gold] Fix PR11604
> Sure, np.
>
> An updated patch is attached.
Ian asked me to write a new set of tests, A new patch is attached.
Same ChangeLog as before.
Cheers,
--
Rafael Ãvila de EspÃndola
diff --git a/gold/object.cc b/gold/object.cc
index 8751d55..9920268 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -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 output sections is NULL, it is because the garbage collector
+ // decided it is not needed. Avoid reverting that decision.
+ if (this->output_sections()[deferred->shndx_] == NULL)
+ continue;
+
this->layout_section(layout, deferred->shndx_, deferred->name_.c_str(),
shdr, deferred->reloc_shndx_, deferred->reloc_type_);
}
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 4cd69ac..0f859ac 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1284,6 +1284,25 @@ 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
+ @touch plugin_test_7.err
+
plugin_test.so: plugin_test.o
$(LINK) -Bgcctestdir/ -shared plugin_test.o
plugin_test.o: plugin_test.c
diff --git a/gold/testsuite/plugin_test_7.sh b/gold/testsuite/plugin_test_7.sh
new file mode 100755
index 0000000..27723f9
--- /dev/null
+++ b/gold/testsuite/plugin_test_7.sh
@@ -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
index 0000000..5f4c4f3
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_1.c
@@ -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
index 0000000..06b7676
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_2.c
@@ -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();
+}