* [PATCH] PE aouthdr SizeOfHeaders field
@ 2004-03-25 12:46 Brian Ford
2004-04-09 18:10 ` [PATCH ping] " Brian Ford
0 siblings, 1 reply; 2+ messages in thread
From: Brian Ford @ 2004-03-25 12:46 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1727 bytes --]
While trying to add DWARF2 support to Cygwin/mingw, I came accross the
following buglet:
After compiling and linking a Cygwin app with DWARF2, executing the app
fails with:
-bash: ./app: Permission denied
ls -l app.exe
-rwxr-xr-x 1 ford None 17876798 Mar 21 17:11 app.exe*
strace ./app.exe
strace.exe: error creating process app.exe, (error 193)
MSDN says error 193 is:
ERROR_BADE_EXE_FORMAT: %1 is not a valid Win32 application
I stumbled on to the fact that objcopy app.exe fixes it. The file size
grows to:
-rwxr-xr-x 1 ford None 17898525 Mar 21 17:11 app.exe*
Diffing objdump -x shows (amoung other things):
-SizeOfImage 0194d000
-SizeOfHeaders 00000400
-CheckSum 0111987e
+SizeOfImage 0194c000
+SizeOfHeaders 00000000
+CheckSum 0110d9f8
Hmm..., SizeOfHeaders is output from peXXigen.c
(_bfd_XXi_swap_aouthdr_out). It is assumed to be the same as the file
offset of the first section (aligned to the section alignment, although,
shouldn't that already be reflected there by definition?).
Anyway, setting a break point there showed the first section to be one I had
accidentally left out of the linker script (.debug_ranges, an orphan) with
a file offset of 0. Looking at the output of objdump -h shows that alloc
only sections also have a zero file offset. So,
2004-03-24 Brian Ford <ford@vss.fsi.com>
* peXXigen.c (_bfd_XXi_swap_aouthdr_out): Orphan and alloc only
sections can have a filepos of 0, so use the first non-zero
filepos for the SizeOfHeaders field.
--
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
Phone: 314-551-8460
Fax: 314-551-8444
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1317 bytes --]
Index: peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.22
diff -u -p -r1.22 peXXigen.c
--- peXXigen.c 21 Feb 2004 06:16:02 -0000 1.22
+++ peXXigen.c 24 Mar 2004 23:43:53 -0000
@@ -657,14 +657,19 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out
{
asection *sec;
+ bfd_vma hsize = 0;
bfd_vma dsize = 0;
- bfd_vma isize = SA(abfd->sections->filepos);
+ bfd_vma isize = 0;
bfd_vma tsize = 0;
for (sec = abfd->sections; sec; sec = sec->next)
{
int rounded = FA(sec->_raw_size);
+ /* The first non-zero section filepos is the header size.
+ * Orphaned and alloc only sections may have a filepos of 0. */
+ if (hsize == 0)
+ hsize = sec->filepos;
if (sec->flags & SEC_DATA)
dsize += rounded;
if (sec->flags & SEC_CODE)
@@ -681,10 +686,10 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out
aouthdr_in->dsize = dsize;
aouthdr_in->tsize = tsize;
- extra->SizeOfImage = isize;
+ extra->SizeOfHeaders = hsize;
+ extra->SizeOfImage = SA(hsize) + isize;
}
- extra->SizeOfHeaders = abfd->sections->filepos;
H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->standard.magic);
#define LINKER_VERSION 256 /* That is, 2.56 */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH ping] PE aouthdr SizeOfHeaders field
2004-03-25 12:46 [PATCH] PE aouthdr SizeOfHeaders field Brian Ford
@ 2004-04-09 18:10 ` Brian Ford
0 siblings, 0 replies; 2+ messages in thread
From: Brian Ford @ 2004-04-09 18:10 UTC (permalink / raw)
To: binutils
http://sources.redhat.com/ml/binutils/2004-03/msg00543.html
Ok. I admit that this patch isn't perfect, but it is certainly an
improvement over what's currently there (using similar logic).
Is this Nick's call? I see he's been gone for a while. I hope he is ok.
If so, I'll be content to wait until I see him catching up on things :).
Thanks.
--
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
Phone: 314-551-8460
Fax: 314-551-8444
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-04-09 18:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-25 12:46 [PATCH] PE aouthdr SizeOfHeaders field Brian Ford
2004-04-09 18:10 ` [PATCH ping] " Brian Ford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).