0138-util-mkimage-Reorder-PE-optional-header-fields-set-u.patch 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From ba44c87e56a8bccde235ebb7d41d5aa54604d241 Mon Sep 17 00:00:00 2001
  2. From: Peter Jones <pjones@redhat.com>
  3. Date: Mon, 15 Feb 2021 14:21:48 +0100
  4. Subject: [PATCH] util/mkimage: Reorder PE optional header fields set-up
  5. This makes the PE32 and PE32+ header fields set-up easier to follow by
  6. setting them closer to the initialization of their related sections.
  7. Signed-off-by: Peter Jones <pjones@redhat.com>
  8. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
  9. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  10. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  11. ---
  12. util/mkimage.c | 16 ++++++++--------
  13. 1 file changed, 8 insertions(+), 8 deletions(-)
  14. diff --git a/util/mkimage.c b/util/mkimage.c
  15. index a039039..deaef56 100644
  16. --- a/util/mkimage.c
  17. +++ b/util/mkimage.c
  18. @@ -1332,16 +1332,12 @@ grub_install_generate_image (const char *dir, const char *prefix,
  19. sections = o64 + 1;
  20. }
  21. - PE_OHDR (o32, o64, code_size) = grub_host_to_target32 (layout.exec_size);
  22. - PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);
  23. + PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
  24. PE_OHDR (o32, o64, entry_addr) = grub_host_to_target32 (layout.start_address);
  25. - PE_OHDR (o32, o64, code_base) = grub_host_to_target32 (header_size);
  26. -
  27. PE_OHDR (o32, o64, image_base) = 0;
  28. + PE_OHDR (o32, o64, image_size) = grub_host_to_target32 (pe_size);
  29. PE_OHDR (o32, o64, section_alignment) = grub_host_to_target32 (image_target->section_align);
  30. PE_OHDR (o32, o64, file_alignment) = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT);
  31. - PE_OHDR (o32, o64, image_size) = grub_host_to_target32 (pe_size);
  32. - PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
  33. PE_OHDR (o32, o64, subsystem) = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
  34. /* Do these really matter? */
  35. @@ -1351,10 +1347,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
  36. PE_OHDR (o32, o64, heap_commit_size) = grub_host_to_target32 (0x10000);
  37. PE_OHDR (o32, o64, num_data_directories) = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
  38. - PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (reloc_addr);
  39. - PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (layout.reloc_size);
  40. /* The sections. */
  41. + PE_OHDR (o32, o64, code_base) = grub_host_to_target32 (header_size);
  42. + PE_OHDR (o32, o64, code_size) = grub_host_to_target32 (layout.exec_size);
  43. text_section = sections;
  44. strcpy (text_section->name, ".text");
  45. text_section->virtual_size = grub_host_to_target32 (layout.exec_size);
  46. @@ -1366,6 +1362,8 @@ grub_install_generate_image (const char *dir, const char *prefix,
  47. | GRUB_PE32_SCN_MEM_EXECUTE
  48. | GRUB_PE32_SCN_MEM_READ);
  49. + PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);
  50. +
  51. data_section = text_section + 1;
  52. strcpy (data_section->name, ".data");
  53. data_section->virtual_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
  54. @@ -1388,6 +1386,8 @@ grub_install_generate_image (const char *dir, const char *prefix,
  55. | GRUB_PE32_SCN_MEM_READ
  56. | GRUB_PE32_SCN_MEM_WRITE);
  57. + PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (reloc_addr);
  58. + PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (layout.reloc_size);
  59. reloc_section = mods_section + 1;
  60. strcpy (reloc_section->name, ".reloc");
  61. reloc_section->virtual_size = grub_host_to_target32 (layout.reloc_size);
  62. --
  63. 2.14.2