efi_loader: fix SectionAlignment, FileAlignment
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 14 Jan 2022 20:40:15 +0000 (21:40 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 15 Jan 2022 09:57:22 +0000 (10:57 +0100)
The alignment of sections in the EFI binaries generated by U-Boot is
incorrect.

According to the PE-COFF specification [1] the minimum value for
FileAlignment is 512. If the value of SectionAlignment is
less then the page size, it must equal FileAlignment.

Let's set both values to 512 for the ARM and RISC-V architectures.

[1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
arch/arm/lib/crt0_aarch64_efi.S
arch/arm/lib/crt0_arm_efi.S
arch/arm/lib/elf_aarch64_efi.lds
arch/arm/lib/elf_arm_efi.lds
arch/riscv/lib/crt0_riscv_efi.S
arch/riscv/lib/elf_riscv32_efi.lds
arch/riscv/lib/elf_riscv64_efi.lds

index 492195f7654f4da5ea9d463585559cf4669b7c30..7f38465359c7d1f50641183b3b2a801619b85bd3 100644 (file)
@@ -47,8 +47,8 @@ optional_header:
 
 extra_header_fields:
        .quad   0                               /* ImageBase */
-       .long   0x20                            /* SectionAlignment */
-       .long   0x8                             /* FileAlignment */
+       .long   0x200                           /* SectionAlignment */
+       .long   0x200                           /* FileAlignment */
        .short  0                               /* MajorOperatingSystemVersion */
        .short  0                               /* MinorOperatingSystemVersion */
        .short  0                               /* MajorImageVersion */
@@ -117,6 +117,7 @@ section_table:
        .short  0               /* NumberOfLineNumbers  (0 for executables) */
        .long   0xe0500020      /* Characteristics (section flags) */
 
+       .align          9
 _start:
        stp             x29, x30, [sp, #-32]!
        mov             x29, sp
index cc8a115f319c9f0f9c5305331dc452324d6bb8c1..75ee37b7d31bc0ee3c218309eaf75967ce4a518d 100644 (file)
@@ -47,8 +47,8 @@ optional_header:
 
 extra_header_fields:
        .long   0                               /* image_base */
-       .long   0x20                            /* SectionAlignment */
-       .long   0x8                             /* FileAlignment */
+       .long   0x200                           /* SectionAlignment */
+       .long   0x200                           /* FileAlignment */
        .short  0                               /* MajorOperatingSystemVersion */
        .short  0                               /* MinorOperatingSystemVersion */
        .short  0                               /* MajorImageVersion */
@@ -115,6 +115,7 @@ section_table:
        .short  0               /* NumberOfLineNumbers  (0 for executables) */
        .long   0xe0500020      /* Characteristics (section flags) */
 
+       .align          9
 _start:
        stmfd           sp!, {r0-r2, lr}
 
index 90af469f48b9ea0f1e2af520e541c44f5ce04eb3..c0604dad464dab789faa1529a9f126227495e724 100644 (file)
@@ -18,7 +18,7 @@ SECTIONS
                *(.gnu.linkonce.t.*)
                *(.srodata)
                *(.rodata*)
-               . = ALIGN(16);
+               . = ALIGN(512);
        }
        _etext = .;
        _text_size = . - _text;
@@ -44,7 +44,7 @@ SECTIONS
                *(.bss)
                *(.bss.*)
                *(COMMON)
-               . = ALIGN(16);
+               . = ALIGN(512);
                _bss_end = .;
                _edata = .;
        }
index d6d742e8687ba74598ed02c310b8ad4e387690e6..767ebda6351b5463ecb1958b8a791ccd58dc708b 100644 (file)
@@ -18,7 +18,7 @@ SECTIONS
                *(.gnu.linkonce.t.*)
                *(.srodata)
                *(.rodata*)
-               . = ALIGN(16);
+               . = ALIGN(512);
        }
        _etext = .;
        _text_size = . - _text;
@@ -44,7 +44,7 @@ SECTIONS
                *(.bss)
                *(.bss.*)
                *(COMMON)
-               . = ALIGN(16);
+               . = ALIGN(512);
                _bss_end = .;
                _edata = .;
        }
index 3e62e8e67b0fb2549025bcf877583255e5904f50..a01e08a3c6d33fad37cdf8bad3584f619733a8a9 100644 (file)
@@ -71,8 +71,8 @@ extra_header_fields:
 #else
        .quad   0                               /* ImageBase */
 #endif
-       .long   0x20                            /* SectionAlignment */
-       .long   0x8                             /* FileAlignment */
+       .long   0x200                           /* SectionAlignment */
+       .long   0x200                           /* FileAlignment */
        .short  0                               /* MajorOperatingSystemVersion */
        .short  0                               /* MinorOperatingSystemVersion */
        .short  1                               /* MajorImageVersion */
@@ -148,6 +148,7 @@ section_table:
        .short  0               /* NumberOfLineNumbers  (0 for executables) */
        .long   0xe0500020      /* Characteristics (section flags) */
 
+       .align  9
 _start:
        addi            sp, sp, -(SIZE_LONG * 3)
        SAVE_LONG(a0, 0)
index 629705fc2800ab0575d47cf1eaeaeeffc77fd645..c3e0d20d5774e955995d8068ccebca9cd974d984 100644 (file)
@@ -20,7 +20,7 @@ SECTIONS
                *(.gnu.linkonce.t.*)
                *(.srodata)
                *(.rodata*)
-               . = ALIGN(16);
+               . = ALIGN(512);
        }
        _etext = .;
        _text_size = . - _text;
@@ -46,7 +46,7 @@ SECTIONS
                *(.bss)
                *(.bss.*)
                *(COMMON)
-               . = ALIGN(16);
+               . = ALIGN(512);
                _bss_end = .;
                _edata = .;
        }
index aece030c37b52599e1f2fdcf21853d75633add63..ecb91395486d12635605913a04fdb7aaec721568 100644 (file)
@@ -20,7 +20,7 @@ SECTIONS
                *(.gnu.linkonce.t.*)
                *(.srodata)
                *(.rodata*)
-               . = ALIGN(16);
+               . = ALIGN(512);
        }
        _etext = .;
        _text_size = . - _text;
@@ -46,7 +46,7 @@ SECTIONS
                *(.bss)
                *(.bss.*)
                *(COMMON)
-               . = ALIGN(16);
+               . = ALIGN(512);
                _bss_end = .;
                _edata = .;
        }