]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFw: move PE/COFF header closer to payload
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 27 Jul 2015 13:50:09 +0000 (13:50 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Mon, 27 Jul 2015 13:50:09 +0000 (13:50 +0000)
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 <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yingke Liu <yingke.d.liu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18078 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/C/GenFw/Elf32Convert.c
BaseTools/Source/C/GenFw/Elf64Convert.c

index 53bb14a47dbfbbb95881e8898ea8a4113ef36b38..e1b92ebd713ef990899e5b48727e2703445f3d49 100644 (file)
@@ -306,6 +306,16 @@ ScanSections32 (
     }\r
   }\r
 \r
+  //\r
+  // Move the PE/COFF header right before the first section. This will help us\r
+  // save space when converting to TE.\r
+  //\r
+  if (mCoffAlignment > mCoffOffset) {\r
+    mNtHdrOffset += mCoffAlignment - mCoffOffset;\r
+    mTableOffset += mCoffAlignment - mCoffOffset;\r
+    mCoffOffset = mCoffAlignment;\r
+  }\r
+\r
   //\r
   // First text sections.\r
   //\r
index 7650afe54cfc90fc17546463e38d654413b484b6..1c0f4a4dc87cc15b042d3e5ab71808be49d4cc19 100644 (file)
@@ -300,6 +300,16 @@ ScanSections64 (
     }\r
   }\r
 \r
+  //\r
+  // Move the PE/COFF header right before the first section. This will help us\r
+  // save space when converting to TE.\r
+  //\r
+  if (mCoffAlignment > mCoffOffset) {\r
+    mNtHdrOffset += mCoffAlignment - mCoffOffset;\r
+    mTableOffset += mCoffAlignment - mCoffOffset;\r
+    mCoffOffset = mCoffAlignment;\r
+  }\r
+\r
   //\r
   // First text sections.\r
   //\r