This is the mail archive of the binutils@sourceware.cygnus.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]

[aph@cygnus.co.uk: PE linker broken with `ld -r' and C++]


Last year I submitted this patch.  At the time, we couldn't agree that
it was the right thing to do.  I believe it is, and this patch has
been in Cygnus releases ever since, with no apparent regressions.

I think that six months is long enough.  Unless someone objects I'd
like to check it in.

Andrew.

------- Start of forwarded message -------
Date: 14 Oct 1999 10:25:52 -0000
From: Andrew Haley <aph@cygnus.co.uk>
To: binutils@sourceware.cygnus.com
Subject: PE linker broken with `ld -r' and C++

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;
+       /* This is for PE: 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 destroyed. */
+      if (obj_raw_syment_count (abfd) == 0) 
+       if (! coff_write_symbols (abfd))
+         return false;
     }
 #endif
 #ifdef COFF_IMAGE_WITH_PE
------- End of forwarded message -------

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