efi_loader: correct SizeOfCode, SizeOfInitializedData
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 16 Jan 2025 11:39:08 +0000 (12:39 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 17 Jan 2025 19:31:26 +0000 (20:31 +0100)
The fields SizeOfCode, SizeOfInitializedData, and SizeOfUninitializedData
are define in the PE-COFF specification [1].

* SizeOfCode must match the size of all .text sections.
* SizeOfInitializedData must match the size of all .data sections.
* SizeOfUninitializedData must match the size of all .bss sections.

We only have one .text and one .data section. SizeOfCode and
SizeOfInitializedData have to be calculated as the difference between
the end and the start of the respective section.

As we don't have any .bss sections in the generated EFI binaries.
SizeOfUninitializedData must remain 0.

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

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
arch/arm/lib/crt0_aarch64_efi.S
arch/arm/lib/crt0_arm_efi.S
arch/riscv/lib/crt0_riscv_efi.S

index fe6eca5..e21b54f 100644 (file)
@@ -41,7 +41,7 @@ optional_header:
        .byte   0x02                            /* MajorLinkerVersion */
        .byte   0x14                            /* MinorLinkerVersion */
        .long   _etext - _start                 /* SizeOfCode */
-       .long   0                               /* SizeOfInitializedData */
+       .long   _data_size                      /* SizeOfInitializedData */
        .long   0                               /* SizeOfUninitializedData */
        .long   _start - ImageBase              /* AddressOfEntryPoint */
        .long   _start - ImageBase              /* BaseOfCode */
index b5dfd4e..3664cce 100644 (file)
@@ -38,8 +38,8 @@ optional_header:
        .short  IMAGE_NT_OPTIONAL_HDR32_MAGIC   /* PE32 format */
        .byte   0x02                            /* MajorLinkerVersion */
        .byte   0x14                            /* MinorLinkerVersion */
-       .long   _edata - _start                 /* SizeOfCode */
-       .long   0                               /* SizeOfInitializedData */
+       .long   _etext - _start                 /* SizeOfCode */
+       .long   _data_size                      /* SizeOfInitializedData */
        .long   0                               /* SizeOfUninitializedData */
        .long   _start - image_base             /* AddressOfEntryPoint */
        .long   _start - image_base             /* BaseOfCode */
index c7a4559..9eacbe4 100644 (file)
@@ -63,8 +63,8 @@ optional_header:
        .short  PE_MAGIC                        /* PE32(+) format */
        .byte   0x02                            /* MajorLinkerVersion */
        .byte   0x14                            /* MinorLinkerVersion */
-       .long   _edata - _start                 /* SizeOfCode */
-       .long   0                               /* SizeOfInitializedData */
+       .long   _etext - _start                 /* SizeOfCode */
+       .long   _data_size                      /* SizeOfInitializedData */
        .long   0                               /* SizeOfUninitializedData */
        .long   _start - ImageBase              /* AddressOfEntryPoint */
        .long   _start - ImageBase              /* BaseOfCode */