summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-12-24 19:24:19 +0100
committerBen Gamari <ben@smart-cactus.org>2022-03-04 14:04:17 -0500
commit1831d9ebd962d9f664686db2dd06a0364484f8bf (patch)
treedd55a5ff71bdd51bb666d227110aa11143186334
parentb3d7230ec0a6bf40a846081231be288c3948f789 (diff)
downloadhaskell-1831d9ebd962d9f664686db2dd06a0364484f8bf.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. (cherry picked from commit 1496a2a7d2f6e00e33132c999d1e4ecde556dd10)
-rw-r--r--compiler/GHC/Driver/Flags.hs1
-rw-r--r--compiler/GHC/Driver/Session.hs6
-rw-r--r--compiler/GHC/Linker/Static.hs3
-rw-r--r--docs/users_guide/phases.rst14
4 files changed, 23 insertions, 1 deletions
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs
index 828db3b183..5280f0ad45 100644
--- a/compiler/GHC/Driver/Flags.hs
+++ b/compiler/GHC/Driver/Flags.hs
@@ -267,6 +267,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 50d393019c..27fad85858 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -2111,6 +2111,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 cfb83f0575..c7ecf15f30 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 6833ce36d7..7bf48862ec 100644
--- a/docs/users_guide/phases.rst
+++ b/docs/users_guide/phases.rst
@@ -1310,3 +1310,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, 9.2.2
+
+ 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.