[clang] [libcxx] [clang][driver] Cleanup UEFI toolchain driver (PR #111473)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 10:05:44 PDT 2024
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/111473
>From 9b55509827b25fda48bdb8e2322259415c01e206 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 7 Oct 2024 20:14:58 -0700
Subject: [PATCH 1/2] [clang][driver] Cleanup UEFI toolchain driver
UEFI toolchain predefines clean up. Introducing new __PECOFF__ predefine
for targets that produce PE COFF binaries. Updating UEFI header includes
to not include system include directories.
---
clang/lib/Basic/Targets/OSTargets.cpp | 1 +
clang/lib/Basic/Targets/OSTargets.h | 6 +++++-
clang/lib/Basic/Targets/X86.h | 5 -----
clang/lib/Driver/ToolChains/UEFI.cpp | 18 ++++++++++++++++++
clang/lib/Driver/ToolChains/UEFI.h | 4 ++++
clang/lib/Lex/InitHeaderSearch.cpp | 1 +
libcxx/include/__configuration/platform.h | 2 ++
7 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..d625967deb2589 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -260,6 +260,7 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
Builder.defineMacro("_WIN32");
+ Builder.defineMacro("__PECOFF__");
if (Triple.isArch64Bit())
Builder.defineMacro("_WIN64");
if (Triple.isWindowsGNUEnvironment())
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..049c03ea2b1ad5 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,11 @@ 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("__PECOFF__");
+ Builder.defineMacro("__UEFI__");
+ // Builder.defineMacro("_WIN32");
+ }
public:
UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index a99ae62984c7d5..de371743481144 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -826,11 +826,6 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
}
- void getTargetDefines(const LangOptions &Opts,
- MacroBuilder &Builder) const override {
- getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
- }
-
BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}
diff --git a/clang/lib/Driver/ToolChains/UEFI.cpp b/clang/lib/Driver/ToolChains/UEFI.cpp
index 66cbbec59246c0..a9d7e7892c5a64 100644
--- a/clang/lib/Driver/ToolChains/UEFI.cpp
+++ b/clang/lib/Driver/ToolChains/UEFI.cpp
@@ -35,6 +35,24 @@ UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
+void UEFI::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
+ return;
+
+ if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+ SmallString<128> Dir(getDriver().ResourceDir);
+ llvm::sys::path::append(Dir, "include");
+ addSystemInclude(DriverArgs, CC1Args, Dir.str());
+ }
+
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+ return;
+
+ if (std::optional<std::string> Path = getStdlibIncludePath())
+ addSystemInclude(DriverArgs, CC1Args, *Path);
+}
+
void tools::uefi::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
diff --git a/clang/lib/Driver/ToolChains/UEFI.h b/clang/lib/Driver/ToolChains/UEFI.h
index a126ac32db6c6c..7e038b5cb8b186 100644
--- a/clang/lib/Driver/ToolChains/UEFI.h
+++ b/clang/lib/Driver/ToolChains/UEFI.h
@@ -51,6 +51,10 @@ class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain {
return false;
}
bool isPICDefaultForced() const override { return true; }
+
+ void
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
};
} // namespace toolchains
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index 2218db15013d92..ed404333bd7b3d 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -305,6 +305,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
case llvm::Triple::PS5:
case llvm::Triple::RTEMS:
case llvm::Triple::Solaris:
+ case llvm::Triple::UEFI:
case llvm::Triple::WASI:
case llvm::Triple::ZOS:
return false;
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index 2a92ce209b91f8..8add73c8f2e6cd 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -22,6 +22,8 @@
# define _LIBCPP_OBJECT_FORMAT_MACHO 1
#elif defined(_WIN32)
# define _LIBCPP_OBJECT_FORMAT_COFF 1
+#elif defined(__UEFI__)
+# define _LIBCPP_OBJECT_FORMAT_COFF 1
#elif defined(__wasm__)
# define _LIBCPP_OBJECT_FORMAT_WASM 1
#elif defined(_AIX)
>From 41727dd7668adc456af62a9c817b12ded9485890 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 9 Oct 2024 10:03:58 -0700
Subject: [PATCH 2/2] Move predefine changes out of this PR.
---
clang/lib/Basic/Targets/OSTargets.cpp | 1 -
clang/lib/Basic/Targets/OSTargets.h | 6 +-----
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index d625967deb2589..b56e2c7ca9c494 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -260,7 +260,6 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
Builder.defineMacro("_WIN32");
- Builder.defineMacro("__PECOFF__");
if (Triple.isArch64Bit())
Builder.defineMacro("_WIN64");
if (Triple.isWindowsGNUEnvironment())
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 049c03ea2b1ad5..a83d6464e789d6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,11 +783,7 @@ 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 {
- Builder.defineMacro("__PECOFF__");
- Builder.defineMacro("__UEFI__");
- // Builder.defineMacro("_WIN32");
- }
+ MacroBuilder &Builder) const override {}
public:
UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
More information about the cfe-commits
mailing list