summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-01-22 08:11:02 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-01-30 05:06:26 -0500
commit8bed166bb79445f90015757fd5baac69a7b835df (patch)
treee0d23918d6ace41e69bc60bd7c65b953cef0138b /compiler/GHC
parent78c07219d5dad9730bbe3ec26ad22912ff22f058 (diff)
downloadhaskell-8bed166bb79445f90015757fd5baac69a7b835df.tar.gz
nativeGen: Disable asm-shortcutting on Darwin
Asm-shortcutting may produce relative references to symbols defined in other compilation units. This is not something that MachO relocations support (see #21972). For this reason we disable the optimisation on Darwin. We do so without a warning since this flag is enabled by `-O2`. Another way to address this issue would be to rather implement a PLT-relocatable jump-table strategy. However, this would only benefit Darwin and does not seem worth the effort. Closes #21972.
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/CmmToAsm.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/GHC/CmmToAsm.hs b/compiler/GHC/CmmToAsm.hs
index c0ac96fa79..94bdaa648b 100644
--- a/compiler/GHC/CmmToAsm.hs
+++ b/compiler/GHC/CmmToAsm.hs
@@ -812,6 +812,19 @@ generateJumpTables ncgImpl xs = concatMap f xs
-- -----------------------------------------------------------------------------
-- Shortcut branches
+-- Note [No asm-shortcutting on Darwin]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- Asm-shortcutting may produce relative references to symbols defined in
+-- other compilation units. This is not something that MachO relocations
+-- support (see #21972). For this reason we disable the optimisation on Darwin.
+-- We do so in the backend without a warning since this flag is enabled by
+-- `-O2`.
+--
+-- Another way to address this issue would be to rather implement a
+-- PLT-relocatable jump-table strategy. However, this would only benefit Darwin
+-- and does not seem worth the effort as this optimisation generally doesn't
+-- offer terribly great benefits.
+
shortcutBranches
:: forall statics instr jumpDest. (Outputable jumpDest)
=> NCGConfig
@@ -822,6 +835,8 @@ shortcutBranches
shortcutBranches config ncgImpl tops weights
| ncgEnableShortcutting config
+ -- See Note [No asm-shortcutting on Darwin]
+ , not $ osMachOTarget $ platformOS $ ncgPlatform config
= ( map (apply_mapping ncgImpl mapping) tops'
, shortcutWeightMap mappingBid <$!> weights )
| otherwise