This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR ld/15323: Unable to redefine weak function in -flto incrementally-linked executable


We didn't set non_ir_ref for reference to the definition within the same
file.  I checked in this patch to fix x86 ELF targets.  Other targets
may need the similar fix.


H.J.
---
bfd/

2013-03-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15323
	* elf32-i386.c (elf_i386_check_relocs): Set non_ir_ref if a
	symbol is referenced by a non-shared object. 
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/testsuite/

2013-03-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15323
	* ld-plugin/lto.exp (lto_link_tests): Add pr15323a-r.o.
	(lto_run_tests): Add a test for PR ld/15323.

	* ld-plugin/pr15323.out: New file.
	* ld-plugin/pr15323a.c: Likewise.
	* ld-plugin/pr15323b.c: Likewise.

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index f898a5c..2609130 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1,6 +1,6 @@
 /* Intel 80386/80486-specific support for 32-bit ELF
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -1514,6 +1514,7 @@ elf_i386_check_relocs (bfd *abfd,
 
 	  /* It is referenced by a non-shared object. */
 	  h->ref_regular = 1;
+	  h->root.non_ir_ref = 1;
 	}
 
       if (! elf_i386_tls_transition (info, abfd, sec, NULL,
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 1e43ff5..9adc959 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1,6 +1,6 @@
 /* X86-64 specific support for ELF
    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010, 2011, 2012
+   2010, 2011, 2012, 2013
    Free Software Foundation, Inc.
    Contributed by Jan Hubicka <jh@suse.cz>.
 
@@ -1519,6 +1519,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
 	  /* It is referenced by a non-shared object. */
 	  h->ref_regular = 1;
+	  h->root.non_ir_ref = 1;
 	}
 
       if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index cd4b25e..cf1ddf3 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -1,5 +1,5 @@
 # Expect script for ld-plugin LTO tests
-#   Copyright 2011
+#   Copyright 2011, 2012, 2013
 #   Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
@@ -143,6 +143,9 @@ set lto_link_tests {
   {"PR ld/13287"
    "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto"
    {pr13287.cc} {} "pr13287.exe" "c++"}
+  {"PR ld/15323"
+   "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto"
+   {pr15323a.c} {} "pr15323a-r.o" "c"}
 }
 
 # Generate input files for complex LTO tests for ELF.
@@ -266,6 +269,9 @@ set lto_run_tests {
   {"PR ld/13201"
    "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" ""
    {dummy.c} "pr13201.exe" "pr13201.out" "" "c"}
+  {"PR ld/15323"
+   "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr15323a-r.o" ""
+   {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"}
 }
 
 # LTO run-time tests for ELF
diff --git a/ld/testsuite/ld-plugin/pr15323.out b/ld/testsuite/ld-plugin/pr15323.out
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15323.out
@@ -0,0 +1 @@
+OK
diff --git a/ld/testsuite/ld-plugin/pr15323a.c b/ld/testsuite/ld-plugin/pr15323a.c
new file mode 100644
index 0000000..02a365b
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15323a.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int x;
+
+__attribute__((weak))
+void foobar (void) { x++; }
+
+int main (void)
+{
+  foobar ();
+  if (x == -1)
+    printf ("OK\n");
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr15323b.c b/ld/testsuite/ld-plugin/pr15323b.c
new file mode 100644
index 0000000..3ce5063
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr15323b.c
@@ -0,0 +1,3 @@
+extern int x;
+
+void foobar (void) { x--; }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]