Ard:
  Good suggestion. How about go through every Shdr and choose the max 
Shdr->sh_addralign?  The alignment should be power of 2. 

Thanks
Liming
-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]] 
Sent: Tuesday, June 23, 2015 5:14 PM
To: [email protected]
Subject: Re: [edk2] [Patch 2/3] BaseTools: Update GenFw to support 4K alignment.

On 23 June 2015 at 10:19, Yingke Liu <[email protected]> wrote:
> 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 <[email protected]>
> ---
>  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;
> +  }
> +

Can you explain why you are using the alignment of the entry point here? 
Wouldn't it be much better if mCoffAlignment is simply the max() of the 
alignments of all the sections?

>    //
>    // 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to