MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPF
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 7 Sep 2018 05:42:01 +0000 (07:42 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 24 Sep 2018 14:56:44 +0000 (16:56 +0200)
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>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Library/BasePeCoffLib/BasePeCoff.c

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