public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch][gold] Fix PR11604
@ 2010-05-24  2:41 Rafael Espindola
  2010-05-24 19:04 ` Cary Coutant
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael Espindola @ 2010-05-24  2:41 UTC (permalink / raw)
  To: Binutils; +Cc: Sriraman Tallam, Ian Lance Taylor, Cary Coutant

[-- Attachment #1: Type: text/plain, Size: 899 bytes --]

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

[-- Attachment #2: gc-plugin.patch --]
[-- Type: text/plain, Size: 6787 bytes --]

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;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-24  2:41 [patch][gold] Fix PR11604 Rafael Espindola
@ 2010-05-24 19:04 ` Cary Coutant
  2010-05-24 21:59   ` Rafael Espindola
  0 siblings, 1 reply; 7+ messages in thread
From: Cary Coutant @ 2010-05-24 19:04 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: Binutils, Sriraman Tallam, Ian Lance Taylor

> 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.

The fix to Sized_relobj::do_layout_deferred_sections looks good to me (thanks!).

In the test case, plugin_test_7_1.syms should be derived automatically
from plugin_test_7_1.o, rather than checked in as a source file.

-cary

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-24 19:04 ` Cary Coutant
@ 2010-05-24 21:59   ` Rafael Espindola
  2010-05-25  0:06     ` Cary Coutant
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael Espindola @ 2010-05-24 21:59 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Binutils, Sriraman Tallam, Ian Lance Taylor

> In the test case, plugin_test_7_1.syms should be derived automatically
> from plugin_test_7_1.o, rather than checked in as a source file.

So, I added it as a source, because it is *not* what you will get if
you run readelf on the .o. The idea of the test is to simulate what
LTO can do. The .syms file corresponds to what the original file
looked like. The .c file corresponds to what optimizations LTO can do.

I could check two .c files if you prefer.

> -cary
>

Cheers,
-- 
Rafael Ávila de Espíndola

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-24 21:59   ` Rafael Espindola
@ 2010-05-25  0:06     ` Cary Coutant
  2010-05-25 14:17       ` Rafael Espindola
  0 siblings, 1 reply; 7+ messages in thread
From: Cary Coutant @ 2010-05-25  0:06 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: Binutils, Sriraman Tallam, Ian Lance Taylor

>> In the test case, plugin_test_7_1.syms should be derived automatically
>> from plugin_test_7_1.o, rather than checked in as a source file.
>
> So, I added it as a source, because it is *not* what you will get if
> you run readelf on the .o. The idea of the test is to simulate what
> LTO can do. The .syms file corresponds to what the original file
> looked like. The .c file corresponds to what optimizations LTO can do.

Oh, right. Sorry, I glossed right over those comments.

> I could check two .c files if you prefer.

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).

-cary

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-25  0:06     ` Cary Coutant
@ 2010-05-25 14:17       ` Rafael Espindola
  2010-05-25 17:54         ` Rafael Espindola
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael Espindola @ 2010-05-25 14:17 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Binutils, Sriraman Tallam, Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

> 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

[-- Attachment #2: gc-plugin.patch --]
[-- Type: text/x-diff, Size: 5002 bytes --]

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;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-25 14:17       ` Rafael Espindola
@ 2010-05-25 17:54         ` Rafael Espindola
  2010-05-26  0:21           ` Ian Lance Taylor
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael Espindola @ 2010-05-25 17:54 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Binutils, Sriraman Tallam, Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

> 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

[-- Attachment #2: gc-plugin.patch --]
[-- Type: text/x-diff, Size: 6519 bytes --]

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();
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch][gold] Fix PR11604
  2010-05-25 17:54         ` Rafael Espindola
@ 2010-05-26  0:21           ` Ian Lance Taylor
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Lance Taylor @ 2010-05-26  0:21 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: Cary Coutant, Binutils, Sriraman Tallam

Rafael Espindola <espindola@google.com> writes:

> @@ -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;
> +

Write this as
    if (!this->is_section_included(deferred->shndx_))
Update the comment accordingly.  Two spaces after a period in the
comment.


> @@ -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

I don't see why this last command is needed.  The rule for
plugin_test_7 should always create plugin_test_7.err.  The dependency
is fine, but I don't see why you need the touch command.


This is OK with the above changes.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-05-26  0:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24  2:41 [patch][gold] Fix PR11604 Rafael Espindola
2010-05-24 19:04 ` Cary Coutant
2010-05-24 21:59   ` Rafael Espindola
2010-05-25  0:06     ` Cary Coutant
2010-05-25 14:17       ` Rafael Espindola
2010-05-25 17:54         ` Rafael Espindola
2010-05-26  0:21           ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).