]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Update BaseDebugLibNull to not touch any global variables or PCD settings
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoff.c
index ebc3b3cc6c558a5b7dac7affe61279415db890f4..0ddbc7a672e295d22f82c63da4841f8178041ff7 100644 (file)
@@ -62,10 +62,10 @@ PeHotRelocateImageEx (
 \r
 \r
 /**\r
-  Returns TRUE if the machine type of PE/COFF image is supported. Supported \r
+  Returns TRUE if the machine type of PE/COFF image is supported. Supported\r
   does not mean the image can be executed it means the PE/COFF loader supports\r
   loading and relocating of the image type. It's up to the caller to support\r
-  the entry point. \r
+  the entry point.\r
 \r
   @param  Machine   Machine type from the PE Header.\r
 \r
@@ -78,6 +78,35 @@ PeCoffLoaderImageFormatSupported (
   );\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 == EFI_IMAGE_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
@@ -98,6 +127,7 @@ PeCoffLoaderGetPeHeader (
   RETURN_STATUS         Status;\r
   EFI_IMAGE_DOS_HEADER  DosHdr;\r
   UINTN                 Size;\r
+  UINT16                Magic;\r
 \r
   //\r
   // Read the DOS image header to check for it's existance\r
@@ -117,16 +147,16 @@ PeCoffLoaderGetPeHeader (
   ImageContext->PeCoffHeaderOffset = 0;\r
   if (DosHdr.e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
     //\r
-    // DOS image header is present, so read the PE header after the DOS image \r
+    // DOS image header is present, so read the PE header after the DOS image\r
     // header\r
     //\r
     ImageContext->PeCoffHeaderOffset = DosHdr.e_lfanew;\r
   }\r
 \r
   //\r
-  // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much \r
+  // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much\r
   // data, but that should not hurt anythine. Hdr.Pe32->OptionalHeader.Magic\r
-  // determins if this is a PE32 or PE32+ image. The magic is in the same \r
+  // determins if this is a PE32 or PE32+ image. The magic is in the same\r
   // location in both images.\r
   //\r
   Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
@@ -155,8 +185,10 @@ PeCoffLoaderGetPeHeader (
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
     ImageContext->IsTeImage = FALSE;\r
     ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;\r
-    \r
-    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+\r
+    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
       //\r
@@ -165,7 +197,7 @@ PeCoffLoaderGetPeHeader (
       ImageContext->SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
       ImageContext->SizeOfHeaders     = Hdr.Pe32->OptionalHeader.SizeOfHeaders;\r
 \r
-    } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
       //\r
       // Use PE32+ offset\r
       //\r
@@ -175,7 +207,7 @@ PeCoffLoaderGetPeHeader (
       ImageContext->SizeOfHeaders     = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;\r
     } else {\r
       ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
-      return RETURN_UNSUPPORTED;    \r
+      return RETURN_UNSUPPORTED;\r
     }\r
   } else {\r
     ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
@@ -187,7 +219,7 @@ PeCoffLoaderGetPeHeader (
     // If the PE/COFF loader does not support the image type return\r
     // unsupported. This library can suport lots of types of images\r
     // this does not mean the user of this library can call the entry\r
-    // point of the image. \r
+    // point of the image.\r
     //\r
     return RETURN_UNSUPPORTED;\r
   }\r
@@ -205,7 +237,7 @@ PeCoffLoaderGetPeHeader (
   If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
   a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
   computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
-  ImageContext. \r
+  ImageContext.\r
 \r
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that needs to be examined by this function.\r
@@ -233,6 +265,7 @@ PeCoffLoaderGetImageInfo (
   EFI_IMAGE_SECTION_HEADER              SectionHeader;\r
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       DebugEntry;\r
   UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
 \r
   if (NULL == ImageContext) {\r
     return RETURN_INVALID_PARAMETER;\r
@@ -248,11 +281,13 @@ 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
-    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
       //\r
@@ -297,20 +332,20 @@ PeCoffLoaderGetImageInfo (
   }\r
 \r
   if (!(ImageContext->IsTeImage)) {\r
-    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-      //     \r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
       // Use PE32 offset\r
       //\r
       NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
       DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
     } else {\r
-      //     \r
+      //\r
       // Use PE32+ offset\r
       //\r
       NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
       DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-    }    \r
-    \r
+    }\r
+\r
     if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
 \r
       DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
@@ -324,8 +359,8 @@ PeCoffLoaderGetImageInfo (
 \r
       SectionHeaderOffset = (UINTN)(\r
                                ImageContext->PeCoffHeaderOffset +\r
-                               sizeof (UINT32) + \r
-                               sizeof (EFI_IMAGE_FILE_HEADER) + \r
+                               sizeof (UINT32) +\r
+                               sizeof (EFI_IMAGE_FILE_HEADER) +\r
                                Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
                                );\r
 \r
@@ -428,8 +463,8 @@ PeCoffLoaderGetImageInfo (
 \r
       //\r
       // In Te image header there is not a field to describe the ImageSize.\r
-      // Actually, the ImageSize equals the RVA plus the VirtualSize of \r
-      // the last section mapped into memory (Must be rounded up to \r
+      // Actually, the ImageSize equals the RVA plus the VirtualSize of\r
+      // the last section mapped into memory (Must be rounded up to\r
       // a mulitple of Section Alignment). Per the PE/COFF specification, the\r
       // section headers in the Section Table must appear in order of the RVA\r
       // values for the corresponding sections. So the ImageSize can be determined\r
@@ -489,7 +524,7 @@ PeCoffLoaderImageAddress (
   )\r
 {\r
   //\r
-  // @bug Check to make sure ImageSize is correct for the relocated image. \r
+  // @bug Check to make sure ImageSize is correct for the relocated image.\r
   //      it may only work for the file we start with and not the relocated image\r
   //\r
   if (Address >= ImageContext->ImageSize) {\r
@@ -506,7 +541,7 @@ PeCoffLoaderImageAddress (
   If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
   ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
   of ImageContext as the relocation base address.  The caller must allocate the relocation\r
-  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.\r
   If ImageContext is NULL, then ASSERT().\r
 \r
   @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
@@ -537,11 +572,12 @@ PeCoffLoaderRelocateImage (
   CHAR8                                 *Fixup;\r
   CHAR8                                 *FixupBase;\r
   UINT16                                *F16;\r
-  UINT32                                *F32;  \r
+  UINT32                                *F32;\r
   UINT64                                *F64;\r
   CHAR8                                 *FixupData;\r
   PHYSICAL_ADDRESS                      BaseAddress;\r
   UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
 \r
   ASSERT (ImageContext != NULL);\r
 \r
@@ -569,13 +605,16 @@ PeCoffLoaderRelocateImage (
 \r
   if (!(ImageContext->IsTeImage)) {\r
     Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);\r
-    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+\r
+    Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
       //\r
       Adjust = (UINT64)BaseAddress - Hdr.Pe32->OptionalHeader.ImageBase;\r
       Hdr.Pe32->OptionalHeader.ImageBase = (UINT32)BaseAddress;\r
-  \r
+\r
       NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
       RelocDir  = &Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
     } else {\r
@@ -610,7 +649,7 @@ PeCoffLoaderRelocateImage (
     }\r
   } else {\r
     Hdr.Te             = (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->ImageAddress);\r
-    Adjust            = (UINT64) (BaseAddress - Hdr.Te->ImageBase);\r
+    Adjust             = (UINT64) (BaseAddress - Hdr.Te->ImageBase);\r
     Hdr.Te->ImageBase  = (UINT64) (BaseAddress);\r
 \r
     //\r
@@ -618,14 +657,14 @@ PeCoffLoaderRelocateImage (
     //\r
     RelocDir = &Hdr.Te->DataDirectory[0];\r
     RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
-                                    ImageContext->ImageAddress + \r
+                                    ImageContext->ImageAddress +\r
                                     RelocDir->VirtualAddress +\r
-                                    sizeof(EFI_TE_IMAGE_HEADER) - \r
+                                    sizeof(EFI_TE_IMAGE_HEADER) -\r
                                     Hdr.Te->StrippedSize\r
                                     );\r
     RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
   }\r
-  \r
+\r
   //\r
   // Run the relocation information and apply the fixups\r
   //\r
@@ -639,13 +678,13 @@ PeCoffLoaderRelocateImage (
     } else {\r
       FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
                     RelocBase->VirtualAddress +\r
-                    sizeof(EFI_TE_IMAGE_HEADER) - \r
+                    sizeof(EFI_TE_IMAGE_HEADER) -\r
                     Hdr.Te->StrippedSize\r
                     );\r
     }\r
 \r
     if ((CHAR8 *) RelocEnd < (CHAR8 *) ((UINTN) ImageContext->ImageAddress) ||\r
-        (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + \r
+        (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress +\r
           (UINTN)ImageContext->ImageSize)) {\r
       ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
       return RETURN_LOAD_ERROR;\r
@@ -663,7 +702,7 @@ PeCoffLoaderRelocateImage (
 \r
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16   = (UINT16 *) Fixup;\r
-        *F16  = (UINT16) ((*F16 << 16) + (UINT16) Adjust);\r
+        *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         if (FixupData != NULL) {\r
           *(UINT16 *) FixupData = *F16;\r
           FixupData             = FixupData + sizeof (UINT16);\r
@@ -771,6 +810,7 @@ PeCoffLoaderLoadImage (
   UINTN                                 Size;\r
   UINT32                                TempDebugEntryRva;\r
   UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
 \r
   ASSERT (ImageContext != NULL);\r
 \r
@@ -852,8 +892,8 @@ PeCoffLoaderLoadImage (
     FirstSection = (EFI_IMAGE_SECTION_HEADER *) (\r
                       (UINTN)ImageContext->ImageAddress +\r
                       ImageContext->PeCoffHeaderOffset +\r
-                      sizeof(UINT32) + \r
-                      sizeof(EFI_IMAGE_FILE_HEADER) + \r
+                      sizeof(UINT32) +\r
+                      sizeof(EFI_IMAGE_FILE_HEADER) +\r
                       Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
       );\r
     NumberOfSections = (UINTN) (Hdr.Pe32->FileHeader.NumberOfSections);\r
@@ -958,14 +998,15 @@ 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 (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
-      //      \r
+      //\r
       ImageContext->EntryPoint = (PHYSICAL_ADDRESS)(UINTN)PeCoffLoaderImageAddress (\r
                                                             ImageContext,\r
                                                             (UINTN)Hdr.Pe32->OptionalHeader.AddressOfEntryPoint\r
@@ -996,7 +1037,7 @@ PeCoffLoaderLoadImage (
   // the optional header to verify a desired directory entry is there.\r
   //\r
   if (!(ImageContext->IsTeImage)) {\r
-    if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
       //\r
@@ -1009,7 +1050,7 @@ PeCoffLoaderLoadImage (
       NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
       DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
     }\r
\r
+\r
     if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
       ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);\r
     } else {\r
@@ -1124,8 +1165,8 @@ PeCoffLoaderLoadImage (
 \r
 /**\r
   Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
-  runtime. \r
-  \r
+  runtime.\r
+\r
   PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
   the fixups with a virtual mapping.\r
 \r
@@ -1134,7 +1175,7 @@ PeCoffLoaderLoadImage (
   @param  VirtImageBase      Virtual mapping for ImageBase\r
   @param  ImageSize          Size of the image to relocate\r
   @param  RelocationData     Location to place results of read\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1164,6 +1205,7 @@ 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
@@ -1192,22 +1234,21 @@ PeCoffLoaderRelocateImageForRuntime (
     return ;\r
   }\r
 \r
-  //\r
-  // Get some data from the PE type dependent data\r
-  //\r
-  if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-    //     \r
+  Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr);\r
+\r
+  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    //\r
     // Use PE32 offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
-    DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+    DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[0]);\r
   } else {\r
-    //     \r
+    //\r
     // Use PE32+ offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
-    DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-  }    \r
+    DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[0]);\r
+  }\r
 \r
   //\r
   // Find the relocation block\r
@@ -1215,7 +1256,7 @@ PeCoffLoaderRelocateImageForRuntime (
   // Per the PE/COFF spec, you can't assume that a given data directory\r
   // is present in the image. You have to check the NumberOfRvaAndSizes in\r
   // the optional header to verify a desired directory entry is there.\r
-  //    \r
+  //\r
   if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
     RelocDir      = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC;\r
     RelocBase     = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress);\r
@@ -1258,7 +1299,7 @@ PeCoffLoaderRelocateImageForRuntime (
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16 = (UINT16 *) Fixup;\r
         if (*(UINT16 *) FixupData == *F16) {\r
-          *F16 = (UINT16) ((*F16 << 16) + ((UINT16) Adjust & 0xffff));\r
+          *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         }\r
 \r
         FixupData = FixupData + sizeof (UINT16);\r
@@ -1286,9 +1327,11 @@ PeCoffLoaderRelocateImageForRuntime (
       case EFI_IMAGE_REL_BASED_DIR64:\r
         F64       = (UINT64 *)Fixup;\r
         FixupData = ALIGN_POINTER (FixupData, sizeof (UINT64));\r
-        if (*(UINT32 *) FixupData == *F64) {\r
+        if (*(UINT64 *) FixupData == *F64) {\r
           *F64 = *F64 + (UINT64)Adjust;\r
         }\r
+\r
+        FixupData = FixupData + sizeof (UINT64);\r
         break;\r
 \r
       case EFI_IMAGE_REL_BASED_HIGHADJ:\r
@@ -1322,14 +1365,14 @@ PeCoffLoaderRelocateImageForRuntime (
 \r
 /**\r
   ImageRead function that operates on a memory buffer whos base is passed into\r
-  FileHandle. \r
+  FileHandle.\r
 \r
   @param  FileHandle        Ponter to baes of the input stream\r
   @param  FileOffset        Offset to the start of the buffer\r
   @param  ReadSize          Number of bytes to copy into the buffer\r
   @param  Buffer            Location to place results of read\r
 \r
-  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into\r
                             the buffer.\r
 **/\r
 RETURN_STATUS\r