Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -malign-double to IA32 compiler flags #516

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

nicholasbishop
Copy link
Contributor

This changes the alignment of UINT64 data to 8 bytes on IA32, which matches EDK2's understanding of alignment. In particular this change affects the offset where shim writes EFI_LOADED_IMAGE.ImageSize.

Fixes #515

Signed-off-by: Nicholas Bishop nicholasbishop@google.com

This changes the alignment of UINT64 data to 8 bytes on IA32, which
matches EDK2's understanding of alignment. In particular this change
affects the offset where shim writes `EFI_LOADED_IMAGE.ImageSize`.

Fixes rhboot#515

Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
@vathpela vathpela merged commit 0cf43ac into rhboot:main Nov 14, 2022
bluca pushed a commit to systemd/systemd that referenced this pull request Apr 11, 2023
On x86 EFI follows the windows ABI, which expects 8-byte aligned long
long. The x86 sysv ELF ABI expects them to be 8-byte aligned when used
alone, but 4-byte aligned when they appear inside of structs:

    struct S {
        int i;
        long long ll;
    };

    // _Static_assert(sizeof(struct S) == 12, "x86 sysv ABI");
    _Static_assert(sizeof(struct S) == 16, "EFI/MS ABI");

To get the behavior we need when building with sysv ELF ABI we need to
pass '-malign-double' to the compiler as done by EDK2.

This in turn will make ubsan unhappy as the stack may not be properly
aligned on entry, so we have to tell the compiler explicitly to re-align
the stack on entry to efi_main.

This fixes loading EFI drivers on x86 that were previously always
rejected as the EFI_LOADED_IMAGE_PROTOCOL had a wrong memory layout.

See also: rhboot/shim#516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Second-stage's loaded image ImageSize is wrong on IA32
3 participants