Skip to content

Commit

Permalink
Abort when binutils ld is used with dynamic linking on ARM
Browse files Browse the repository at this point in the history
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: Austin Seipp <austin@well-typed.com>
  • Loading branch information
bgamari authored and Austin Seipp committed Jan 28, 2014
1 parent 08f8efb commit 4ade962
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions compiler/main/GHC.hs
Expand Up @@ -295,6 +295,7 @@ import Annotations
import Module
import UniqFM
import Panic
import Platform
import Bag ( unitBag )
import ErrUtils
import MonadUtils
Expand Down Expand Up @@ -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


-- %************************************************************************
-- %* *
Expand Down
6 changes: 6 additions & 0 deletions docs/users_guide/7.8.1-notes.xml
Expand Up @@ -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>
Expand Down

0 comments on commit 4ade962

Please sign in to comment.