x86/boot: Increase section and file alignment to 4k/512
authorArd Biesheuvel <ardb@kernel.org>
Fri, 15 Sep 2023 17:16:32 +0000 (17:16 +0000)
committerIngo Molnar <mingo@kernel.org>
Sun, 17 Sep 2023 17:48:44 +0000 (19:48 +0200)
commit3e3eabe26dc88692d34cf76ca0e0dd331481cc15
tree3da19d289431fd3d32f26870eece7d7d208b792e
parent34951f3c28bdf6481d949a20413b2ce7693687b2
x86/boot: Increase section and file alignment to 4k/512

Align x86 with other EFI architectures, and increase the section
alignment to the EFI page size (4k), so that firmware is able to honour
the section permission attributes and map code read-only and data
non-executable.

There are a number of requirements that have to be taken into account:
- the sign tools get cranky when there are gaps between sections in the
  file view of the image
- the virtual offset of each section must be aligned to the image's
  section alignment
- the file offset *and size* of each section must be aligned to the
  image's file alignment
- the image size must be aligned to the section alignment
- each section's virtual offset must be greater than or equal to the
  size of the headers.

In order to meet all these requirements, while avoiding the need for
lots of padding to accommodate the .compat section, the latter is placed
at an arbitrary offset towards the end of the image, but aligned to the
minimum file alignment (512 bytes). The space before the .text section
is therefore distributed between the PE header, the .setup section and
the .compat section, leaving no gaps in the file coverage, making the
signing tools happy.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230915171623.655440-18-ardb@google.com
arch/x86/boot/compressed/vmlinux.lds.S
arch/x86/boot/header.S
arch/x86/boot/setup.ld
arch/x86/boot/tools/build.c