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]
Other format: [Raw text]

Crash in ld while creating relocatable Win32 PE


Hello!

Sorry for writing to this list, but bug-binutils seems to be taken over
by spammers.

Version 2.14 of binutils as well as the current snapshot binutils-031009
have a bug that causes ld to crash when creating a relocatable package for
Win32 (useful for binaries that will run on Win32s).

The minimal test case is:

$ ./ld-new -r /usr/i586-mingw32msvc/lib/crt2.o
Segmentation fault (core dumped)

crt2.o is from Debian unstable, package mingw32-binutils.  I put it here:
http://www.red-bean.com/~proski/tmp/crt2.o

When I run the snapshot under gdb, I see SIGSEGV in
_bfd_pei_swap_aouthdr_out().  The gdb output is attached.  Note that
sec->used_by_bfd is NULL.  Therefore, coff_section_data (abfd, sec) is
NULL.

Following patch fixes the crash, but I have no idea if it's correct:

================================
--- bfd/peigen.c
+++ bfd/peigen.c
@@ -674,7 +674,8 @@ _bfd_pei_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 (sec->used_by_bfd != NULL)
+	  isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
       }

     aouthdr_in->dsize = dsize;
================================

However, if I try to make Win32s executables with this linker, I get a
COFF file instead:

$ i586-mingw32msvc-gcc -Wl,--subsystem=windows:3.10 -Wl,--major-os-version=4\
  -Wl,--major-image-version=1 -Wl,-r -o cmdlgtst.exe -lcomdlg32 -lgdi32
<proski@portland cmdlgtst>$ file cmdlgtst.exe
cmdlgtst.exe: 80386 COFF executable not stripped - version 14338

-- 
Regards,
Pavel Roskin

Attachment: gdb.out
Description: Text document


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