This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch][gold] Fix PR11604
> I think that would be better. I'm just worried about what would happen
> if checking in raw .syms files becomes a regular practice. If the
> readelf output format changes, we'd have to regenerate all the
> checked-in .syms files; if we avoid checking in .syms files, we'd have
> only one thing to change (parse_readelf_line in plugin_test.c).
Sure, np.
An updated patch is attached.
2010-05-25 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.
> -cary
>
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..eb72090
--- /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 "foo2: PREVAILING_DEF_IRONLY"
+check plugin_test_7.err "foo4: RESOLVED_EXEC"
+check plugin_test_7.err "foo1: PREVAILING_DEF_REG"
+check plugin_test_7.err "removing unused section from '.text.foo4' in file 'plugin_test_7_2.o'"
+check_not plugin_test_7.syms "foo4"
diff --git a/gold/testsuite/plugin_test_7_1.c b/gold/testsuite/plugin_test_7_1.c
new file mode 100644
index 0000000..178c59f
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_1.c
@@ -0,0 +1,29 @@
+// Test from http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html
+
+extern int foo1(void);
+extern void foo2(void);
+extern void foo4(void);
+
+#ifndef LTO
+static signed int i = 0;
+
+void foo2(void) {
+ i = -1;
+}
+
+static int foo3(void) {
+ foo4();
+ return 10;
+}
+#endif
+
+int foo1(void) {
+ int data = 0;
+
+#ifndef LTO
+ if (i < 0) { data = foo3(); }
+#endif
+
+ data = data + 42;
+ return data;
+}
diff --git a/gold/testsuite/plugin_test_7_2.c b/gold/testsuite/plugin_test_7_2.c
new file mode 100644
index 0000000..8ecdb74
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_2.c
@@ -0,0 +1,17 @@
+// Test from http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html
+
+#include <stdio.h>
+
+extern int foo1(void);
+/* extern void foo2(void); */
+extern void foo4(void);
+
+void foo4(void) {
+ printf ("Hi\n");
+}
+
+int main(void) {
+ if (foo1() == 42)
+ return 0;
+ return 1;
+}