PE linker broken with `ld -r' and C++

Andrew Haley aph@pasanda.cygnus.co.uk
Thu Oct 14 03:25:00 GMT 1999


PE and C++ and `ld -r' don't work together.

In coff_write_object_contents() there's a bit of code that looks like
this:

  else if (long_section_names)
    {
      /* If we have long section names we have to write out the string
         table even if there are no symbols.  */
      if (! coff_write_symbols (abfd))
	return false;
    }

This is wrong.  If we're doing a partial link, the symbol table has
already been written and we must not call coff_write_symbols() because
at this point output_bfd->symcount is zero and the symbol table will
be nuked.  This used to work OK (with C) because long_section_names
was false whenever doing a partial link; now that I've enabled partial
linking with long section names, everything collapses in a heap.

My fix involves not calling coff_write_symbols() if
obj_raw_syment_count is nonzero, which will be the case if we're doing
a partial link.  Does this make any sense?

Thanks,
Andrew.


Index: coffcode.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/coffcode.h,v
retrieving revision 1.324.2.2
diff -u -r1.324.2.2 coffcode.h
--- coffcode.h	1999/05/28 00:33:18	1.324.2.2
+++ coffcode.h	1999/10/06 15:30:08
@@ -3021,8 +3021,9 @@
     {
       /* If we have long section names we have to write out the string
          table even if there are no symbols.  */
-      if (! coff_write_symbols (abfd))
-	return false;
+      if (obj_raw_syment_count (abfd) == 0) 
+	if (! coff_write_symbols (abfd))
+	  return false;
     }
 #endif
 #ifdef COFF_IMAGE_WITH_PE



More information about the Binutils mailing list