https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/124992
UEFI targets for X86_64 architecture must use appropriate mangling, calling convention and integer size schemes. >From 666e3cf583979789ca86e8e6a2dfc6ee28c1487b Mon Sep 17 00:00:00 2001 From: prabhukr <prabh...@google.com> Date: Wed, 29 Jan 2025 21:47:05 +0000 Subject: [PATCH] [clang] UEFI ABI fixes for X86_64 UEFI targets for X86_64 architecture must use appropriate mangling, calling convention and integer size schemes. --- clang/lib/AST/Mangle.cpp | 2 +- clang/lib/Basic/Targets/X86.h | 11 +++++++++++ clang/lib/Driver/ToolChains/Arch/X86.cpp | 2 +- clang/lib/Sema/SemaChecking.cpp | 10 +++++----- clang/lib/Sema/SemaDeclAttr.cpp | 8 ++++---- clang/lib/Sema/SemaExpr.cpp | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 15be9c62bf8880..a46bc3068cb797 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -74,7 +74,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context, if (FD->isMain() && FD->getNumParams() == 2) return CCM_WasmMainArgcArgv; - if (!Triple.isOSWindows() || !Triple.isX86()) + if (!Triple.isOSWindowsOrUEFI() || !Triple.isX86()) return CCM_Other; if (Context.getLangOpts().CPlusPlus && !isExternC(ND) && diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 8bd54e362526fb..e7faecbd0c01bd 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -835,6 +835,17 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo public: UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) { + LongWidth = LongAlign = 32; + DoubleAlign = LongLongAlign = 64; + IntMaxType = SignedLongLong; + Int64Type = SignedLongLong; + SizeType = UnsignedLongLong; + PtrDiffType = SignedLongLong; + IntPtrType = SignedLongLong; + LongDoubleWidth = LongDoubleAlign = 64; + LongDoubleFormat = &llvm::APFloat::IEEEdouble(); + WCharType = UnsignedShort; + WIntType = UnsignedShort; this->TheCXXABI.set(TargetCXXABI::Microsoft); this->MaxTLSAlign = 8192u * this->getCharWidth(); this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index b2109e11038fe8..1e83db63c3dc35 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -122,7 +122,7 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, // Claim and report unsupported -mabi=. Note: we don't support "sysv_abi" or // "ms_abi" as default function attributes. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mabi_EQ)) { - StringRef DefaultAbi = Triple.isOSWindows() ? "ms" : "sysv"; + StringRef DefaultAbi = Triple.isOSWindowsOrUEFI() ? "ms" : "sysv"; if (A->getValue() != DefaultAbi) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getSpelling() << Triple.getTriple(); diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 61b2c8cf1cad72..36d910cef9307b 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4751,7 +4751,7 @@ static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { bool IsX64 = TT.getArch() == llvm::Triple::x86_64; bool IsAArch64 = (TT.getArch() == llvm::Triple::aarch64 || TT.getArch() == llvm::Triple::aarch64_32); - bool IsWindows = TT.isOSWindows(); + bool IsWindowsOrUEFI = TT.isOSWindowsOrUEFI(); bool IsMSVAStart = BuiltinID == Builtin::BI__builtin_ms_va_start; if (IsX64 || IsAArch64) { CallingConv CC = CC_C; @@ -4759,7 +4759,7 @@ static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { CC = FD->getType()->castAs<FunctionType>()->getCallConv(); if (IsMSVAStart) { // Don't allow this in System V ABI functions. - if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_Win64)) + if (CC == CC_X86_64SysV || (!IsWindowsOrUEFI && CC != CC_Win64)) return S.Diag(Fn->getBeginLoc(), diag::err_ms_va_start_used_in_sysv_function); } else { @@ -4767,11 +4767,11 @@ static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { // On x64 Windows, don't allow this in System V ABI functions. // (Yes, that means there's no corresponding way to support variadic // System V ABI functions on Windows.) - if ((IsWindows && CC == CC_X86_64SysV) || - (!IsWindows && CC == CC_Win64)) + if ((IsWindowsOrUEFI && CC == CC_X86_64SysV) || + (!IsWindowsOrUEFI && CC == CC_Win64)) return S.Diag(Fn->getBeginLoc(), diag::err_va_start_used_in_wrong_abi_function) - << !IsWindows; + << !IsWindowsOrUEFI; } return false; } diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 9d7d22590bce4b..35425297f307f3 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5193,12 +5193,12 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC, CC = CC_X86RegCall; break; case ParsedAttr::AT_MSABI: - CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C : - CC_Win64; + CC = Context.getTargetInfo().getTriple().isOSWindowsOrUEFI() ? CC_C + : CC_Win64; break; case ParsedAttr::AT_SysVABI: - CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV : - CC_C; + CC = Context.getTargetInfo().getTriple().isOSWindowsOrUEFI() ? CC_X86_64SysV + : CC_C; break; case ParsedAttr::AT_Pcs: { StringRef StrRef; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ba4aaa94b90ffd..e15fdfe2c09f1b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17980,7 +17980,7 @@ static bool funcHasParameterSizeMangling(Sema &S, FunctionDecl *FD) { // These manglings don't do anything on non-Windows or non-x86 platforms, so // we don't need parameter type sizes. const llvm::Triple &TT = S.Context.getTargetInfo().getTriple(); - if (!TT.isOSWindows() || !TT.isX86()) + if (!TT.isOSWindowsOrUEFI() || !TT.isX86()) return false; // If this is C++ and this isn't an extern "C" function, parameters do not _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits