From 6de1c17d2806bf7b9ec7f72b7585f3600eb280e3 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Thu, 23 May 2024 13:38:29 +0000
Subject: [PATCH] hadrian: build C/C++ with split sections when enabled

When split sections is enabled, ensure -fsplit-sections is passed to
GHC as well when invoking GHC to compile C/C++; and pass
-ffunction-sections -fdata-sections to gcc/clang when compiling C/C++
with the hadrian Cc builder. Fixes #23381.

(cherry picked from commit 0958937e79efcbe9f1ff25c1d697d62b8796d910)
(cherry picked from commit 7d5a22c2a2d63eec3eefd9a14dfe453f19ff4d15)
---
 hadrian/src/Settings/Builders/SplitSections.hs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hadrian/src/Settings/Builders/SplitSections.hs b/hadrian/src/Settings/Builders/SplitSections.hs
index 024596e50c1..6c87d425992 100644
--- a/hadrian/src/Settings/Builders/SplitSections.hs
+++ b/hadrian/src/Settings/Builders/SplitSections.hs
@@ -29,6 +29,9 @@ splitSectionsArgs = do
     ) then
     ( mconcat
         [ builder (Ghc CompileHs) ? arg "-fsplit-sections"
+        , builder (Ghc CompileCWithGhc) ? arg "-fsplit-sections"
+        , builder (Ghc CompileCppWithGhc) ? arg "-fsplit-sections"
+        , builder (Cc CompileC) ? arg "-ffunction-sections" <> arg "-fdata-sections"
         , builder MergeObjects ? ifM (expr isWinTarget)
             (pure ["-T", "driver/utils/merge_sections_pe.ld"])
             (pure ["-T", "driver/utils/merge_sections.ld"])
-- 
GitLab