diff mbox series

[edk2,2/4] MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPF

Message ID 20180906134523.2036-3-ard.biesheuvel@linaro.org
State Superseded
Headers show
Series remove all 11 occurrences of ELILO on IPF PE/COFF header hack | expand

Commit Message

Ard Biesheuvel Sept. 6, 2018, 1:45 p.m. UTC
Now that Itanium support has been dropped, we can remove the various
occurrences of the ELILO on Itanium PE/COFF header workaround.

Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++-----------------
 1 file changed, 9 insertions(+), 52 deletions(-)

-- 
2.18.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Laszlo Ersek Sept. 6, 2018, 4:31 p.m. UTC | #1
On 09/06/18 15:45, Ard Biesheuvel wrote:
> Now that Itanium support has been dropped, we can remove the various

> occurrences of the ELILO on Itanium PE/COFF header workaround.

> 

> Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---

>  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++-----------------

>  1 file changed, 9 insertions(+), 52 deletions(-)

> 

> diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

> index 32eca0ad2ef4..c57816a80887 100644

> --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

> +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

> @@ -46,36 +46,6 @@ PeCoffLoaderAdjustOffsetForTeImage (

>    SectionHeader->PointerToRawData -= TeStrippedOffset;

>  }

>  

> -/**

> -  Retrieves the magic value from the PE/COFF header.

> -

> -  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.

> -

> -  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32

> -  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+

> -

> -**/

> -UINT16

> -PeCoffLoaderGetPeHeaderMagicValue (

> -  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr

> -  )

> -{

> -  //

> -  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value

> -  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the

> -  //       Magic value in the OptionalHeader is  EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC

> -  //       then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC

> -  //

> -  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> -    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;

> -  }

> -  //

> -  // Return the magic value from the PC/COFF Optional Header

> -  //

> -  return Hdr.Pe32->OptionalHeader.Magic;

> -}

> -

> -

>  /**

>    Retrieves the PE or TE Header from a PE/COFF or TE image.

>  

> @@ -101,7 +71,6 @@ PeCoffLoaderGetPeHeader (

>    EFI_IMAGE_DOS_HEADER  DosHdr;

>    UINTN                 Size;

>    UINTN                 ReadSize;

> -  UINT16                Magic;

>    UINT32                SectionHeaderOffset;

>    UINT32                Index;

>    UINT32                HeaderWithoutDataDir;

> @@ -222,9 +191,7 @@ PeCoffLoaderGetPeHeader (

>      ImageContext->IsTeImage = FALSE;

>      ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;

>  

> -    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

> -

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // 1. Check OptionalHeader.NumberOfRvaAndSizes filed.

>        //

> @@ -339,7 +306,7 @@ PeCoffLoaderGetPeHeader (

>        ImageContext->SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;

>        ImageContext->SizeOfHeaders     = Hdr.Pe32->OptionalHeader.SizeOfHeaders;

>  

> -    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {

> +    } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {

>        //

>        // 1. Check FileHeader.NumberOfRvaAndSizes filed.

>        //

> @@ -605,7 +572,6 @@ PeCoffLoaderGetImageInfo (

>    EFI_IMAGE_SECTION_HEADER              SectionHeader;

>    EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       DebugEntry;

>    UINT32                                NumberOfRvaAndSizes;

> -  UINT16                                Magic;

>    UINT32                                TeStrippedOffset;

>  

>    if (ImageContext == NULL) {

> @@ -622,14 +588,12 @@ PeCoffLoaderGetImageInfo (

>      return Status;

>    }

>  

> -  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

> -

>    //

>    // Retrieve the base address of the image

>    //

>    if (!(ImageContext->IsTeImage)) {

>      TeStrippedOffset = 0;

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -678,7 +642,7 @@ PeCoffLoaderGetImageInfo (

>    }

>  

>    if (!(ImageContext->IsTeImage)) {

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -952,7 +916,6 @@ PeCoffLoaderRelocateImage (

>    CHAR8                                 *FixupData;

>    PHYSICAL_ADDRESS                      BaseAddress;

>    UINT32                                NumberOfRvaAndSizes;

> -  UINT16                                Magic;

>    UINT32                                TeStrippedOffset;

>  

>    ASSERT (ImageContext != NULL);

> @@ -985,9 +948,8 @@ PeCoffLoaderRelocateImage (

>    if (!(ImageContext->IsTeImage)) {

>      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);

>      TeStrippedOffset = 0;

> -    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>  

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -1230,7 +1192,6 @@ PeCoffLoaderLoadImage (

>    UINTN                                 Size;

>    UINT32                                TempDebugEntryRva;

>    UINT32                                NumberOfRvaAndSizes;

> -  UINT16                                Magic;

>    EFI_IMAGE_RESOURCE_DIRECTORY          *ResourceDirectory;

>    EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;

>    EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;

> @@ -1404,12 +1365,11 @@ PeCoffLoaderLoadImage (

>    //

>    // Get image's entry point

>    //

> -  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>    if (!(ImageContext->IsTeImage)) {

>      //

>      // Sizes of AddressOfEntryPoint are different so we need to do this safely

>      //

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -1444,7 +1404,7 @@ PeCoffLoaderLoadImage (

>    // the optional header to verify a desired directory entry is there.

>    //

>    if (!(ImageContext->IsTeImage)) {

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -1565,7 +1525,7 @@ PeCoffLoaderLoadImage (

>    //

>    ImageContext->HiiResourceData = 0;

>    if (!(ImageContext->IsTeImage)) {

> -    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>        //

>        // Use PE32 offset

>        //

> @@ -1721,7 +1681,6 @@ PeCoffLoaderRelocateImageForRuntime (

>    CHAR8                               *FixupData;

>    UINTN                               Adjust;

>    RETURN_STATUS                       Status;

> -  UINT16                              Magic;

>  

>    OldBase = (CHAR8 *)((UINTN)ImageBase);

>    NewBase = (CHAR8 *)((UINTN)VirtImageBase);

> @@ -1750,9 +1709,7 @@ PeCoffLoaderRelocateImageForRuntime (

>      return ;

>    }

>  

> -  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

> -

> -  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

> +  if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>      //

>      // Use PE32 offset

>      //

> 


Reviewed-by: Laszlo Ersek <lersek@redhat.com>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Zeng, Star Sept. 7, 2018, 5:15 a.m. UTC | #2
Reviewed-by: Star Zeng <star.zeng@intel.com>


-----Original Message-----
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] 

Sent: Thursday, September 6, 2018 9:45 PM
To: edk2-devel@lists.01.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Zeng, Star <star.zeng@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>; Zhang, Chao B <chao.b.zhang@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Laszlo Ersek <lersek@redhat.com>; Leif Lindholm <leif.lindholm@linaro.org>
Subject: [PATCH 2/4] MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPF

Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround.

Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++-----------------
 1 file changed, 9 insertions(+), 52 deletions(-)

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 32eca0ad2ef4..c57816a80887 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -46,36 +46,6 @@ PeCoffLoaderAdjustOffsetForTeImage (
   SectionHeader->PointerToRawData -= TeStrippedOffset;  }
 
-/**
-  Retrieves the magic value from the PE/COFF header.
-
-  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.
-
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
-
-**/
-UINT16
-PeCoffLoaderGetPeHeaderMagicValue (
-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr
-  )
-{
-  //
-  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
-  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the
-  //       Magic value in the OptionalHeader is  EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
-  //       then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
-  //
-  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
-    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
-  }
-  //
-  // Return the magic value from the PC/COFF Optional Header
-  //
-  return Hdr.Pe32->OptionalHeader.Magic; -}
-
-
 /**
   Retrieves the PE or TE Header from a PE/COFF or TE image.
 
@@ -101,7 +71,6 @@ PeCoffLoaderGetPeHeader (
   EFI_IMAGE_DOS_HEADER  DosHdr;
   UINTN                 Size;
   UINTN                 ReadSize;
-  UINT16                Magic;
   UINT32                SectionHeaderOffset;
   UINT32                Index;
   UINT32                HeaderWithoutDataDir;
@@ -222,9 +191,7 @@ PeCoffLoaderGetPeHeader (
     ImageContext->IsTeImage = FALSE;
     ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;
 
-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // 1. Check OptionalHeader.NumberOfRvaAndSizes filed.
       //
@@ -339,7 +306,7 @@ PeCoffLoaderGetPeHeader (
       ImageContext->SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;
       ImageContext->SizeOfHeaders     = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
 
-    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+    } else if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
       //
       // 1. Check FileHeader.NumberOfRvaAndSizes filed.
       //
@@ -605,7 +572,6 @@ PeCoffLoaderGetImageInfo (
   EFI_IMAGE_SECTION_HEADER              SectionHeader;
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       DebugEntry;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   UINT32                                TeStrippedOffset;
 
   if (ImageContext == NULL) {
@@ -622,14 +588,12 @@ PeCoffLoaderGetImageInfo (
     return Status;
   }
 
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
   //
   // Retrieve the base address of the image
   //
   if (!(ImageContext->IsTeImage)) {
     TeStrippedOffset = 0;
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -678,7 +642,7 @@ PeCoffLoaderGetImageInfo (
   }
 
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -952,7 +916,6 @@ PeCoffLoaderRelocateImage (
   CHAR8                                 *FixupData;
   PHYSICAL_ADDRESS                      BaseAddress;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   UINT32                                TeStrippedOffset;
 
   ASSERT (ImageContext != NULL);
@@ -985,9 +948,8 @@ PeCoffLoaderRelocateImage (
   if (!(ImageContext->IsTeImage)) {
     Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);
     TeStrippedOffset = 0;
-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
 
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1230,7 +1192,6 @@ PeCoffLoaderLoadImage (
   UINTN                                 Size;
   UINT32                                TempDebugEntryRva;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   EFI_IMAGE_RESOURCE_DIRECTORY          *ResourceDirectory;
   EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;
   EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;
@@ -1404,12 +1365,11 @@ PeCoffLoaderLoadImage (
   //
   // Get image's entry point
   //
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
   if (!(ImageContext->IsTeImage)) {
     //
     // Sizes of AddressOfEntryPoint are different so we need to do this safely
     //
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1444,7 +1404,7 @@ PeCoffLoaderLoadImage (
   // the optional header to verify a desired directory entry is there.
   //
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1565,7 +1525,7 @@ PeCoffLoaderLoadImage (
   //
   ImageContext->HiiResourceData = 0;
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1721,7 +1681,6 @@ PeCoffLoaderRelocateImageForRuntime (
   CHAR8                               *FixupData;
   UINTN                               Adjust;
   RETURN_STATUS                       Status;
-  UINT16                              Magic;
 
   OldBase = (CHAR8 *)((UINTN)ImageBase);
   NewBase = (CHAR8 *)((UINTN)VirtImageBase); @@ -1750,9 +1709,7 @@ PeCoffLoaderRelocateImageForRuntime (
     return ;
   }
 
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
-  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+  if (Hdr.Pe32->OptionalHeader.Magic == 
+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
     //
     // Use PE32 offset
     //
--
2.18.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Gao, Liming Sept. 7, 2018, 5:36 a.m. UTC | #3
Reviewed-by: Liming Gao <liming.gao@intel.com>


>-----Original Message-----

>From: Zeng, Star

>Sent: Friday, September 07, 2018 1:15 PM

>To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; edk2-devel@lists.01.org

>Cc: Wang, Jian J <jian.j.wang@intel.com>; Kinney, Michael D

><michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>; Zhang,

>Chao B <chao.b.zhang@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;

>Laszlo Ersek <lersek@redhat.com>; Leif Lindholm <leif.lindholm@linaro.org>;

>Zeng, Star <star.zeng@intel.com>

>Subject: RE: [PATCH 2/4] MdePkg/BasePeCoffLib: remove PE/COFF header

>workaround for ELILO on IPF

>

>Reviewed-by: Star Zeng <star.zeng@intel.com>

>

>-----Original Message-----

>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

>Sent: Thursday, September 6, 2018 9:45 PM

>To: edk2-devel@lists.01.org

>Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Zeng, Star

><star.zeng@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Kinney,

>Michael D <michael.d.kinney@intel.com>; Gao, Liming

><liming.gao@intel.com>; Zhang, Chao B <chao.b.zhang@intel.com>; Yao,

>Jiewen <jiewen.yao@intel.com>; Laszlo Ersek <lersek@redhat.com>; Leif

>Lindholm <leif.lindholm@linaro.org>

>Subject: [PATCH 2/4] MdePkg/BasePeCoffLib: remove PE/COFF header

>workaround for ELILO on IPF

>

>Now that Itanium support has been dropped, we can remove the various

>occurrences of the ELILO on Itanium PE/COFF header workaround.

>

>Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816

>Contributed-under: TianoCore Contribution Agreement 1.1

>Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>---

> MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++-----------------

> 1 file changed, 9 insertions(+), 52 deletions(-)

>

>diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

>b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

>index 32eca0ad2ef4..c57816a80887 100644

>--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

>+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

>@@ -46,36 +46,6 @@ PeCoffLoaderAdjustOffsetForTeImage (

>   SectionHeader->PointerToRawData -= TeStrippedOffset;  }

>

>-/**

>-  Retrieves the magic value from the PE/COFF header.

>-

>-  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE

>header.

>-

>-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32

>-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+

>-

>-**/

>-UINT16

>-PeCoffLoaderGetPeHeaderMagicValue (

>-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr

>-  )

>-{

>-  //

>-  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic

>value

>-  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the

>-  //       Magic value in the OptionalHeader is

>EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC

>-  //       then override the returned value to

>EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC

>-  //

>-  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 &&

>Hdr.Pe32->OptionalHeader.Magic ==

>EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>-    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;

>-  }

>-  //

>-  // Return the magic value from the PC/COFF Optional Header

>-  //

>-  return Hdr.Pe32->OptionalHeader.Magic; -}

>-

>-

> /**

>   Retrieves the PE or TE Header from a PE/COFF or TE image.

>

>@@ -101,7 +71,6 @@ PeCoffLoaderGetPeHeader (

>   EFI_IMAGE_DOS_HEADER  DosHdr;

>   UINTN                 Size;

>   UINTN                 ReadSize;

>-  UINT16                Magic;

>   UINT32                SectionHeaderOffset;

>   UINT32                Index;

>   UINT32                HeaderWithoutDataDir;

>@@ -222,9 +191,7 @@ PeCoffLoaderGetPeHeader (

>     ImageContext->IsTeImage = FALSE;

>     ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;

>

>-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>-

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // 1. Check OptionalHeader.NumberOfRvaAndSizes filed.

>       //

>@@ -339,7 +306,7 @@ PeCoffLoaderGetPeHeader (

>       ImageContext->SectionAlignment  = Hdr.Pe32-

>>OptionalHeader.SectionAlignment;

>       ImageContext->SizeOfHeaders     = Hdr.Pe32-

>>OptionalHeader.SizeOfHeaders;

>

>-    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {

>+    } else if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {

>       //

>       // 1. Check FileHeader.NumberOfRvaAndSizes filed.

>       //

>@@ -605,7 +572,6 @@ PeCoffLoaderGetImageInfo (

>   EFI_IMAGE_SECTION_HEADER              SectionHeader;

>   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       DebugEntry;

>   UINT32                                NumberOfRvaAndSizes;

>-  UINT16                                Magic;

>   UINT32                                TeStrippedOffset;

>

>   if (ImageContext == NULL) {

>@@ -622,14 +588,12 @@ PeCoffLoaderGetImageInfo (

>     return Status;

>   }

>

>-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>-

>   //

>   // Retrieve the base address of the image

>   //

>   if (!(ImageContext->IsTeImage)) {

>     TeStrippedOffset = 0;

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -678,7 +642,7 @@ PeCoffLoaderGetImageInfo (

>   }

>

>   if (!(ImageContext->IsTeImage)) {

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -952,7 +916,6 @@ PeCoffLoaderRelocateImage (

>   CHAR8                                 *FixupData;

>   PHYSICAL_ADDRESS                      BaseAddress;

>   UINT32                                NumberOfRvaAndSizes;

>-  UINT16                                Magic;

>   UINT32                                TeStrippedOffset;

>

>   ASSERT (ImageContext != NULL);

>@@ -985,9 +948,8 @@ PeCoffLoaderRelocateImage (

>   if (!(ImageContext->IsTeImage)) {

>     Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext-

>>ImageAddress + ImageContext->PeCoffHeaderOffset);

>     TeStrippedOffset = 0;

>-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -1230,7 +1192,6 @@ PeCoffLoaderLoadImage (

>   UINTN                                 Size;

>   UINT32                                TempDebugEntryRva;

>   UINT32                                NumberOfRvaAndSizes;

>-  UINT16                                Magic;

>   EFI_IMAGE_RESOURCE_DIRECTORY          *ResourceDirectory;

>   EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;

>   EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;

>@@ -1404,12 +1365,11 @@ PeCoffLoaderLoadImage (

>   //

>   // Get image's entry point

>   //

>-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>   if (!(ImageContext->IsTeImage)) {

>     //

>     // Sizes of AddressOfEntryPoint are different so we need to do this safely

>     //

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -1444,7 +1404,7 @@ PeCoffLoaderLoadImage (

>   // the optional header to verify a desired directory entry is there.

>   //

>   if (!(ImageContext->IsTeImage)) {

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -1565,7 +1525,7 @@ PeCoffLoaderLoadImage (

>   //

>   ImageContext->HiiResourceData = 0;

>   if (!(ImageContext->IsTeImage)) {

>-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+    if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>       //

>       // Use PE32 offset

>       //

>@@ -1721,7 +1681,6 @@ PeCoffLoaderRelocateImageForRuntime (

>   CHAR8                               *FixupData;

>   UINTN                               Adjust;

>   RETURN_STATUS                       Status;

>-  UINT16                              Magic;

>

>   OldBase = (CHAR8 *)((UINTN)ImageBase);

>   NewBase = (CHAR8 *)((UINTN)VirtImageBase); @@ -1750,9 +1709,7 @@

>PeCoffLoaderRelocateImageForRuntime (

>     return ;

>   }

>

>-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);

>-

>-  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>+  if (Hdr.Pe32->OptionalHeader.Magic ==

>+ EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {

>     //

>     // Use PE32 offset

>     //

>--

>2.18.0


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 32eca0ad2ef4..c57816a80887 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -46,36 +46,6 @@  PeCoffLoaderAdjustOffsetForTeImage (
   SectionHeader->PointerToRawData -= TeStrippedOffset;
 }
 
-/**
-  Retrieves the magic value from the PE/COFF header.
-
-  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.
-
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
-
-**/
-UINT16
-PeCoffLoaderGetPeHeaderMagicValue (
-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr
-  )
-{
-  //
-  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
-  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the
-  //       Magic value in the OptionalHeader is  EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
-  //       then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
-  //
-  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
-    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
-  }
-  //
-  // Return the magic value from the PC/COFF Optional Header
-  //
-  return Hdr.Pe32->OptionalHeader.Magic;
-}
-
-
 /**
   Retrieves the PE or TE Header from a PE/COFF or TE image.
 
@@ -101,7 +71,6 @@  PeCoffLoaderGetPeHeader (
   EFI_IMAGE_DOS_HEADER  DosHdr;
   UINTN                 Size;
   UINTN                 ReadSize;
-  UINT16                Magic;
   UINT32                SectionHeaderOffset;
   UINT32                Index;
   UINT32                HeaderWithoutDataDir;
@@ -222,9 +191,7 @@  PeCoffLoaderGetPeHeader (
     ImageContext->IsTeImage = FALSE;
     ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;
 
-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // 1. Check OptionalHeader.NumberOfRvaAndSizes filed.
       //
@@ -339,7 +306,7 @@  PeCoffLoaderGetPeHeader (
       ImageContext->SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;
       ImageContext->SizeOfHeaders     = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
 
-    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+    } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
       //
       // 1. Check FileHeader.NumberOfRvaAndSizes filed.
       //
@@ -605,7 +572,6 @@  PeCoffLoaderGetImageInfo (
   EFI_IMAGE_SECTION_HEADER              SectionHeader;
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       DebugEntry;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   UINT32                                TeStrippedOffset;
 
   if (ImageContext == NULL) {
@@ -622,14 +588,12 @@  PeCoffLoaderGetImageInfo (
     return Status;
   }
 
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
   //
   // Retrieve the base address of the image
   //
   if (!(ImageContext->IsTeImage)) {
     TeStrippedOffset = 0;
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -678,7 +642,7 @@  PeCoffLoaderGetImageInfo (
   }
 
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -952,7 +916,6 @@  PeCoffLoaderRelocateImage (
   CHAR8                                 *FixupData;
   PHYSICAL_ADDRESS                      BaseAddress;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   UINT32                                TeStrippedOffset;
 
   ASSERT (ImageContext != NULL);
@@ -985,9 +948,8 @@  PeCoffLoaderRelocateImage (
   if (!(ImageContext->IsTeImage)) {
     Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);
     TeStrippedOffset = 0;
-    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
 
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1230,7 +1192,6 @@  PeCoffLoaderLoadImage (
   UINTN                                 Size;
   UINT32                                TempDebugEntryRva;
   UINT32                                NumberOfRvaAndSizes;
-  UINT16                                Magic;
   EFI_IMAGE_RESOURCE_DIRECTORY          *ResourceDirectory;
   EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;
   EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;
@@ -1404,12 +1365,11 @@  PeCoffLoaderLoadImage (
   //
   // Get image's entry point
   //
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
   if (!(ImageContext->IsTeImage)) {
     //
     // Sizes of AddressOfEntryPoint are different so we need to do this safely
     //
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1444,7 +1404,7 @@  PeCoffLoaderLoadImage (
   // the optional header to verify a desired directory entry is there.
   //
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1565,7 +1525,7 @@  PeCoffLoaderLoadImage (
   //
   ImageContext->HiiResourceData = 0;
   if (!(ImageContext->IsTeImage)) {
-    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
       //
       // Use PE32 offset
       //
@@ -1721,7 +1681,6 @@  PeCoffLoaderRelocateImageForRuntime (
   CHAR8                               *FixupData;
   UINTN                               Adjust;
   RETURN_STATUS                       Status;
-  UINT16                              Magic;
 
   OldBase = (CHAR8 *)((UINTN)ImageBase);
   NewBase = (CHAR8 *)((UINTN)VirtImageBase);
@@ -1750,9 +1709,7 @@  PeCoffLoaderRelocateImageForRuntime (
     return ;
   }
 
-  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);
-
-  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+  if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
     //
     // Use PE32 offset
     //