This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[Patch] Fix PE dll -auto-import breakage from enforcing PE specs for section flags
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: binutils <binutils at sources dot redhat dot com>
- Cc: nickc at redhat dot com
- Date: Fri, 9 Jan 2004 10:07:55 +1100 (EST)
- Subject: [Patch] Fix PE dll -auto-import breakage from enforcing PE specs for section flags
This change to bfd
2003-12-15 Dmitry Semyonov <Dmitry.Semyonov@oktet.ru>
Nick Clifton <nickc@redhat.com>
* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Ensure that correct flags
are set on known section types.
causes the -auto-import feature of ld to produce invalid executables.
Here is an an example:
================================
/* clib.c */
int i = 1;
================================
================================
/* main.c */
extern int i;
int main (void)
{
return i;
}
================================
gcc -shared -o clib.dll -Wl,--out-implib,libclib.dll.a clib.c
gcc -o main main.c -L. -lclib.dll
./main.exe
Although the the dll and exe are built without error, executing the app
results in EXCEPTION_ACCESS_VIOLATION at initialization.
The problem is that -auto-import wants object with writeable .text section
(see pe_create_import_fixup() in ld/pe-dll.c) but _bfd_XXi_swap_scnhdr_out
unsets IMAGE_SCN_MEM_WRITE
The following patch works around the problem. I have used STRICT_PE_FORMAT
as a guard. Should all of the -auto-import code in pe-dll.c
and pe.em also be guarded with this (or something similar)?
Danny
bfd/ChangeLog
2004-01-08 Danny Smith <dannysmith@users.sourceforge.net>
* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Don't enforce PE spec flags
on .text if not STRICT_PE_FORMAT.
Index: peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.20
diff -c -3 -p -r1.20 peXXigen.c
*** peXXigen.c 15 Dec 2003 11:50:11 -0000 1.20
--- peXXigen.c 8 Jan 2004 20:05:52 -0000
*************** _bfd_XXi_swap_scnhdr_out (abfd, in, out)
*** 976,982 ****
--- 976,986 ----
{ ".rdata", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA },
{ ".reloc", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_DISCARDABLE },
{ ".rsrc", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_WRITE },
+ #ifdef STRICT_PE_FORMAT
+ /* When using -auto-import, .text is made writable!
+ See ld/pe-dll.c (pe_create_import_fixup). */
{ ".text" , IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE },
+ #endif
{ ".tls", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_WRITE },
{ ".xdata", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA },
{ NULL, 0}
http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.