[PATCH v2 4/5] efi_loader: correct SizeOfCode, SizeOfInitializedData
Ilias Apalodimas
ilias.apalodimas at linaro.org
Fri Jan 17 10:19:14 CET 2025
On Thu, 16 Jan 2025 at 13:39, Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> 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
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> v2:
> new patch
> ---
> arch/arm/lib/crt0_aarch64_efi.S | 2 +-
> arch/arm/lib/crt0_arm_efi.S | 4 ++--
> arch/riscv/lib/crt0_riscv_efi.S | 4 ++--
> 3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
> index fe6eca576ec..e21b54fdbcb 100644
> --- a/arch/arm/lib/crt0_aarch64_efi.S
> +++ b/arch/arm/lib/crt0_aarch64_efi.S
> @@ -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 */
> diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
> index b5dfd4e3819..3664cce8412 100644
> --- a/arch/arm/lib/crt0_arm_efi.S
> +++ b/arch/arm/lib/crt0_arm_efi.S
> @@ -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 */
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index c7a4559eac8..9eacbe4a859 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -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 */
> --
> 2.47.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
More information about the U-Boot
mailing list