|
|
9723a8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
9723a8 |
From: Peter Jones <pjones@redhat.com>
|
|
|
9723a8 |
Date: Thu, 11 Feb 2021 17:07:33 +0100
|
|
|
9723a8 |
Subject: [PATCH] util/mkimage: Improve data_size value calculation
|
|
|
9723a8 |
|
|
|
9723a8 |
According to "Microsoft Portable Executable and Common Object File Format
|
|
|
9723a8 |
Specification", the Optional Header SizeOfInitializedData field contains:
|
|
|
9723a8 |
|
|
|
9723a8 |
Size of the initialized data section, or the sum of all such sections if
|
|
|
9723a8 |
there are multiple data sections.
|
|
|
9723a8 |
|
|
|
9723a8 |
Make this explicit by adding the GRUB kernel data size to the sum of all
|
|
|
9723a8 |
the modules sizes. The ALIGN_UP() is not required by the PE spec but do
|
|
|
9723a8 |
it to avoid alignment issues.
|
|
|
9723a8 |
|
|
|
9723a8 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
9723a8 |
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
|
|
|
9723a8 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
9723a8 |
---
|
|
|
9723a8 |
util/mkimage.c | 6 +++++-
|
|
|
9723a8 |
1 file changed, 5 insertions(+), 1 deletion(-)
|
|
|
9723a8 |
|
|
|
9723a8 |
diff --git a/util/mkimage.c b/util/mkimage.c
|
|
|
9723a8 |
index 18a92c68d15..ed2d59d995f 100644
|
|
|
9723a8 |
--- a/util/mkimage.c
|
|
|
9723a8 |
+++ b/util/mkimage.c
|
|
|
9723a8 |
@@ -1213,6 +1213,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
|
|
9723a8 |
void *pe_img;
|
|
|
9723a8 |
grub_uint8_t *header;
|
|
|
9723a8 |
void *sections;
|
|
|
9723a8 |
+ size_t scn_size;
|
|
|
9723a8 |
size_t pe_size;
|
|
|
9723a8 |
struct grub_pe32_coff_header *c;
|
|
|
9723a8 |
struct grub_pe32_section_table *text_section, *data_section;
|
|
|
9723a8 |
@@ -1315,7 +1316,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
|
|
9723a8 |
| GRUB_PE32_SCN_MEM_EXECUTE
|
|
|
9723a8 |
| GRUB_PE32_SCN_MEM_READ);
|
|
|
9723a8 |
|
|
|
9723a8 |
- PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);
|
|
|
9723a8 |
+ scn_size = ALIGN_UP (layout.kernel_size - layout.exec_size, GRUB_PE32_FILE_ALIGNMENT);
|
|
|
9723a8 |
+ PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size +
|
|
|
9723a8 |
+ ALIGN_UP (total_module_size,
|
|
|
9723a8 |
+ GRUB_PE32_FILE_ALIGNMENT));
|
|
|
9723a8 |
|
|
|
9723a8 |
data_section = text_section + 1;
|
|
|
9723a8 |
strcpy (data_section->name, ".data");
|