[efi] Match signtool expectations for file alignment

As of commit f1e9e2b ("[efi] Align EFI image sections by page size"),
our SectionAlignment has been increased to 4kB in order to allow for
page-level memory protection to be applied by the UEFI firmware, with
FileAlignment left at 32 bytes.

The PE specification states that the value for FileAlignment "should
be a power of 2 between 512 and 64k, inclusive", and that "if the
SectionAlignment is less than the architecture's page size, then
FileAlignment must match SectionAlignment".

Testing shows that signtool.exe will reject binaries where
FileAlignment is less than 512, unless FileAlignment is equal to
SectionAlignment.  This indicates a somewhat zealous interpretation of
the word "should" in the PE specification.

Work around this interpretation by increasing FileAlignment from 32
bytes to 512 bytes, and add explanatory comments for both
FileAlignment and SectionAlignment.

Debugged-by: Andreas Hammarskjöld <junior@2PintSoftware.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/448/head
Michael Brown 2021-07-15 15:32:31 +01:00
parent 8d08300ad9
commit c64dfff0a9
1 changed files with 15 additions and 1 deletions

View File

@ -125,7 +125,21 @@
#define R_ARM_V4BX 40
#endif
#define EFI_FILE_ALIGN 0x20
/**
* Alignment of raw data of sections in the image file
*
* Some versions of signtool.exe will spuriously complain if this
* value is less than 512.
*/
#define EFI_FILE_ALIGN 0x200
/**
* Alignment of sections when loaded into memory
*
* This must equal the architecture page size, in order to allow for
* the possibility of the firmware using page-level protection to
* enforce section attributes at runtime.
*/
#define EFI_IMAGE_ALIGN 0x1000
struct elf_file {