This is an archive of the discontinued LLVM Phabricator instance.

[Triple] Add triple for UEFI
ClosedPublic

Authored by Prabhuk on Aug 10 2022, 9:48 AM.

Details

Summary

Target triple to support "x86_64-unknown-uefi"

Diff Detail

Event Timeline

Prabhuk created this revision.Aug 10 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 9:48 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Prabhuk requested review of this revision.Aug 10 2022, 9:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 10 2022, 9:48 AM
phosek added a subscriber: phosek.Aug 15 2022, 3:02 PM
phosek added inline comments.
clang/lib/Basic/Targets.cpp
644

What does this comment refer to?

clang/lib/Basic/Targets/OSTargets.h
919

I'd start with only necessary minimum and add more later if needed. Initially we probably only need a define to identify this target, likely __UEFI__.

Prabhuk updated this revision to Diff 468370.Oct 17 2022, 4:53 PM

Added changes to the Driver.cpp.
This version uses underlying MSVC toolchain to compile UEFI target introduced here.

Prabhuk updated this revision to Diff 468595.Oct 18 2022, 9:45 AM

Introducing UEFIX86_64TargetInfo.

Prabhuk updated this revision to Diff 468600.Oct 18 2022, 9:50 AM

Add UEFI macro.

phosek added inline comments.Oct 18 2022, 3:10 PM
clang/lib/Basic/Targets/X86.h
839–855

According to https://wiki.osdev.org/UEFI#Calling_Conventions, only cdecl, Microsoft's 64-bit calling convention and ARM SMC are supported for UEFI. This would translate to CC_C and CC_Win64 (I'm not sure if SMC is supported by Clang, it doesn't appear to be).

Prabhuk updated this revision to Diff 477622.Nov 23 2022, 3:09 PM
Prabhuk marked an inline comment as done.

Introducing a new toolchain for UEFI COFF.

Prabhuk updated this revision to Diff 477634.Nov 23 2022, 3:37 PM
Prabhuk marked an inline comment as done.

Added tests to the new UEFI target.

Prabhuk marked an inline comment as done.Nov 23 2022, 3:40 PM
phosek added inline comments.Jan 3 2023, 2:54 PM
clang/lib/Driver/ToolChains/UEFI.cpp
42–46

I'd hardcode and inline this for simplicity, this toolchain is only used for x86_64 and arm64 right now so now need to duplicate that here.

49–50

I'd hardcode and inline this for simplicity, this toolchain is only used for x86_64 and arm64 right now so now need to duplicate that here.

53

I'd inline this.

56–57

I'd hardcode and inline this for simplicity, this toolchain is only used for x86_64 and arm64 right now so now need to duplicate that here.

60

I'd inline this.

clang/lib/Driver/ToolChains/UEFI.h
23
29

You'll also need to override buildLinker since the default implementation doesn't do anything, see https://github.com/llvm/llvm-project/blob/46dee4a3a3dfb372a0eaa0b4490c80be2f421f29/clang/lib/Driver/ToolChain.cpp#L319

I'd hardcode it to use lld-link for simplicty. You can use Fuchsia's implementation for inspiration (although the flags are going to be different since Fuchsia uses ld.lld, not lld-link):

https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Fuchsia.h#L17-L34
https://github.com/llvm/llvm-project/blob/609b789170625277f631139c790c22d527ff1eed/clang/lib/Driver/ToolChains/Fuchsia.cpp#L31-L191

Prabhuk updated this revision to Diff 522644.May 16 2023, 8:37 AM

Added UEFI toolchain. Constructing linker and started a WIP UEFI toolchain to break away from MSVC toolchain.

Prabhuk updated this revision to Diff 522657.May 16 2023, 9:13 AM

Not ready for review yet. Updating build files and tests.
Fixed a compile time error.

Prabhuk updated this revision to Diff 522680.May 16 2023, 10:03 AM

Use make_unique instead of new for UEFI TargetInfo.

Prabhuk updated this revision to Diff 522714.May 16 2023, 11:03 AM

Addressing Petr's comments. Adding buildLinker initial draft for UEFI.

Prabhuk updated this revision to Diff 528064.Jun 2 2023, 6:46 PM

Simplifying the patch to include just the scaffolding for X86_64 platform.
Removing the predefines to be added as a separate patch.

I'd split the llvm/ changes into a separate change.

clang/lib/Driver/ToolChains/UEFI.cpp
59–60

I don't think these should be needed for UEFI targets.

llvm/test/ExecutionEngine/RuntimeDyld/X86/coff-alignment.ll
4 ↗(On Diff #528064)

Should this be uefi?

llvm/test/Instrumentation/InstrProfiling/profiling.ll
10 ↗(On Diff #528064)

Should this be uefi?

llvm/test/Transforms/PGOProfile/comdat_rename.ll
3 ↗(On Diff #528064)

Should this be uefi?

Prabhuk retitled this revision from WORK IN PROGRESS Add Clang UEFI target to support "x86_64-unknown-uefi" triple to Add Clang UEFI target to support "x86_64-unknown-uefi" triple.Jun 5 2023, 2:29 PM
phosek added a comment.Jun 5 2023, 2:54 PM

I'd omit the lit test cases for now since they're not necessary. There should be a test case in https://github.com/llvm/llvm-project/blob/86b6ac5d54d7fe5cd21beff64b5c2194b1368bdf/llvm/unittests/TargetParser/TripleTest.cpp though.

Prabhuk updated this revision to Diff 528603.Jun 5 2023, 3:23 PM

Update the test. Remove unnecessary items in UEFI toolchain.

Prabhuk updated this revision to Diff 528610.Jun 5 2023, 3:40 PM

Updated commit message.

Prabhuk retitled this revision from Add Clang UEFI target to support "x86_64-unknown-uefi" triple to [Triple] Add triple for UEFI.Jun 5 2023, 3:40 PM
phosek accepted this revision.Jun 5 2023, 11:49 PM
phosek added reviewers: rnk, hans, mstorsjo.

Can you also provide description for this change (this should be the same you'll use for the Git message).

llvm/include/llvm/MC/TargetRegistry.h
568

Nit: phrasing.

llvm/lib/MC/MCContext.cpp
90

Nit: update the error message.

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
1521

Nit: consistent case in assert messages.

This revision is now accepted and ready to land.Jun 5 2023, 11:50 PM
Prabhuk edited the summary of this revision. (Show Details)Jun 6 2023, 8:12 AM
This revision was landed with ongoing or failed builds.Jun 6 2023, 8:42 AM
This revision was automatically updated to reflect the committed changes.