Commit 4ade9627 authored by Ben Gamari's avatar Ben Gamari Committed by Austin Seipp

Abort when binutils ld is used with dynamic linking on ARM

The binutils linker on ARM emits unnecessary R_ARM_COPY relocations
which breaks tables-next-to-code in dynamically linked modules. This
check should be more selective but there is currently no released
version where this bug is fixed.  See
https://sourceware.org/bugzilla/show_bug.cgi?id=16177 and
https://ghc.haskell.org/trac/ghc/ticket/4210#comment:29 for details.
Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 08f8efb8
......@@ -295,6 +295,7 @@ import Annotations
import Module
import UniqFM
import Panic
import Platform
import Bag ( unitBag )
import ErrUtils
import MonadUtils
......@@ -450,12 +451,42 @@ initGhcMonad mb_top_dir
; initStaticOpts
; mySettings <- initSysTools mb_top_dir
; dflags <- initDynFlags (defaultDynFlags mySettings)
; checkBrokenTablesNextToCode dflags
; setUnsafeGlobalDynFlags dflags
-- c.f. DynFlags.parseDynamicFlagsFull, which
-- creates DynFlags and sets the UnsafeGlobalDynFlags
; newHscEnv dflags }
; setSession env }
-- | The binutils linker on ARM emits unnecessary R_ARM_COPY relocations which
-- breaks tables-next-to-code in dynamically linked modules. This
-- check should be more selective but there is currently no released
-- version where this bug is fixed.
-- See https://sourceware.org/bugzilla/show_bug.cgi?id=16177 and
-- https://ghc.haskell.org/trac/ghc/ticket/4210#comment:29
checkBrokenTablesNextToCode :: MonadIO m => DynFlags -> m ()
checkBrokenTablesNextToCode dflags
= do { broken <- checkBrokenTablesNextToCode' dflags
; when broken
$ do { liftIO $ throwIO $ mkApiErr dflags
(text "Tables-next-to-code not supported on ARM using binutils ld (https://sourceware.org/bugzilla/show_bug.cgi?id=16177)")
; fail "unsupported linker"
}
}
checkBrokenTablesNextToCode' :: MonadIO m => DynFlags -> m Bool
checkBrokenTablesNextToCode' dflags
| not (isARM arch) = return False
| WayDyn `notElem` ways dflags = return False
| not (tablesNextToCode dflags) = return False
| otherwise = do
linkerInfo <- liftIO $ getLinkerInfo dflags
case linkerInfo of
GnuLD _ -> return True
_ -> return False
where platform = targetPlatform dflags
arch = platformArch platform
-- %************************************************************************
-- %* *
......
......@@ -365,6 +365,12 @@
(e.g. GHCi) support for architectures without support in
GHC's own runtime linker (e.g. ARM).
</para>
<para>
Note: Tables-next-to-code is disabled when building on
ARM with binutil's ld due to a
<ulink url="https://sourceware.org/bugzilla/show_bug.cgi?id=16177">
bug</ulink> in ld.
</para>
</listitem>
</itemizedlist>
</sect2>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment