diff mbox

[edk2,2/3] BaseTools: Update GenFw to support 4K alignment.

Message ID CAKv+Gu-YgojgnEbuo9dfVOFhBDmc=CPj1XVkg_GXFsq6mcRPFQ@mail.gmail.com
State New
Headers show

Commit Message

Ard Biesheuvel June 24, 2015, 8:18 a.m. UTC
On 24 June 2015 at 10:15, Gao, Liming <liming.gao@intel.com> wrote:
> Ard:
>   Good suggestion. How about go through every Shdr and choose the max Shdr->sh_addralign?  The alignment should be power of 2.
>

Indeed. Something like this seems to work fine:

"""
"""

Note that we may want to use 64 KB instead of 4 KB on AArch64, since
the OS may use 64 KB pages. So we should avoid hardcoding 4 KB values
for section alignment.
diff mbox

Patch

diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
b/BaseTools/Source/C/GenFw/Elf64Convert.c
index 2266e487cec7..4025191e868e 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.
@@ -286,6 +286,20 @@  ScanSections64 (
   mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);

   //
+  // Set mCoffAlignment to the maximum alignment of the input sections
+  // we care about
+  //
+  for (i = 0; i < mEhdr->e_shnum; i++) {
+    Elf_Shdr *shdr = GetShdrByIndex(i);
+    if (shdr->sh_addralign <= mCoffAlignment) {
+      continue;
+    }
+    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {
+      mCoffAlignment = shdr->sh_addralign;
+    }
+  }
+
+  //
   // First text sections.
   //
   mCoffOffset = CoffAlign(mCoffOffset);