This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] Generate "correct" PE executables with low alignment
- From: Christopher Faylor <me at cgf dot cx>
- To: binutils at sources dot redhat dot com
- Date: Tue, 28 Sep 2004 10:52:39 -0400
- Subject: Re: [PATCH] Generate "correct" PE executables with low alignment
- References: <41571A94.60600@volny.cz>
On Sun, Sep 26, 2004 at 09:37:56PM +0200, Filip Navara wrote:
>This patch solves one part of the infamous problem of "ld" generating
>incorrect PE binaries when low alignment is specified.
Do you have a URL which describes this "infamous" problem?
>The section virtual memory layout must match the on-disk layout of the
>file in this case (as the PE standard says). There's still other
>problem with the ".bss" section not accepted by the Windows loader and
>thus rejecting the generated executables. So far I haven't solved that
>in proper way, but I have workaround: Merge the .bss section at the end
>of .data section and move .data as the last loadable section in the
>file.
This patch seems ok but I'd like to get an ok from Nick and/or Danny, too.
cgf
ChangeLog:
2004-09-18 Filip Navara <navaraf@reactos.com>
* emulparams/arm_epoc_pe.sh, emulparams/armpe.sh,
emulparams/i386pe.sh, emulparams/i386pe_posix.sh,
emulparams/mcorepe.sh, emulparams/mipspe.sh,
emulparams/ppcpe.sh, scripttempl/pe.sc:
Define TARGET_PAGE_SIZE.
* scripttempl/pe.sc:
Make the virtual address and file offset synced if the alignment is
lower than the target page size.
--- ld/emulparams/arm_epoc_pe.sh Thu Dec 2 12:49:20 1999
+++ ld/emulparams/arm_epoc_pe.sh Sun Sep 19 00:15:47 2004
@@ -7,3 +7,4 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/armpe.sh Thu Dec 4 18:51:43 2003
+++ ld/emulparams/armpe.sh Sun Sep 19 00:11:34 2004
@@ -11,3 +11,5 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/i386pe.sh Sun Sep 12 18:45:16 1999
+++ ld/emulparams/i386pe.sh Sat Sep 18 23:53:30 2004
@@ -6,3 +6,4 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/i386pe_posix.sh Thu Aug 5 18:03:56 1999
+++ ld/emulparams/i386pe_posix.sh Sun Sep 19 00:18:06 2004
@@ -7,3 +7,4 @@
SUBSYSTEM=7
EXECUTABLE_NAME=a.out
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/mcorepe.sh Wed Nov 3 19:19:22 1999
+++ ld/emulparams/mcorepe.sh Sun Sep 19 00:16:16 2004
@@ -7,3 +7,4 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/mipspe.sh Thu Aug 10 21:07:26 2000
+++ ld/emulparams/mipspe.sh Sun Sep 19 00:17:35 2004
@@ -7,3 +7,4 @@
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
ENTRY="_mainCRTStartup"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/ppcpe.sh Sun Sep 12 18:45:16 1999
+++ ld/emulparams/ppcpe.sh Sun Sep 19 00:17:42 2004
@@ -5,3 +5,4 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/emulparams/shpe.sh Mon Jun 19 03:22:43 2000
+++ ld/emulparams/shpe.sh Sun Sep 19 00:17:47 2004
@@ -7,3 +7,4 @@
ENTRY="_mainCRTStartup"
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
+TARGET_PAGE_SIZE=0x1000
--- ld/scripttempl/pe.sc Tue Jun 22 23:38:34 2004
+++ ld/scripttempl/pe.sc Sun Sep 19 00:09:56 2004
@@ -54,7 +54,11 @@
SECTIONS
{
- .text ${RELOCATING+ __image_base__ + __section_alignment__ } :
+ ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
+ ${RELOCATING+ lower than the target page size. */}
+ ${RELOCATING+. = SIZEOF_HEADERS;}
+ ${RELOCATING+. = ALIGN(__section_alignment__);}
+ .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
{
${RELOCATING+ *(.init)}
*(.text)