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]

Re: Fix assertion failure on aliases of dynamic weak symbols


Alan Modra <amodra@bigpond.net.au> writes:
> On Mon, Jul 16, 2007 at 06:10:10PM +0100, Richard Sandiford wrote:
>> 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.
>
> This is OK.

Thanks.  As HJ asked, I changed the test so that the shared library
uses a normal object definition of the strong symbol.  Here's what
I installed, after checking that the new test failed before the
patch and passes after it.

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	23 Jul 2007 09:55:13 -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	23 Jul 2007 09:55:13 -0000
@@ -0,0 +1,13 @@
+	.globl	foo
+	.weak	foo
+	.type	foo,%object
+	.size	foo,1
+
+	.globl	bar
+	.type	bar,%object
+	.size	bar,1
+
+	.data
+foo:
+bar:
+	.byte	1
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	23 Jul 2007 09:55:13 -0000
@@ -0,0 +1,2 @@
+	.data
+	.dc.a	foo
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	23 Jul 2007 09:55:13 -0000
@@ -0,0 +1,8 @@
+SECTIONS
+{
+  . = 0x800000;
+  PROVIDE (bar = .);
+  .data : {
+    *(.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	23 Jul 2007 09:55:13 -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	23 Jul 2007 09:55:13 -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" "" {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]