This is the mail archive of the binutils@sourceware.cygnus.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]

Re: BFD patch for peicode.h


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;

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