53 lines
2.2 KiB
Diff
53 lines
2.2 KiB
Diff
From e54c80ab9def177802bb2bd758041933db24f76a Mon Sep 17 00:00:00 2001
|
|
From: q66 <q66@chimera-linux.org>
|
|
Date: Sun, 14 Apr 2024 14:47:34 +0200
|
|
Subject: [PATCH 16/29] clang: add fortify include paths for musl triplets +
|
|
enable fortify
|
|
|
|
---
|
|
clang/lib/Driver/ToolChains/Linux.cpp | 12 ++++++++----
|
|
clang/lib/Frontend/InitPreprocessor.cpp | 5 +++++
|
|
2 files changed, 13 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
|
|
index 2ac0139dc..9a9b40a25 100644
|
|
--- a/clang/lib/Driver/ToolChains/Linux.cpp
|
|
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
|
|
@@ -688,10 +688,14 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
if (getTriple().getOS() == llvm::Triple::RTEMS)
|
|
return;
|
|
|
|
- // Add an include of '/include' directly. This isn't provided by default by
|
|
- // system GCCs, but is often used with cross-compiling GCCs, and harmless to
|
|
- // add even when Clang is acting as-if it were a system compiler.
|
|
- addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
|
|
+ if (getTriple().isMusl()) {
|
|
+ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include/fortify"));
|
|
+ } else {
|
|
+ // Preserve original clang behavior for non-musl triples, but for musl
|
|
+ // this just gets in the way and none of our crosstoolchains are ever
|
|
+ // actually built this way (and we'd have to figure out fortify for it)
|
|
+ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
|
|
+ }
|
|
|
|
addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include"));
|
|
|
|
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
|
|
index 17f624e96..c239342fa 100644
|
|
--- a/clang/lib/Frontend/InitPreprocessor.cpp
|
|
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
|
|
@@ -1523,6 +1523,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
|
#undef TARGET_OS
|
|
}
|
|
|
|
+ // Enable fortify by default on musl when optimizing, but not with asan
|
|
+ if (TI.getTriple().isMusl() && LangOpts.Optimize &&
|
|
+ !LangOpts.Sanitize.has(SanitizerKind::Address))
|
|
+ Builder.defineMacro("_FORTIFY_SOURCE", "3");
|
|
+
|
|
// Get other target #defines.
|
|
TI.getTargetDefines(LangOpts, Builder);
|
|
}
|
|
--
|
|
2.49.0
|
|
|