Revision: 18078
          http://sourceforge.net/p/edk2/code/18078
Author:   abiesheuvel
Date:     2015-07-27 13:50:09 +0000 (Mon, 27 Jul 2015)
Log Message:
-----------
BaseTools/GenFw: move PE/COFF header closer to payload

The secondary header (not the DOS header) of a PE/COFF binary
does not reside at a fixed offset. Instead, its offset into the
file is recorded in the DOS header.

This gives us the flexibility to move it, along with the section
headers, to right before the first section if there is considerable
space before it, i.e., when the PE/COFF file alignment is substantially
larger than the size of the header.

Since the PE/COFF to TE conversion replaces everything before the
section headers with a simple TE header, this change removes all
the header padding from such images, leading to smaller files.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
Reviewed-by: Yingke Liu <[email protected]>

Modified Paths:
--------------
    trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c
    trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c

Modified: trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c
===================================================================
--- trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c  2015-07-27 13:49:54 UTC 
(rev 18077)
+++ trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c  2015-07-27 13:50:09 UTC 
(rev 18078)
@@ -307,6 +307,16 @@
   }
 
   //
+  // Move the PE/COFF header right before the first section. This will help us
+  // save space when converting to TE.
+  //
+  if (mCoffAlignment > mCoffOffset) {
+    mNtHdrOffset += mCoffAlignment - mCoffOffset;
+    mTableOffset += mCoffAlignment - mCoffOffset;
+    mCoffOffset = mCoffAlignment;
+  }
+
+  //
   // First text sections.
   //
   mCoffOffset = CoffAlign(mCoffOffset);

Modified: trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c
===================================================================
--- trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c  2015-07-27 13:49:54 UTC 
(rev 18077)
+++ trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c  2015-07-27 13:50:09 UTC 
(rev 18078)
@@ -301,6 +301,16 @@
   }
 
   //
+  // Move the PE/COFF header right before the first section. This will help us
+  // save space when converting to TE.
+  //
+  if (mCoffAlignment > mCoffOffset) {
+    mNtHdrOffset += mCoffAlignment - mCoffOffset;
+    mTableOffset += mCoffAlignment - mCoffOffset;
+    mCoffOffset = mCoffAlignment;
+  }
+
+  //
   // First text sections.
   //
   mCoffOffset = CoffAlign(mCoffOffset);


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to