From 15014bcec5072c1bbb4b1d46a75f44b97c852f83 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 7 Dec 2022 10:33:11 +0000 Subject: compiler: Add -f[no-]split-sections flags Here we add a `-fsplit-sections` flag which may some day replace `-split-sections`. This has the advantage of automatically providing a `-fno-split-sections` flag, which is useful for our packaging because we enable `-split-sections` by default but want to disable it in certain configurations. (cherry picked from commit 32255d055b768d51deb9d1f49681164cf7492011) --- compiler/GHC/Driver/Session.hs | 20 ++++++++++++-------- docs/users_guide/phases.rst | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 831267e2bf..07106c7c8c 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -2192,14 +2192,10 @@ dynamic_flags_deps = [ , make_ord_flag defGhcFlag "split-objs" (NoArg $ addWarn "ignoring -split-objs") + -- N.B. We may someday deprecate this in favor of -fsplit-sections, + -- which has the benefit of also having a negating -fno-split-sections. , make_ord_flag defGhcFlag "split-sections" - (noArgM (\dflags -> do - if platformHasSubsectionsViaSymbols (targetPlatform dflags) - then do addWarn $ - "-split-sections is not useful on this platform " ++ - "since it always uses subsections via symbols. Ignoring." - return dflags - else return (gopt_set dflags Opt_SplitSections))) + (NoArg $ setGeneralFlag Opt_SplitSections) -------- ghc -M ----------------------------------------------------- , make_ord_flag defGhcFlag "dep-suffix" (hasArg addDepSuffix) @@ -3514,7 +3510,8 @@ fFlagsDeps = [ (addWarn "-compact-unwind is only implemented by the darwin platform. Ignoring.") return dflags)), flagSpec "show-error-context" Opt_ShowErrorContext, - flagSpec "cmm-thread-sanitizer" Opt_CmmThreadSanitizer + flagSpec "cmm-thread-sanitizer" Opt_CmmThreadSanitizer, + flagSpec "split-sections" Opt_SplitSections ] ++ fHoleFlags @@ -4800,6 +4797,13 @@ makeDynFlagsConsistent dflags warn = "-dynamic-too is ignored when using -dynamic" in loop dflags' warn + | gopt Opt_SplitSections dflags + , platformHasSubsectionsViaSymbols (targetPlatform dflags) + = let dflags' = gopt_unuset dflags Opt_SplitSections + warn = "-fsplit-sections is not useful on this platform " ++ + "since it uses subsections-via-symbols. Ignoring." + in loop dflags' warn + -- Via-C backend only supports unregisterised ABI. Switch to a backend -- supporting it if possible. | backendUnregisterisedAbiOnly (backend dflags) && diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst index aa171c2055..8d0c32f5c1 100644 --- a/docs/users_guide/phases.rst +++ b/docs/users_guide/phases.rst @@ -909,10 +909,12 @@ for example). option for Apple's Linker (``-F`` already means something else for GHC). -.. ghc-flag:: -split-sections +.. ghc-flag:: -fsplit-sections + -split-sections :shortdesc: Split sections for link-time dead-code stripping :type: dynamic :category: linking + :reverse: -fno-split-sections Place each generated function or data item into its own section in the output file if the target supports arbitrary sections. The name of the -- cgit v1.2.1