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]

Fix assertion failure on aliases of dynamic weak symbols


The attached testcase fails on GNU/Linux targets with:

  BFD (GNU Binutils) 2.17.50.20070716 assertion fail .../bfd/elflink.c:2496

A shared library has a weak symbol "foo", and bfd determines that the
strong symbol "data_start" is an alias for "foo" (it has the same section
and value).  The shared library is then involved in another link, and the
script for that link defines "data_start" via a PROVIDE statement.

This works in the same way that it would for a non-PROVIDE assignment;
"data_start" is not used as an alias for "foo".  However, we handle the
PROVIDE case by setting "data_start"'s type to bfd_link_hash_undefined:

  /* If this symbol is being provided by the linker script, and it is
     currently defined by a dynamic object, but not by a regular
     object, then mark it as undefined so that the generic linker will
     force the correct value.  */
  if (provide
      && h->def_dynamic
      && !h->def_regular)
    h->root.type = bfd_link_hash_undefined;
  [...]
  h->def_regular = 1;

whereas _bfd_elf_fix_symbol_flags expects the type to be
bfd_link_hash_defined or bfd_link_hash_defweak.

The testcase is still being handled correctly, and it doesn't seem
appropriate to weaken the assert by checking for the non-obvious
bfd_link_hash_undefined, so I simply moved the assert into the
!def_regular case (i.e. the one where we continue to use the alias).

I've restricted the test to GNU/Linux targets because not all ELF
targets support -shared.

Tested on x86_64-linux-gnu, i686-pc-linux-gnu, arm-eabi, cris-elf,
mips-linux-gnu, mips64-linux-gnu, mipsisa64-elf, powerpc-linux-gnu,
powerpc64-linux-gnu and ia64-linux-gnu.  OK to install?

Richard


bfd/
	* elflink.c (_bfd_elf_fix_symbol_flags): Only assert the type
	of weakdef->root.type if weakdef has no regular definition.

ld/testsuite/
	* ld-elf/weak-dyn-1a.s, ld-elf/weak-dyn-1b.s, ld-elf/weak-dyn-1.ld,
	* ld-elf/weak-dyn-1.rd: New test.
	* ld-elf/elf.exp: Run it.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.269
diff -u -p -r1.269 elflink.c
--- bfd/elflink.c	10 Jul 2007 02:40:31 -0000	1.269
+++ bfd/elflink.c	16 Jul 2007 17:09:19 -0000
@@ -2492,8 +2492,6 @@ _bfd_elf_fix_symbol_flags (struct elf_li
 
       BFD_ASSERT (h->root.type == bfd_link_hash_defined
 		  || h->root.type == bfd_link_hash_defweak);
-      BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
-		  || weakdef->root.type == bfd_link_hash_defweak);
       BFD_ASSERT (weakdef->def_dynamic);
 
       /* If the real definition is defined by a regular object file,
@@ -2502,8 +2500,11 @@ _bfd_elf_fix_symbol_flags (struct elf_li
       if (weakdef->def_regular)
 	h->u.weakdef = NULL;
       else
-	(*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef,
-						  h);
+	{
+	  BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
+		      || weakdef->root.type == bfd_link_hash_defweak);
+	  (*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef, h);
+	}
     }
 
   return TRUE;
Index: ld/testsuite/ld-elf/weak-dyn-1a.s
===================================================================
RCS file: ld/testsuite/ld-elf/weak-dyn-1a.s
diff -N ld/testsuite/ld-elf/weak-dyn-1a.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/weak-dyn-1a.s	16 Jul 2007 17:09:19 -0000
@@ -0,0 +1,7 @@
+	.globl	foo
+	.weak	foo
+	.type	foo,%object
+	.size	foo,1
+	.data
+foo:
+	.dc.a	data_begin
Index: ld/testsuite/ld-elf/weak-dyn-1b.s
===================================================================
RCS file: ld/testsuite/ld-elf/weak-dyn-1b.s
diff -N ld/testsuite/ld-elf/weak-dyn-1b.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/weak-dyn-1b.s	16 Jul 2007 17:09:19 -0000
@@ -0,0 +1,3 @@
+	.data
+	.dc.a	foo
+	.dc.a	data_begin
Index: ld/testsuite/ld-elf/weak-dyn-1.ld
===================================================================
RCS file: ld/testsuite/ld-elf/weak-dyn-1.ld
diff -N ld/testsuite/ld-elf/weak-dyn-1.ld
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/weak-dyn-1.ld	16 Jul 2007 17:09:19 -0000
@@ -0,0 +1,8 @@
+SECTIONS
+{
+  . = 0x800000;
+  .data : {
+    PROVIDE (data_begin = .);
+    *(.data)
+  }
+}
Index: ld/testsuite/ld-elf/weak-dyn-1.rd
===================================================================
RCS file: ld/testsuite/ld-elf/weak-dyn-1.rd
diff -N ld/testsuite/ld-elf/weak-dyn-1.rd
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/weak-dyn-1.rd	16 Jul 2007 17:09:19 -0000
@@ -0,0 +1,3 @@
+#...
+0+800000 .* foo.*
+#pass
Index: ld/testsuite/ld-elf/elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/elf.exp,v
retrieving revision 1.10
diff -u -p -r1.10 elf.exp
--- ld/testsuite/ld-elf/elf.exp	6 Jul 2007 14:09:43 -0000	1.10
+++ ld/testsuite/ld-elf/elf.exp	16 Jul 2007 17:09:19 -0000
@@ -36,6 +36,19 @@ foreach t $test_list {
     run_dump_test [file rootname $t]
 }
 
+if { [istarget *-*-linux*] } {
+    run_ld_link_tests {
+	{"Weak symbols in dynamic objects 1 (support)"
+	    "-shared -Tweak-dyn-1.ld" "" {weak-dyn-1a.s}
+	    {}
+	    "libweakdyn1a.so"}
+	{"Weak symbols in dynamic objects 1 (main test)"
+	    "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s}
+	    {{readelf {--relocs --wide} weak-dyn-1.rd}}
+	    "libweakdyn1b.so"}
+    }
+}
+
 # The following tests require running the executable generated by ld.
 if ![isnative] {
     return


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