[Git][ghc/ghc][master] 2 commits: hadrian: build C/C++ with split sections when enabled

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Fri May 31 03:36:59 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
0958937e by Cheng Shao at 2024-05-30T23:36:25-04:00
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.

- - - - -
02b1f91e by Cheng Shao at 2024-05-30T23:36:25-04:00
driver: build C/C++ with -ffunction-sections -fdata-sections when split sections is enabled

When -fsplit-sections is passed to GHC, pass -ffunction-sections
-fdata-sections to gcc/clang when building C/C++. Previously,
-fsplit-sections was only respected by the NCG/LLVM backends, but not
the unregisterised backend; the GHC driver did not pass
-fdata-sections and -ffunction-sections to the C compiler, which
resulted in excessive executable sizes.

Fixes #23381.

-------------------------
Metric Decrease:
    size_hello_artifact
    size_hello_unicode
-------------------------

- - - - -


2 changed files:

- compiler/GHC/Driver/Pipeline/Execute.hs
- hadrian/src/Settings/Builders/SplitSections.hs


Changes:

=====================================
compiler/GHC/Driver/Pipeline/Execute.hs
=====================================
@@ -487,6 +487,13 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do
                     , not $ target32Bit (targetPlatform dflags)
                     ]
 
+                 -- if -fsplit-sections is enabled, we should also
+                 -- build with these flags.
+                 ++ (if gopt Opt_SplitSections dflags &&
+                      platformOS (targetPlatform dflags) /= OSDarwin
+                        then ["-ffunction-sections", "-fdata-sections"]
+                        else [])
+
           -- Stub files generated for foreign exports references the runIO_closure
           -- and runNonIO_closure symbols, which are defined in the base package.
           -- These symbols are imported into the stub.c file via RtsAPI.h, and the


=====================================
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"])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d10a1c6513a963bd69659bc6a110a041db0cfe1b...02b1f91e93b4e26c8fc227f48878a66f342cb68f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d10a1c6513a963bd69659bc6a110a041db0cfe1b...02b1f91e93b4e26c8fc227f48878a66f342cb68f
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240530/e389425b/attachment-0001.html>


More information about the ghc-commits mailing list