-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang][uefi] add arm, aarch64, x86, loongarch64, riscv64 targets #136247
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
base: main
Are you sure you want to change the base?
[clang][uefi] add arm, aarch64, x86, loongarch64, riscv64 targets #136247
Conversation
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-clang Author: Tristan Ross (RossComputerGuy) ChangesAdds the rest of the targets which support UEFI according to the spec. Full diff: https://github.com/llvm/llvm-project/pull/136247.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def
index 58dce330f9c8f..f4f3276ad1c25 100644
--- a/clang/include/clang/Basic/TargetOSMacros.def
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
+// UEFI target.
+TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI())
+
#undef TARGET_OS
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index c6d228fe98100..0502d99a20e4f 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -164,6 +164,11 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<OHOSTargetInfo<AArch64leTargetInfo>>(Triple,
Opts);
}
+
+ case llvm::Triple::UEFI:
+ return std::make_unique<UEFITargetInfo<AArch64leTargetInfo>>(Triple,
+ Opts);
+
case llvm::Triple::NetBSD:
return std::make_unique<NetBSDTargetInfo<AArch64leTargetInfo>>(Triple,
Opts);
@@ -227,6 +232,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<HaikuTargetInfo<ARMleTargetInfo>>(Triple, Opts);
case llvm::Triple::NaCl:
return std::make_unique<NaClTargetInfo<ARMleTargetInfo>>(Triple, Opts);
+ case llvm::Triple::UEFI:
+ return std::make_unique<UEFITargetInfo<ARMleTargetInfo>>(Triple, Opts);
case llvm::Triple::Win32:
switch (Triple.getEnvironment()) {
case llvm::Triple::Cygnus:
@@ -457,6 +464,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::Haiku:
return std::make_unique<HaikuTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::UEFI:
+ return std::make_unique<UEFITargetInfo<RISCV64TargetInfo>>(Triple, Opts);
case llvm::Triple::Linux:
switch (Triple.getEnvironment()) {
default:
@@ -569,6 +578,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::Solaris:
return std::make_unique<SolarisTargetInfo<X86_32TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::UEFI:
+ return std::make_unique<UEFITargetInfo<X86_32TargetInfo>>(Triple, Opts);
case llvm::Triple::Win32: {
switch (Triple.getEnvironment()) {
case llvm::Triple::Cygnus:
@@ -760,6 +771,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::UEFI:
+ return std::make_unique<UEFITargetInfo<LoongArch64TargetInfo>>(Triple,
+ Opts);
default:
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
}
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 1ac325d444662..55a7340deba24 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2835,6 +2835,11 @@
// RISCV64-LINUX: #define unix 1
// RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=armv7l-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=loongarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=riscv64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
// UEFI: #define __UEFI__ 1
|
427b22a
to
b601bb7
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
c94d5d0
to
bede2c6
Compare
2 targets have complications which require non-trivial backend work:
There's 3 options:
|
@@ -352,6 +352,8 @@ static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI, | |||
MAI = new AArch64MCAsmInfoMicrosoftCOFF(); | |||
else if (TheTriple.isOSBinFormatCOFF()) | |||
MAI = new AArch64MCAsmInfoGNUCOFF(); | |||
else if (TheTriple.isUEFI()) | |||
MAI = new AArch64MCAsmInfoGNUCOFF(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be using GNU COFF for UEFI, we should be using Microsoft COFF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, why does x86 use it?
llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
Lines 455 to 456 in ee4c8b5
} else if (TheTriple.isUEFI()) { | |
MAI = new X86MCAsmInfoGNUCOFF(TheTriple); |
Is it because of the win64 calling convention?
bede2c6
to
31d6ee2
Compare
Adds the rest of the targets which support UEFI according to the spec.
To test:
Check these files exist:
build/install/lib/aarch64-unknown-uefi-llvm/libc.a
build/install/lib/x86_64-unknown-uefi-llvm/libc.a
build/install/lib/loongarch64-unknown-uefi-llvm/libc.a
build/install/lib/riscv64-unknown-uefi-llvm/libc.a