diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index ee5144854d80025ae2c4bfbe28d0835cd2b7d243..7f8438bf2a2ed44126a06ef7b503feec45937810 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -291,6 +291,7 @@ data GeneralFlag | Opt_Ticky_Dyn_Thunk | Opt_RPath | Opt_RelativeDynlibPaths + | Opt_CompactUnwind -- ^ @-fcompact-unwind@ | Opt_Hpc | Opt_FamAppCache | Opt_ExternalInterpreter diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 780a38e3d71e49a83190a9c7b19576d9686c2f32..6fc71e878aac6d2a817d44437d5b32e203e3a5c2 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -2078,6 +2078,12 @@ dynamic_flags_deps = [ (NoArg (setGeneralFlag Opt_SingleLibFolder)) , make_ord_flag defGhcFlag "pie" (NoArg (setGeneralFlag Opt_PICExecutable)) , make_ord_flag defGhcFlag "no-pie" (NoArg (unSetGeneralFlag Opt_PICExecutable)) + , make_ord_flag defGhcFlag "fcompact-unwind" + (noArgM (\dflags -> do + if platformOS (targetPlatform dflags) == OSDarwin + then return (gopt_set dflags Opt_CompactUnwind) + else do addWarn "-compact-unwind is only implemented by the darwin platform. Ignoring." + return dflags)) ------- Specific phases -------------------------------------------- -- need to appear before -pgmL to be parsed as LLVM flags. diff --git a/compiler/GHC/Linker/Static.hs b/compiler/GHC/Linker/Static.hs index 5d63d594616942a77cf26a4a9327770e5fcdc144..7a7dc89c829b7c57d5763c4fa8581a2584888f72 100644 --- a/compiler/GHC/Linker/Static.hs +++ b/compiler/GHC/Linker/Static.hs @@ -218,7 +218,8 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do -- like -- ld: warning: could not create compact unwind for .LFB3: non-standard register 5 being saved in prolog -- on x86. - ++ (if toolSettings_ldSupportsCompactUnwind toolSettings' && + ++ (if not (gopt Opt_CompactUnwind dflags) && + toolSettings_ldSupportsCompactUnwind toolSettings' && not staticLink && (platformOS platform == OSDarwin) && case platformArch platform of diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst index 8b99939d98a8f0615c6cd19a7935aa1adb2a6244..c931268bbdd01081e83659e720924a6b99660729 100644 --- a/docs/users_guide/phases.rst +++ b/docs/users_guide/phases.rst @@ -1322,3 +1322,17 @@ for example). that do runtime dynamic linking, where code dynamically linked in the future might require the value of a CAF that would otherwise be garbage-collected. + +.. ghc-flag:: -fcompact-unwind + :shortdesc: Instruct the linker to produce a `__compact_unwind` section. + :type: dynamic + :category: linking + + :since: 9.4.1 + + This instructs the linker to produce an executable that supports Apple's + compact unwinding sections. These are used by C++ and Objective-C code + to unwind the stack when an exception occurs. + + In theory, the older `__eh_frame` section should also be usable for this + purpose, but this does not always work.