[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 10:36:24 PST 2024


https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/111719

>From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 9 Oct 2024 10:16:58 -0700
Subject: [PATCH 1/3] [clang] Introduce a new UEFI target predefine.

---
 clang/lib/Basic/Targets/OSTargets.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..92c76b303def65 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,10 @@ 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 {
+    Builder.defineMacro("__UEFI__");
+    Builder.defineMacro("__PECOFF__");
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001
From: Prabhuk <prabhukrllvm at gmail.com>
Date: Wed, 13 Nov 2024 10:30:50 -0800
Subject: [PATCH 2/3] Update OSTargets.h

Remove PE_COFF
---
 clang/lib/Basic/Targets/OSTargets.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 92c76b303def65..5a23eef0117294 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     MacroBuilder &Builder) const override {
     Builder.defineMacro("__UEFI__");
-    Builder.defineMacro("__PECOFF__");
   }
 
 public:

>From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001
From: Prabhuk <prabhukrllvm at gmail.com>
Date: Wed, 13 Nov 2024 10:36:15 -0800
Subject: [PATCH 3/3] add __UEFI__ to windows predefines

Updating the PE COFF generating windows code path to predefine the new __UEFI__ macro.
---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..b9edeefa60148e 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
                        MacroBuilder &Builder) {
+  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
     Builder.defineMacro("_WIN64");



More information about the cfe-commits mailing list