]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/BasePeCoff.c
OVMF: Align PE images in ROM, and strip relocations were possible.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoff.c
index 0194cdba9761f6791749cfd8955ebe7e645357aa..eeabbb24bc301abf962f4c9b9520abdf2c98604d 100644 (file)
@@ -3,7 +3,7 @@
   only supports relocating IA32, x64, IPF, and EBC images.\r
 \r
   Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  Portions Copyright (c) 2008-2009 Apple Inc.<BR>
+  Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -548,7 +548,7 @@ PeCoffLoaderRelocateImage (
   if (ImageContext->RelocationsStripped) {\r
     // Applies additional environment specific actions to relocate fixups \r
     // to a PE/COFF image if needed\r
-    PeCoffLoaderRelocateImageExtraAction (ImageContext);       \r
+    PeCoffLoaderRelocateImageExtraAction (ImageContext);  \r
     return RETURN_SUCCESS;\r
   }\r
 \r
@@ -925,6 +925,14 @@ PeCoffLoaderLoadImage (
   //\r
   Section = FirstSection;\r
   for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) {\r
+    //\r
+    // Read the section\r
+    //\r
+    Size = (UINTN) Section->Misc.VirtualSize;\r
+    if ((Size == 0) || (Size > Section->SizeOfRawData)) {\r
+      Size = (UINTN) Section->SizeOfRawData;\r
+    }\r
+\r
     //\r
     // Compute sections address\r
     //\r
@@ -935,9 +943,9 @@ PeCoffLoaderLoadImage (
             );\r
 \r
     //\r
-    // If the base start or end address resolved to 0, then fail.\r
+    // If the size of the section is non-zero and the base address or end address resolved to 0, then fail.\r
     //\r
-    if ((Base == NULL) || (End == NULL)) {\r
+    if ((Size > 0) && ((Base == NULL) || (End == NULL))) {\r
       ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED;\r
       return RETURN_LOAD_ERROR;\r
     }\r
@@ -951,14 +959,6 @@ PeCoffLoaderLoadImage (
       MaxEnd = End;\r
     }\r
 \r
-    //\r
-    // Read the section\r
-    //\r
-    Size = (UINTN) Section->Misc.VirtualSize;\r
-    if ((Size == 0) || (Size > Section->SizeOfRawData)) {\r
-      Size = (UINTN) Section->SizeOfRawData;\r
-    }\r
-\r
     if (Section->SizeOfRawData > 0) {\r
       if (!(ImageContext->IsTeImage)) {\r
         Status = ImageContext->ImageRead (\r
@@ -1153,10 +1153,10 @@ PeCoffLoaderLoadImage (
           ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
           break;\r
 \r
-        case CODEVIEW_SIGNATURE_MTOC:
+        case CODEVIEW_SIGNATURE_MTOC:\r
           ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY);\r
-          break;
-
+          break;\r
+\r
         default:\r
           break;\r
         }\r