]> 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 5be6e9037979c4df871305f99f970ca751190eb6..eeabbb24bc301abf962f4c9b9520abdf2c98604d 100644 (file)
@@ -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