]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Update GenFw to support 4K alignment.
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 29 Jun 2015 03:17:34 +0000 (03:17 +0000)
committeryingke <yingke@Edk2>
Mon, 29 Jun 2015 03:17:34 +0000 (03:17 +0000)
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

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

index 5c7b689ee868c182d6dded209f55347b00f91760..10d9892ba1e06839e1adcaf8e6284695573d589c 100644 (file)
@@ -96,7 +96,7 @@ STATIC Elf_Phdr *mPhdrBase;
 //\r
 // Coff information\r
 //\r
-STATIC const UINT32 mCoffAlignment = 0x20;\r
+STATIC UINT32 mCoffAlignment = 0x20;\r
 \r
 //\r
 // PE section alignment.\r
@@ -291,6 +291,20 @@ ScanSections32 (
   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
index 25b90e2f7b51089526bf1cbcad8a64b0a0b65f9b..d2becf165f5501a331ef7e08ed91ec1ae239ac54 100644 (file)
@@ -97,7 +97,7 @@ STATIC Elf_Phdr *mPhdrBase;
 //\r
 // Coff information\r
 //\r
-STATIC const UINT32 mCoffAlignment = 0x20;\r
+STATIC UINT32 mCoffAlignment = 0x20;\r
 \r
 //\r
 // PE section alignment.\r
@@ -285,6 +285,20 @@ ScanSections64 (
   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
index 1a84d3c28794f702036d4365b6e7a53e57f1e3a0..6211389ba1695458ec9e82faee470e1108910b68 100644 (file)
@@ -96,11 +96,11 @@ CoffAddFixup(
 \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
index b27a2f9d223f50b7792095d65431d5a6e1a3f6d0..56f165eae59b35c8b4e7e5f05520275a0f64ce6d 100644 (file)
@@ -34,6 +34,7 @@ extern UINT32 mOutImageType;
 // Common EFI specific data.\r
 //\r
 #define ELF_HII_SECTION_NAME ".hii"\r
+#define MAX_COFF_ALIGNMENT 0x10000\r
 \r
 //\r
 // Filter Types\r