[clang] 6274cdb - [clang] Fix UEFI Target info (#127290)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 30 10:08:01 PDT 2025
Author: Prabhu Rajasekaran
Date: 2025-04-30T10:07:57-07:00
New Revision: 6274cdb9a6714908c8a4e30d2ef0bf22a6949065
URL: https://github.com/llvm/llvm-project/commit/6274cdb9a6714908c8a4e30d2ef0bf22a6949065
DIFF: https://github.com/llvm/llvm-project/commit/6274cdb9a6714908c8a4e30d2ef0bf22a6949065.diff
LOG: [clang] Fix UEFI Target info (#127290)
For X64 UEFI targets set appropriate integer type sizes, and relevant
ABI information.
---------
Co-authored-by: Petr Hosek <phosek at google.com>
Added:
Modified:
clang/include/clang/Basic/TargetOSMacros.def
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Preprocessor/init.c
Removed:
################################################################################
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/X86.h b/clang/lib/Basic/Targets/X86.h
index bc8d60f592548..194f3faef1be3 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -837,8 +837,23 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
public:
UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) {
+ // The UEFI spec does not mandate specific C++ ABI, integer widths, or
+ // alignment. We are setting these defaults to match the Windows target as
+ // it is the only way to build EFI applications with Clang/LLVM today. We
+ // intend to offer flexibility by supporting choices that are not default in
+ // Windows target in the future.
this->TheCXXABI.set(TargetCXXABI::Microsoft);
- this->MaxTLSAlign = 8192u * this->getCharWidth();
+ LongWidth = LongAlign = 32;
+ DoubleAlign = LongLongAlign = 64;
+ LongDoubleWidth = LongDoubleAlign = 64;
+ LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+ IntMaxType = SignedLongLong;
+ Int64Type = SignedLongLong;
+ SizeType = UnsignedLongLong;
+ PtrDiffType = SignedLongLong;
+ IntPtrType = SignedLongLong;
+ WCharType = UnsignedShort;
+ WIntType = UnsignedShort;
this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
}
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f0ce4625c1921..242eaec8f2bda 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -267,6 +267,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
: X86AVXABILevel::None);
switch (Triple.getOS()) {
+ case llvm::Triple::UEFI:
case llvm::Triple::Win32:
return createWinX86_64TargetCodeGenInfo(CGM, AVXLevel);
default:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 762f8af886920..3ff35c1577450 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5977,7 +5977,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// We turn strict aliasing off by default if we're Windows MSVC since MSVC
// doesn't do any TBAA.
if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
- options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
+ options::OPT_fno_strict_aliasing,
+ !IsWindowsMSVC && !IsUEFI))
CmdArgs.push_back("-relaxed-aliasing");
if (Args.hasFlag(options::OPT_fno_pointer_tbaa, options::OPT_fpointer_tbaa,
false))
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 1ac325d444662..4c8d519c2b664 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2835,6 +2835,7 @@
// 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=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
// UEFI: #define __UEFI__ 1
More information about the cfe-commits
mailing list