If current ELF file is 4K aligned, the converted PE should also be 4K aligned.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yingke Liu <yingke.d....@intel.com> --- BaseTools/Source/C/GenFw/Elf32Convert.c | 8 ++++++-- BaseTools/Source/C/GenFw/Elf64Convert.c | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c index 5c7b689..9245851 100644 --- a/BaseTools/Source/C/GenFw/Elf32Convert.c +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c @@ -96,7 +96,7 @@ STATIC Elf_Phdr *mPhdrBase; // // Coff information // -STATIC const UINT32 mCoffAlignment = 0x20; +STATIC UINT32 mCoffAlignment = 0x20; // // PE section alignment. @@ -154,7 +154,11 @@ InitializeElf32 ( Error (NULL, 0, 3000, "Unsupported", "ELF e_version (%u) not EV_CURRENT (%d)", (unsigned) mEhdr->e_version, EV_CURRENT); return FALSE; } - + + if ((mEhdr->e_entry & 0xFFF) == 0) { + mCoffAlignment = 0x1000; + } + // // Update section header pointers // diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 25b90e2..8737e30 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -97,7 +97,7 @@ STATIC Elf_Phdr *mPhdrBase; // // Coff information // -STATIC const UINT32 mCoffAlignment = 0x20; +STATIC UINT32 mCoffAlignment = 0x20; // // PE section alignment. @@ -158,6 +158,10 @@ InitializeElf64 ( return FALSE; } + if ((mEhdr->e_entry & 0xFFF) == 0) { + mCoffAlignment = 0x1000; + } + // // Update section header pointers // -- 1.9.5.msysgit.0 ------------------------------------------------------------------------------ Monitor 25 network devices or servers for free with OpManager! OpManager is web-based network management software that monitors network devices and physical & virtual servers, alerts via email & sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel