Skip to content

[clang] Fix UEFI Target info #127290

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

Merged
merged 16 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/TargetOSMacros.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,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");
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5959,7 +5959,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))
Expand Down
1 change: 1 addition & 0 deletions clang/test/Preprocessor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down