public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: BFD patch for peicode.h
@ 2000-06-22 20:57 David Mosberger
  2000-06-22 21:16 ` DJ Delorie
  0 siblings, 1 reply; 2+ messages in thread
From: David Mosberger @ 2000-06-22 20:57 UTC (permalink / raw)
  To: binutils

Jim Wilson suggested that I send the attached mail to this list so
that the right people can see it.  Suggestions on the particulars of
the patch are welcome (I'm no PECOFF expert).  Also, I'd appreciate if
we could find a way to make it less likely that changes to the PECOFF
support break the EFI support.

(EFI is the bootloader object file format that Intel is using for the
IA-64 platform.  It's exactly like PECOFF+, except that the subsystem
type must be EFI Application.  Also, even though it's used primarily
for IA-64, there is an x86 version as well, which makes EFI testing
possible even without access to an IA-64 machine.)

Thanks,

	--david

--------------------------------------------------------------------
From: David Mosberger <davidm@hpl.hp.com>
Subject: [ia64-tools] BFD patch for peicode.h
Date: Thu, 22 Jun 2000 18:00:22 -0700

The attached patch was necessary to get non-trivial EFI programs to
build correctly.  Without this patch, every so often (usually with
large programs), it happened that EFI would refuse to load an EFI
binary with a message along the lines of "address out of image range".
This appeared to happen whenever the binary contained a section that
was not completely inside the address range
[ImageBase,ImageBase+SizeOfImage).  Based on this I concluded that
SizeOfImage probably should be calculated as the difference between
the highest address in the binary and ImageBase (the PECOFF doc I have
is less than clear on this topic) and this is what the attached patch
is trying to do.  Could a PECOFF expert review this and merge it into
the official tree if it looks right?

On a related note: I noticed that the BFD tree on sourceware has
completely broken EFI support.  It looked like the EFI binaries
produced end up with an SizeOfImage of zero and the Subsystem type is
zero instead of "EFI Application".  I'd really appreciate if the
person who broke this had the courtesy of fixing it again.  Sample GNU
EFI applications are publically available
(ftp.hpl.hp.com/pub/linux-ia64/gnu-efi*) and can be built on any x86
system, so there is little excuse not to do that.

Thanks,

	--david

2000-06-22  David Mosberger  <davidm@hpl.hp.com>

	* peicode.h (coff_swap_aouthdr_out): Compute SizeOfImage as
	difference between highest section address and the ImageBase.

--- orig/bfd/peicode.h	Fri Feb 18 14:39:16 2000
+++ src/bfd/peicode.h	Thu Jun 22 17:36:01 2000
@@ -1119,7 +1119,7 @@
   {
     asection *sec;
     bfd_vma dsize= 0;
-    bfd_vma isize = SA(abfd->sections->filepos);
+    bfd_vma hi = 0;
     bfd_vma tsize= 0;
 
     for (sec = abfd->sections; sec; sec = sec->next)
@@ -1130,12 +1130,15 @@
 	  dsize += rounded;
 	if (sec->flags & SEC_CODE)
 	  tsize += rounded;
-	isize += SA(rounded);
+
+	rounded = SA(rounded);
+	if (sec->lma + rounded > hi)
+		hi = sec->lma + rounded;
       }
 
     aouthdr_in->dsize = dsize;
     aouthdr_in->tsize = tsize;
-    extra->SizeOfImage = isize;
+    extra->SizeOfImage = (hi - ib);
   }
 
   extra->SizeOfHeaders = abfd->sections->filepos;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: BFD patch for peicode.h
  2000-06-22 20:57 BFD patch for peicode.h David Mosberger
@ 2000-06-22 21:16 ` DJ Delorie
  0 siblings, 0 replies; 2+ messages in thread
From: DJ Delorie @ 2000-06-22 21:16 UTC (permalink / raw)
  To: davidm; +Cc: binutils

> Also, I'd appreciate if we could find a way to make it less likely
> that changes to the PECOFF support break the EFI support.

I suggest automated build/test machines for targets that you want to
keep in a good state.  Unfortunately, automated testing on PE machines
isn't trivial.  I do cross-builds for cygwin every night.

> This appeared to happen whenever the binary contained a section that
> was not completely inside the address range
> [ImageBase,ImageBase+SizeOfImage).  Based on this I concluded that
> SizeOfImage probably should be calculated as the difference between
> the highest address in the binary and ImageBase (the PECOFF doc I have
> is less than clear on this topic) and this is what the attached patch
> is trying to do.

Based on what I read in MSDN, I agree that it's the size of the
virtual image *in memory*.  I don't know if it includes the
non-program sections, though, like the import table.  We've never had
problems with NT or CE wrt this field, but then NT is pretty lax about
what it runs.

> Could a PECOFF expert review this and merge it into the official
> tree if it looks right?

We're woefully short on PE experts at the moment :-(

> On a related note: I noticed that the BFD tree on sourceware has
> completely broken EFI support.

Sourceware has broken *PE* support at the moment, which I'm trying to
fix.  PE has been fairly unusable since Sept 1999.

> 2000-06-22  David Mosberger  <davidm@hpl.hp.com>
> 
> 	* peicode.h (coff_swap_aouthdr_out): Compute SizeOfImage as
> 	difference between highest section address and the ImageBase.
> 
> --- orig/bfd/peicode.h	Fri Feb 18 14:39:16 2000
> +++ src/bfd/peicode.h	Thu Jun 22 17:36:01 2000
> @@ -1119,7 +1119,7 @@

What is this patch against?  In sourceware, that function is in
peigen.c and looks nothing like what you're patch is against.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-06-22 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-22 20:57 BFD patch for peicode.h David Mosberger
2000-06-22 21:16 ` DJ Delorie

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).