Get maximum section alignment from each ELF section, and this alignment is used to create PE header.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17727
6f19259b-4bc3-4df7-8a09-
765794883524
//\r
// Coff information\r
//\r
-STATIC const UINT32 mCoffAlignment = 0x20;\r
+STATIC UINT32 mCoffAlignment = 0x20;\r
\r
//\r
// PE section alignment.\r
mTableOffset = mCoffOffset;\r
mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);\r
\r
+ //\r
+ // Set mCoffAlignment to the maximum alignment of the input sections\r
+ // we care about\r
+ //\r
+ for (i = 0; i < mEhdr->e_shnum; i++) {\r
+ Elf_Shdr *shdr = GetShdrByIndex(i);\r
+ if (shdr->sh_addralign <= mCoffAlignment) {\r
+ continue;\r
+ }\r
+ if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {\r
+ mCoffAlignment = (UINT32)shdr->sh_addralign;\r
+ }\r
+ }\r
+\r
//\r
// First text sections.\r
//\r
//\r
// Coff information\r
//\r
-STATIC const UINT32 mCoffAlignment = 0x20;\r
+STATIC UINT32 mCoffAlignment = 0x20;\r
\r
//\r
// PE section alignment.\r
mTableOffset = mCoffOffset;\r
mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);\r
\r
+ //\r
+ // Set mCoffAlignment to the maximum alignment of the input sections\r
+ // we care about\r
+ //\r
+ for (i = 0; i < mEhdr->e_shnum; i++) {\r
+ Elf_Shdr *shdr = GetShdrByIndex(i);\r
+ if (shdr->sh_addralign <= mCoffAlignment) {\r
+ continue;\r
+ }\r
+ if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {\r
+ mCoffAlignment = (UINT32)shdr->sh_addralign;\r
+ }\r
+ }\r
+\r
//\r
// First text sections.\r
//\r
\r
mCoffFile = realloc (\r
mCoffFile,\r
- mCoffOffset + sizeof(EFI_IMAGE_BASE_RELOCATION) + 2*0x1000\r
+ mCoffOffset + sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
);\r
memset (\r
mCoffFile + mCoffOffset, 0,\r
- sizeof(EFI_IMAGE_BASE_RELOCATION) + 2*0x1000\r
+ sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
);\r
\r
mCoffBaseRel = (EFI_IMAGE_BASE_RELOCATION*)(mCoffFile + mCoffOffset);\r
// Common EFI specific data.\r
//\r
#define ELF_HII_SECTION_NAME ".hii"\r
+#define MAX_COFF_ALIGNMENT 0x10000\r
\r
//\r
// Filter Types\r