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