• Ard Biesheuvel's avatar
    x86/boot: Increase section and file alignment to 4k/512 · 3e3eabe2
    Ard Biesheuvel authored
    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: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20230915171623.655440-18-ardb@google.com
    3e3eabe2
build.c 7.52 KB