Blame SOURCES/0471-util-mkimage-Reorder-PE-optional-header-fields-set-u.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Peter Jones <pjones@redhat.com>
80913e
Date: Mon, 15 Feb 2021 14:21:48 +0100
80913e
Subject: [PATCH] util/mkimage: Reorder PE optional header fields set-up
80913e
80913e
This makes the PE32 and PE32+ header fields set-up easier to follow by
80913e
setting them closer to the initialization of their related sections.
80913e
80913e
Signed-off-by: Peter Jones <pjones@redhat.com>
80913e
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 util/mkimage.c | 16 ++++++++--------
80913e
 1 file changed, 8 insertions(+), 8 deletions(-)
80913e
80913e
diff --git a/util/mkimage.c b/util/mkimage.c
80913e
index ff5462c98c1..e73a5864b22 100644
80913e
--- a/util/mkimage.c
80913e
+++ b/util/mkimage.c
80913e
@@ -1320,16 +1320,12 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 	    sections = o64 + 1;
80913e
 	  }
80913e
 
80913e
-	PE_OHDR (o32, o64, code_size) = grub_host_to_target32 (layout.exec_size);
80913e
-	PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);
80913e
+	PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
80913e
 	PE_OHDR (o32, o64, entry_addr) = grub_host_to_target32 (layout.start_address);
80913e
-	PE_OHDR (o32, o64, code_base) = grub_host_to_target32 (header_size);
80913e
-
80913e
 	PE_OHDR (o32, o64, image_base) = 0;
80913e
+	PE_OHDR (o32, o64, image_size) = grub_host_to_target32 (pe_size);
80913e
 	PE_OHDR (o32, o64, section_alignment) = grub_host_to_target32 (image_target->section_align);
80913e
 	PE_OHDR (o32, o64, file_alignment) = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT);
80913e
-	PE_OHDR (o32, o64, image_size) = grub_host_to_target32 (pe_size);
80913e
-	PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
80913e
 	PE_OHDR (o32, o64, subsystem) = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
80913e
 
80913e
 	/* Do these really matter? */
80913e
@@ -1339,10 +1335,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 	PE_OHDR (o32, o64, heap_commit_size) = grub_host_to_target32 (0x10000);
80913e
 
80913e
 	PE_OHDR (o32, o64, num_data_directories) = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
80913e
-	PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (reloc_addr);
80913e
-	PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (layout.reloc_size);
80913e
 
80913e
 	/* The sections.  */
80913e
+	PE_OHDR (o32, o64, code_base) = grub_host_to_target32 (header_size);
80913e
+	PE_OHDR (o32, o64, code_size) = grub_host_to_target32 (layout.exec_size);
80913e
 	text_section = sections;
80913e
 	strcpy (text_section->name, ".text");
80913e
 	text_section->virtual_size = grub_host_to_target32 (layout.exec_size);
80913e
@@ -1354,6 +1350,8 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 						| GRUB_PE32_SCN_MEM_EXECUTE
80913e
 						| GRUB_PE32_SCN_MEM_READ);
80913e
 
80913e
+	PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);
80913e
+
80913e
 	data_section = text_section + 1;
80913e
 	strcpy (data_section->name, ".data");
80913e
 	data_section->virtual_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
80913e
@@ -1376,6 +1374,8 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 			      | GRUB_PE32_SCN_MEM_READ
80913e
 			      | GRUB_PE32_SCN_MEM_WRITE);
80913e
 
80913e
+	PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (reloc_addr);
80913e
+	PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (layout.reloc_size);
80913e
 	reloc_section = mods_section + 1;
80913e
 	strcpy (reloc_section->name, ".reloc");
80913e
 	reloc_section->virtual_size = grub_host_to_target32 (layout.reloc_size);