https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632
>From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross <tristan.r...@midstall.com> Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/4] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { + resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" + "i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); - bool IsWinCOFF = - getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); + bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross <tristan.r...@midstall.com> Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/4] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template <typename Target> class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, - MacroBuilder &Builder) const override {} + MacroBuilder &Builder) const override { + DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From a9fb7e7b26ef375a2a8e2e920f5fcd696d5cf4fc Mon Sep 17 00:00:00 2001 From: Tristan Ross <tristan.r...@midstall.com> Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/4] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..e0693df72180d9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,11 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// AARCH64-UEFI: #define __uefi__ 1 +// +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// X86-64-UEFI: #define __uefi__ 1 >From 905d34693b2f0aebd2a54e6e3b82dc81c22b7210 Mon Sep 17 00:00:00 2001 From: Tristan Ross <tristan.r...@midstall.com> Date: Thu, 19 Dec 2024 13:51:08 -0800 Subject: [PATCH 4/4] [clang] add missing uefi support to aarch64 --- clang/lib/Basic/Targets.cpp | 3 +++ clang/lib/Basic/Targets/AArch64.cpp | 12 ++++++++++++ clang/lib/Basic/Targets/AArch64.h | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..d1aacafe704dd7 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique<OpenBSDTargetInfo<AArch64leTargetInfo>>(Triple, Opts); + case llvm::Triple::UEFI: + return std::make_unique<UEFIAArch64TargetInfo>(Triple, Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index dd5d033afd8763..94d99c0bb38f74 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1721,3 +1721,15 @@ TargetInfo::BuiltinVaListKind DarwinAArch64TargetInfo::getBuiltinVaListKind() const { return TargetInfo::CharPtrBuiltinVaList; } + +UEFIAArch64TargetInfo::UEFIAArch64TargetInfo(const llvm::Triple &Triple, + const TargetOptions &Opts) + : UEFITargetInfo<AArch64leTargetInfo>(Triple, Opts) { + TheCXXABI.set(TargetCXXABI::Microsoft); +} + +void UEFIAArch64TargetInfo::setDataLayout() { + assert(!getTriple().isOSBinFormatCOFF()); + resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" + "i64:64-i128:128-n32:64-S128-Fn32"); +} diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index 68a8b1ebad8cde..fc5d5b27aa0068 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -318,6 +318,16 @@ class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo MacroBuilder &Builder) const override; }; +class LLVM_LIBRARY_VISIBILITY UEFIAArch64TargetInfo + : public UEFITargetInfo<AArch64leTargetInfo> { + const llvm::Triple Triple; +public: + UEFIAArch64TargetInfo(const llvm::Triple &Triple, + const TargetOptions &Opts); + + void setDataLayout() override; +}; + } // namespace targets } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits