From 0a876ce2825f1e54bec7059a387e43a2e0386665 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Sun, 23 Oct 2022 01:02:35 +0200
Subject: [PATCH 2/4] clang: enable fortify by default on optimizing musl
 targets

---
 lib/Frontend/InitPreprocessor.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 20bfbf144..9095c0f2f 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -1288,6 +1288,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
     Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
   }
 
+  // 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", "2");
+
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }
-- 
2.38.0

