diff options
author | Robert Hensing <robert@roberthensing.nl> | 2021-12-24 19:24:19 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-01-24 21:28:24 -0500 |
commit | 516eeb9e295b50872398bc9848a42ab41f743316 (patch) | |
tree | e6deb9f5ad1254cbab00992a6658998571c9c4d1 | |
parent | 3b009e1a6247057ff976043695b797b5d0649414 (diff) | |
download | haskell-516eeb9e295b50872398bc9848a42ab41f743316.tar.gz |
Add -fcompact-unwind
This gives users the choice to enable __compact_unwind sections
when linking. These were previously hardcoded to be removed.
This can be used to solved the problem "C++ does not catch
exceptions when used with Haskell-main and linked by ghc",
https://gitlab.haskell.org/ghc/ghc/-/issues/11829
It does not change the default behavior, because I can not
estimate the impact this would have.
When Apple first introduced the compact unwind ABI, a number of
open source projects have taken the easy route of disabling it,
avoiding errors or even just warnings shortly after its
introduction.
Since then, about a decade has passed, so it seems quite possible
that Apple itself, and presumably many programs with it, have
successfully switched to the new format, to the point where the
old __eh_frame section support is in disrepair. Perhaps we should
get along with the program, but for now we can test the waters
with this flag, and use it to fix packages that need it.
-rw-r--r-- | compiler/GHC/Driver/Flags.hs | 1 | ||||
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Linker/Static.hs | 3 | ||||
-rw-r--r-- | docs/users_guide/phases.rst | 14 |
4 files changed, 23 insertions, 1 deletions
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index ee5144854d..7f8438bf2a 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 780a38e3d7..6fc71e878a 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 5d63d59461..7a7dc89c82 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 8b99939d98..c931268bbd 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. |