This is the mail archive of the binutils@sources.redhat.com 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]

MIPS ELF ld -Ur fails


Ian, Mark,

I have a patch which I'm hoping you'll be able to review.

I've been struggling with a problem on a linker configured for
mips-wrs-vxworks. The problem occurs with binutils 2.10.1 and
to 2.11.2, but does not occur for binutils 2.7!

Invoking the linker with:

	ld -Ur -u main a.o libb.a

causes a memory fault.

I managed to isolate the fault to elf_reloc_link_order (elflink.h),
and discovered that the call to elf_swap_reloc_out() at the tail
of this function was overwriting the end of the array.

The problem appears to confusion amongst the three counters are
used to track the number of relocation entries required in
the output file:

    o->reloc_count
    elf_section_data(o)->rel_count
    elf_section_data(o)->rel_count2.

Inspecting the counters when elf_link_size_reloc_section() is called
showed that rel_count + rel_count2 < reloc_count.

I believe that the problem is that bfd_section_reloc_link_order and
bfd_symbol_reloc_link_order contribute to reloc_count, but do
not get counted in either rel_count or rel_count2.

I've attempted to correct that with the patch below, which also
includes an assert to ensure that the counts match up.

I see that you modified this code around July 1999, and would
probably be in a position to review this patch.

(I have a test case available --- it's a little large.)

Thanks in advance.

Earl
========================================================================
--- /temp/binutils-2.10.1/bfd/elflink.h	Mon Oct 16 09:57:08 2000
+++ elflink.h	Mon Oct 22 21:45:07 2001
@@ -4087,7 +4087,10 @@
 	{
 	  if (p->type == bfd_section_reloc_link_order
 	      || p->type == bfd_symbol_reloc_link_order)
+            {
 	    ++o->reloc_count;
+	    ++elf_section_data(o)->rel_count;
+            }
 	  else if (p->type == bfd_indirect_link_order)
 	    {
 	      asection *sec;
@@ -4230,6 +4233,10 @@
 					       o))
 	    goto error_return;
 	}
+
+      BFD_ASSERT(
+          elf_section_data (o)->rel_count +
+          elf_section_data (o)->rel_count2 == o->reloc_count);
 
       /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
 	 to count upwards while actually outputting the relocations. */


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