[patch][gold] Fix PR11604
Rafael Espindola
espindola@google.com
Mon May 24 02:41:00 GMT 2010
With the attached patch gold can, with the llvm plugin, pass the test in
http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html
The last remaining issue was that the delayed layout would add back a
section the garbage collector decided was not needed.
I have ported the test to use the test plugin by checking in the original
.syms file but a .c file that reflects what LTO can do with it.
2010-05-23 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_1.syms: New.
* gold/testsuite/plugin_test_7_2.c: New.
Cheers,
--
Rafael Ávila de Espíndola
-------------- next part --------------
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..1928fbf 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1284,6 +1284,21 @@ 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 $(srcdir)/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) -O0 -c -ffunction-sections -fdata-sections -o $@ $<
+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..d529e57
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_1.c
@@ -0,0 +1,28 @@
+// Test from http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html
+
+// Comments simulate what LTO can do with this file. The .syms file contains
+// what the symbols looked like before LTO.
+
+extern int foo1(void);
+extern void foo2(void);
+extern void foo4(void);
+
+//static signed int i = 0;
+
+//void foo2(void) {
+// i = -1;
+//}
+
+//static int foo3(void) {
+// foo4();
+// return 10;
+//}
+
+int foo1(void) {
+ int data = 0;
+
+// if (i < 0) { data = foo3(); }
+
+ data = data + 42;
+ return data;
+}
diff --git a/gold/testsuite/plugin_test_7_1.syms b/gold/testsuite/plugin_test_7_1.syms
new file mode 100644
index 0000000..6743e50
--- /dev/null
+++ b/gold/testsuite/plugin_test_7_1.syms
@@ -0,0 +1,28 @@
+
+Symbol table '.symtab' contains 25 entries:
+ Num: Value Size Type Bind Vis Ndx Name
+ 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+ 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS plugin_test_7_1.c
+ 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1
+ 3: 0000000000000000 0 SECTION LOCAL DEFAULT 2
+ 4: 0000000000000000 0 SECTION LOCAL DEFAULT 3
+ 5: 0000000000000000 0 SECTION LOCAL DEFAULT 4
+ 6: 0000000000000000 0 SECTION LOCAL DEFAULT 5
+ 7: 0000000000000000 0 SECTION LOCAL DEFAULT 7
+ 8: 0000000000000000 0 SECTION LOCAL DEFAULT 9
+ 9: 0000000000000000 4 OBJECT LOCAL DEFAULT 9 i
+ 10: 0000000000000000 0 SECTION LOCAL DEFAULT 10
+ 11: 0000000000000000 0 SECTION LOCAL DEFAULT 12
+ 12: 0000000000000000 16 FUNC LOCAL DEFAULT 12 foo3
+ 13: 0000000000000000 0 SECTION LOCAL DEFAULT 14
+ 14: 0000000000000000 0 SECTION LOCAL DEFAULT 16
+ 15: 0000000000000000 0 SECTION LOCAL DEFAULT 18
+ 16: 0000000000000000 0 SECTION LOCAL DEFAULT 20
+ 17: 0000000000000000 0 SECTION LOCAL DEFAULT 22
+ 18: 0000000000000000 0 SECTION LOCAL DEFAULT 24
+ 19: 0000000000000000 0 SECTION LOCAL DEFAULT 26
+ 20: 0000000000000000 0 SECTION LOCAL DEFAULT 27
+ 21: 0000000000000000 0 SECTION LOCAL DEFAULT 25
+ 22: 0000000000000000 16 FUNC GLOBAL DEFAULT 10 foo2
+ 23: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND foo4
+ 24: 0000000000000000 42 FUNC GLOBAL DEFAULT 14 foo1
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;
+}
More information about the Binutils
mailing list