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

Use LLVM's UEFI targets #132570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Use LLVM's UEFI targets #132570

wants to merge 1 commit into from

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Nov 3, 2024

The UEFI targets previously passed Windows targets to LLVM, because that's what they're the most similar to.

That's not ideal though (part of this problem was analyzed in #64334), but it seems like LLVM has gained support for UEFI in-tree, so we should probably just use that?

Unresolved is whether the linker flags /entry:efi_main /subsystem:efi_application are still needed, or if such details are handled by LLVM/LLD nowadays automatically?

Note that I am only opening this because it causes issues for cc when trying to pass that target name to LLVM, I have no idea if this is actually correct, and it's completely untested!

CC target maintainers @dvdhrm @nicholasbishop
@rustbot label O-uefi

@rustbot
Copy link
Collaborator

rustbot commented Nov 3, 2024

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 3, 2024

These commits modify compiler targets.
(See the Target Tier Policy.)

@workingjubilee
Copy link
Member

cc @Ayush1325

@rust-log-analyzer

This comment has been minimized.

The UEFI targets previously passed Windows targets to LLVM, because
that's what they're the most similar to.

That's not ideal though (part of this problem was analyzed in 21e062d),
but it seems like LLVM has since the introduction of these targets
gained support for UEFI in-tree, so we should just use that:
https://discourse.llvm.org/t/rfc-uefi-driver-support-uefi-target/73261
Comment on lines 34 to +35
data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32"
i128:128-f64:32:64-f80:32-n8:16:32-S128"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running ./x test tests/assembly/targets/targets-pe.rs shows that the data layout for our i686-unknown-uefi, for it to match Clang's i686-unknown-uefi, should have the following modifications:

  • Remove i64:64: Decreases the alignment of i64 to 32 bits.
  • Add f64:32:64: Decreases the alignment of f64 to 32 bits.
  • Remove a:0:32: Decreases the alignment of aggregates (structs?) to 32 bits.
  • Replace S32 with S128: Increases the natural alignment of the stack to 128 bits.

I have no idea if this is the desired behaviour?

Copy link
Contributor

@nicholasbishop nicholasbishop Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove i64:64: Decreases the alignment of i64 to 32 bits.
Add f64:32:64: Decreases the alignment of f64 to 32 bits.

These I think are not desirable. Edk2 sets -malign-double for ia32 in https://github.com/tianocore/edk2/blob/HEAD/BaseTools/Conf/tools_def.template. So while the UEFI spec isn't super clear on what the alignment for double and long long should be on ia32, the de facto alignment is 8 bytes.

See rhboot/shim#516 for a real-world example where this makes a difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we file a bug against LLVM, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if @nicholasbishop did it, you seem more knowledgeable about it - but I can try to do it if you don't have the time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a quick sanity check of compiling C code with these triples, and I suspect this isn't fully implemented in clang yet (tested 19.1.0). Getting errors like: error: backend data layout 'e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128' does not match expected target description 'e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128'.

I think the implementation work in LLVM is ongoing, so not quite ready for us to use yet. @Prabhuk can you confirm that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking from edk2 is definitely not desirable. From what I understand, even most of the proprietary UEFI implementations use edk2 as the base.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the slow response! I am on vacation till mid November. I have a WIP backend patch (llvm/llvm-project#109320) to support X86_64 first. I am debugging a assertion failure I ran into while compiling a downstream EFI example. I will prioritize upstreaming fixing it and sending out a PR as soon as I return. aarch64 will be next. w.r.t to data layout, I need to look at a closer look once I return before commenting.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@workingjubilee workingjubilee added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-UEFI UEFI S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants