[PATCH] Fix for "ld -r" crash in mingw32

Pavel Roskin proski@gnu.org
Fri Oct 17 02:02:00 GMT 2003


Hello!

This patch fixes segmentation fault in mingw32 linker when it tries to
combine multiple object files into one.  Function
_bfd_XXi_swap_aouthdr_out() calculates the total virtual size by adding
virtual size of sections.  However, some sections don't provide this
information and should not be counted.

There are many other examples in the same file peXXigen.c, when
coff_section_data and pei_section_data are checked for being not NULL
before the virt_size field is accessed.  See functions add_data_entry(),
pe_print_pdata(), _bfd_XX_bfd_copy_private_section_data() in the same
file.

I tried to be consistent with the existing code style.  The code has been
tested with problematic object files.  The problematic object file can be
found here: http://www.red-bean.com/~proski/tmp/crt2.o

To test, run "ld -r -o out.o crt2.o" - it crashes without the patch.

Description of the problem can be found here:
http://sources.redhat.com/ml/binutils/2003-10/msg00189.html

The patch is against the head version in CVS.  I checked the sources and
I'm quite confident that the patch is correct.  Please review and apply.

-- 
Regards,
Pavel Roskin
-------------- next part --------------
--- bfd/peXXigen.c
+++ bfd/peXXigen.c
@@ -674,7 +674,9 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out
 	   5.0 link.exe) where the file size of the .data segment is
 	   quite small compared to the virtual size.  Without this
 	   fix, strip munges the file.  */
-	isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
+	if (coff_section_data (abfd, sec) != NULL
+	    && pei_section_data (abfd, sec) != NULL)
+	  isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
       }
 
     aouthdr_in->dsize = dsize;


More information about the Binutils mailing list