[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@google.com>
This commit is contained in:
Prabhu Rajasekaran
2025-04-30 10:07:57 -07:00
committed by GitHub
parent 8e4dd21e63
commit 6274cdb9a6
5 changed files with 23 additions and 2 deletions

View File

@@ -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

View File

@@ -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");
}

View File

@@ -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:

View File

@@ -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))

View File

@@ -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