Skip to content

Commit 6274cdb

Browse files
Prabhukpetrhosek
andauthored
[clang] Fix UEFI Target info (#127290)
For X64 UEFI targets set appropriate integer type sizes, and relevant ABI information. --------- Co-authored-by: Petr Hosek <[email protected]>
1 parent 8e4dd21 commit 6274cdb

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

clang/include/clang/Basic/TargetOSMacros.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
5353
TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
5454
TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
5555

56+
// UEFI target.
57+
TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI())
58+
5659
#undef TARGET_OS

clang/lib/Basic/Targets/X86.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,23 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
837837
public:
838838
UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
839839
: UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) {
840+
// The UEFI spec does not mandate specific C++ ABI, integer widths, or
841+
// alignment. We are setting these defaults to match the Windows target as
842+
// it is the only way to build EFI applications with Clang/LLVM today. We
843+
// intend to offer flexibility by supporting choices that are not default in
844+
// Windows target in the future.
840845
this->TheCXXABI.set(TargetCXXABI::Microsoft);
841-
this->MaxTLSAlign = 8192u * this->getCharWidth();
846+
LongWidth = LongAlign = 32;
847+
DoubleAlign = LongLongAlign = 64;
848+
LongDoubleWidth = LongDoubleAlign = 64;
849+
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
850+
IntMaxType = SignedLongLong;
851+
Int64Type = SignedLongLong;
852+
SizeType = UnsignedLongLong;
853+
PtrDiffType = SignedLongLong;
854+
IntPtrType = SignedLongLong;
855+
WCharType = UnsignedShort;
856+
WIntType = UnsignedShort;
842857
this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
843858
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
844859
}

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
267267
: X86AVXABILevel::None);
268268

269269
switch (Triple.getOS()) {
270+
case llvm::Triple::UEFI:
270271
case llvm::Triple::Win32:
271272
return createWinX86_64TargetCodeGenInfo(CGM, AVXLevel);
272273
default:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5977,7 +5977,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59775977
// We turn strict aliasing off by default if we're Windows MSVC since MSVC
59785978
// doesn't do any TBAA.
59795979
if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
5980-
options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
5980+
options::OPT_fno_strict_aliasing,
5981+
!IsWindowsMSVC && !IsUEFI))
59815982
CmdArgs.push_back("-relaxed-aliasing");
59825983
if (Args.hasFlag(options::OPT_fno_pointer_tbaa, options::OPT_fpointer_tbaa,
59835984
false))

clang/test/Preprocessor/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,7 @@
28352835
// RISCV64-LINUX: #define unix 1
28362836

28372837
// RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
2838+
// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
28382839

28392840
// UEFI: #define __UEFI__ 1
28402841

0 commit comments

Comments
 (0)