Commit b29b6662 authored by Divam Narula's avatar Divam Narula
Browse files

Merge commit '1f02b743' into dn-ghcjs-ghc-8.10.7

parents 5c56b34d 1f02b743
Pipeline #40190 failed with stages
in 17 minutes and 7 seconds
......@@ -189,6 +189,7 @@ _darcs/
/utils/mkUserGuidePart/mkUserGuidePart.cabal
/utils/runghc/runghc.cabal
/utils/gen-dll/gen-dll.cabal
/utils/ghc-pkg/ghc-pkg.cabal
utils/lndir/fs.*
utils/unlit/fs.*
rts/fs.*
......
......@@ -2,7 +2,7 @@ variables:
GIT_SSL_NO_VERIFY: "1"
# Commit of ghc/ci-images repository from which to pull Docker images
DOCKER_REV: 1ac7f435c9312f10422a82d304194778378e2a1a
DOCKER_REV: 3ae30d6ca1dad3670b0e3d3d2cdfdf4ad145b05f
# Sequential version number capturing the versions of all tools fetched by
# .gitlab/ci.sh.
......@@ -446,36 +446,6 @@ release-x86_64-freebsd:
# x86_64-darwin
#################################
validate-x86_64-darwin-old:
extends: .validate
stage: full-build
tags:
- x86_64-darwin
variables:
GHC_VERSION: 8.6.5
CABAL_INSTALL_VERSION: 3.0.0.0
BIN_DIST_PREP_TAR_COMP: "ghc-x86_64-apple-darwin.tar.xz"
MACOSX_DEPLOYMENT_TARGET: "10.7"
# Only Sierra and onwards supports clock_gettime. See #12858
ac_cv_func_clock_gettime: "no"
# Only newer OS Xs support utimensat. See #17895
ac_cv_func_utimensat: "no"
LANG: "en_US.UTF-8"
CONFIGURE_ARGS: "--with-intree-gmp"
TEST_ENV: "x86_64-darwin"
BUILD_FLAVOUR: "perf"
after_script:
- cp -Rf $HOME/.cabal cabal-cache
- .gitlab/ci.sh clean
artifacts:
when: always
expire_in: 2 week
cache:
key: "darwin-$GHC_VERSION"
paths:
- cabal-cache
- toolchain
validate-x86_64-darwin:
extends: .validate
stage: full-build
......@@ -503,7 +473,7 @@ validate-x86_64-darwin:
CPUS: 8
LANG: "en_US.UTF-8"
# WARNING: this is overridden in the shell.nix, see shell.nix!
CONFIGURE_ARGS: "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
CONFIGURE_ARGS: "--with-intree-gmp"
# I wish we could just use the nix #! logic, but we can't --run and -i bash
# behave very differently. -i bash does not pass any nix related env vars
......@@ -590,7 +560,7 @@ validate-aarch64-darwin:
CPUS: 8
LANG: "en_US.UTF-8"
# WARNING: this is overridden in the shell.nix, see shell.nix!
CONFIGURE_ARGS: "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
CONFIGURE_ARGS: "--with-intree-gmp"
# I wish we could just use the nix #! logic, but we can't --run and -i bash
# behave very differently. -i bash does not pass any nix related env vars
......@@ -989,9 +959,11 @@ release-x86_64-linux-deb8:
when: always
expire_in: 2 week
release-x86_64-linux-alpine:
release-x86_64-linux-alpine-integer-simple:
<<: *release
extends: .build-x86_64-linux-alpine-hadrian
variables:
HADRIAN_ARGS: "--docs=no-sphinx --integer-simple"
nightly-x86_64-linux-alpine:
<<: *nightly
......
......@@ -282,19 +282,9 @@ function prepare_build_mk() {
if [[ -z ${INTEGER_LIBRARY:-} ]]; then INTEGER_LIBRARY=integer-gmp; fi
cat > mk/build.mk <<EOF
V=1
HADDOCK_DOCS=YES
LATEX_DOCS=YES
HSCOLOUR_SRCS=YES
BUILD_SPHINX_HTML=$BUILD_SPHINX_HTML
BUILD_SPHINX_PDF=$BUILD_SPHINX_PDF
BeConservative=YES
INTEGER_LIBRARY=$INTEGER_LIBRARY
BuildFlavour=$BUILD_FLAVOUR
ifneq "\$(BuildFlavour)" ""
include mk/flavours/\$(BuildFlavour).mk
endif
include mk/flavours/${BUILD_FLAVOUR}.mk
GhcLibHcOpts+=-haddock
EOF
......@@ -302,10 +292,6 @@ EOF
echo "EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump" >> mk/build.mk
fi
case "$(uname)" in
Darwin) echo "libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp" >> mk/build.mk ;;
*) ;;
esac
info "build.mk is:"
cat mk/build.mk
......@@ -344,9 +330,7 @@ function build_make() {
MAKE_ARGS="${MAKE_ARGS:-} V=0"
fi
echo "include mk/flavours/${BUILD_FLAVOUR}.mk" > mk/build.mk
echo 'GhcLibHcOpts+=-haddock' >> mk/build.mk
run "$MAKE" -j"$cores" $MAKE_ARGS
run "$MAKE" -j"$cores" "$MAKE_ARGS"
run "$MAKE" -j"$cores" binary-dist-prep TAR_COMP_OPTS=-1
ls -lh "$BIN_DIST_PREP_TAR_COMP"
}
......@@ -380,14 +364,23 @@ function build_hadrian() {
function test_hadrian() {
cd _build/bindist/ghc-*/
run ./configure --prefix="$TOP"/_build/install
run "$MAKE" install
case "$(uname)" in
MSYS_*|MINGW*)
mkdir -p "$TOP"/_build/install
cp -a * "$TOP"/_build/install
;;
*)
run ./configure --prefix="$TOP"/_build/install
run "$MAKE" install
;;
esac
cd ../../../
run_hadrian \
test \
--summary-junit=./junit.xml \
--test-compiler="$TOP"/_build/install/bin/ghc
--test-compiler="$TOP/_build/install/bin/ghc$exe" \
"runtest.opts+=${RUNTEST_ARGS:-}"
}
function clean() {
......
......@@ -13,13 +13,14 @@
# we need to inject ncurses into --with-curses-libraries.
# the real fix is to teach terminfo to use libcurses on macOS.
# CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=${pkgs.ncurses.out}/lib";
CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib SH=/bin/bash";
CONFIGURE_ARGS = "--with-intree-gmp";
# magic speedup pony :facepalm:
#
# nix has the ugly habbit of duplicating ld flags more than necessary. This
# somewhat consolidates this.
shellHook = ''
echo $NIX_LDFLAGS
export NIX_LDFLAGS=$(for a in $NIX_LDFLAGS; do echo $a; done |sort|uniq|xargs)
export NIX_LDFLAGS_FOR_TARGET=$(for a in $NIX_LDFLAGS_FOR_TARGET; do echo $a; done |sort|uniq|xargs)
export NIX_LDFLAGS_FOR_TARGET=$(comm -3 <(for l in $NIX_LDFLAGS_FOR_TARGET; do echo $l; done) <(for l in $NIX_LDFLAGS; do echo $l; done))
......@@ -43,6 +44,13 @@
# unconditionally add the MacOSX.sdk and TargetConditional.h
export NIX_CFLAGS_COMPILE+=" -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
export NIX_LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib $NIX_LDFLAGS"
echo $NIX_LDFLAGS
echo $MACOSX_DEPLOYMENT_TARGET
export MACOSX_DEPLOYMENT_TARGET=10.7
echo $MACOSX_DEPLOYMENT_TARGET
'';
nativeBuildInputs = (with pkgs; [
......
......@@ -2244,7 +2244,7 @@ AC_DEFUN([FIND_LLVM_PROG],[
[AC_MSG_RESULT(no)
$1=""
AC_MSG_NOTICE([We only support llvm $3 to $4 (found $PROG_VERSION).])],
[AX_COMPARE_VERSION([$PROG_VERSION], [gt], [$4],
[AX_COMPARE_VERSION([$PROG_VERSION], [ge], [$4],
[AC_MSG_RESULT(no)
$1=""
AC_MSG_NOTICE([We only support llvm $3 to $4 (found $PROG_VERSION).])],
......
......@@ -2599,7 +2599,7 @@ emitCopyArray copy src0 src_off dst0 dst_off0 n =
dst_off <- assignTempE dst_off0
-- Nonmoving collector write barrier
emitCopyUpdRemSetPush dflags (arrPtrsHdrSizeW dflags) dst dst_off n
emitCopyUpdRemSetPush dflags (arrPtrsHdrSize dflags) dst dst_off n
-- Set the dirty bit in the header.
emit (setInfo dst (CmmLit (CmmLabel mkMAP_DIRTY_infoLabel)))
......@@ -2664,7 +2664,7 @@ emitCopySmallArray copy src0 src_off dst0 dst_off n =
dst <- assignTempE dst0
-- Nonmoving collector write barrier
emitCopyUpdRemSetPush dflags (smallArrPtrsHdrSizeW dflags) dst dst_off n
emitCopyUpdRemSetPush dflags (smallArrPtrsHdrSize dflags) dst dst_off n
-- Set the dirty bit in the header.
emit (setInfo dst (CmmLit (CmmLabel mkSMAP_DIRTY_infoLabel)))
......@@ -2987,7 +2987,7 @@ emitCtzCall res x width = do
-- | Push a range of pointer-array elements that are about to be copied over to
-- the update remembered set.
emitCopyUpdRemSetPush :: DynFlags
-> WordOff -- ^ array header size
-> ByteOff -- ^ array header size (in bytes)
-> CmmExpr -- ^ destination array
-> CmmExpr -- ^ offset in destination array (in words)
-> Int -- ^ number of elements to copy
......
......@@ -914,7 +914,7 @@ dynLoadObjs hsc_env pls@PersistentLinkerState{..} objs = do
concatMap (\l -> [ Option ("-l" ++ l) ])
(nub $ snd <$> temp_sos)
++ concatMap (\lp -> Option ("-L" ++ lp)
: if gopt Opt_RPath dflags
: if useXLinkerRPath dflags (platformOS platform)
then [ Option "-Xlinker"
, Option "-rpath"
, Option "-Xlinker"
......@@ -923,7 +923,7 @@ dynLoadObjs hsc_env pls@PersistentLinkerState{..} objs = do
(nub $ fst <$> temp_sos)
++ concatMap
(\lp -> Option ("-L" ++ lp)
: if gopt Opt_RPath dflags
: if useXLinkerRPath dflags (platformOS platform)
then [ Option "-Xlinker"
, Option "-rpath"
, Option "-Xlinker"
......
......@@ -268,7 +268,7 @@ ppCall ct fptr args attrs = case fptr of
where
ppCall' (LlvmFunctionDecl _ _ cc ret argTy params _) =
let tc = if ct == TailCall then text "tail " else empty
ppValues = hsep $ punctuate comma $ map ppCallMetaExpr args
ppValues = ppCallParams (map snd params) args
ppArgTy = (ppCommaJoin $ map fst params) <>
(case argTy of
VarArgs -> text ", ..."
......@@ -279,10 +279,13 @@ ppCall ct fptr args attrs = case fptr of
<> fnty <+> ppName fptr <> lparen <+> ppValues
<+> rparen <+> attrDoc
-- Metadata needs to be marked as having the `metadata` type when used
-- in a call argument
ppCallMetaExpr (MetaVar v) = ppr v
ppCallMetaExpr v = text "metadata" <+> ppr v
ppCallParams :: [[LlvmParamAttr]] -> [MetaExpr] -> SDoc
ppCallParams attrs args = hsep $ punctuate comma $ zipWith ppCallMetaExpr attrs args
where
-- Metadata needs to be marked as having the `metadata` type when used
-- in a call argument
ppCallMetaExpr attrs (MetaVar v) = ppVar' attrs v
ppCallMetaExpr _ v = text "metadata" <+> ppr v
ppMachOp :: LlvmMachOp -> LlvmVar -> LlvmVar -> SDoc
ppMachOp op left right =
......
......@@ -114,8 +114,12 @@ data LlvmVar
deriving (Eq)
instance Outputable LlvmVar where
ppr (LMLitVar x) = ppr x
ppr (x ) = ppr (getVarType x) <+> ppName x
ppr = ppVar' []
ppVar' :: [LlvmParamAttr] -> LlvmVar -> SDoc
ppVar' attrs v = case v of
LMLitVar x -> ppTypeLit' attrs x
x -> ppr (getVarType x) <+> ppSpaceJoin attrs <+> ppName x
-- | Llvm Literal Data.
......@@ -135,8 +139,12 @@ data LlvmLit
deriving (Eq)
instance Outputable LlvmLit where
ppr l@(LMVectorLit {}) = ppLit l
ppr l = ppr (getLitType l) <+> ppLit l
ppr = ppTypeLit' []
ppTypeLit' :: [LlvmParamAttr] -> LlvmLit -> SDoc
ppTypeLit' attrs l = case l of
l@(LMVectorLit {}) -> ppLit l
_ -> ppr (getLitType l) <+> ppSpaceJoin attrs <+> ppLit l
-- | Llvm Static Data.
......
......@@ -58,8 +58,8 @@ llvmCodeGen dflags h cmm_stream
let doWarn = wopt Opt_WarnUnsupportedLlvmVersion dflags
when (not (llvmVersionSupported ver) && doWarn) $ putMsg dflags $
"You are using an unsupported version of LLVM!" $$
"Currently only" <+> text (llvmVersionStr supportedLlvmVersionMin) <+>
"to" <+> text (llvmVersionStr supportedLlvmVersionMax) <+> "is supported." <+>
"Currently only" <+> text (llvmVersionStr supportedLlvmVersionLowerBound) <+>
"to" <+> text (llvmVersionStr supportedLlvmVersionUpperBound) <+> "is supported." <+>
"System LLVM version: " <> text (llvmVersionStr ver) $$
"We will try though..."
let isS390X = platformArch (targetPlatform dflags) == ArchS390X
......@@ -72,7 +72,7 @@ llvmCodeGen dflags h cmm_stream
-- currently don't use the LLVM version to guide code generation
-- so this is okay.
let llvm_ver :: LlvmVersion
llvm_ver = fromMaybe supportedLlvmVersionMin mb_ver
llvm_ver = fromMaybe supportedLlvmVersionLowerBound mb_ver
-- run code generation
a <- runLlvm dflags llvm_ver bufh $
......
......@@ -14,7 +14,7 @@ module LlvmCodeGen.Base (
LlvmUnresData, LlvmData, UnresLabel, UnresStatic,
LlvmVersion, llvmVersionSupported, parseLlvmVersion,
supportedLlvmVersionMin, supportedLlvmVersionMax,
supportedLlvmVersionLowerBound, supportedLlvmVersionUpperBound,
llvmVersionStr, llvmVersionList,
LlvmM,
......@@ -267,7 +267,6 @@ llvmPtrBits dflags = widthInBits $ typeWidth $ gcWord dflags
-- * Llvm Version
--
-- Newtype to avoid using the Eq instance!
newtype LlvmVersion = LlvmVersion { llvmVersionNE :: NE.NonEmpty Int }
deriving (Eq, Ord)
......@@ -285,14 +284,17 @@ parseLlvmVersion =
where
(ver_str, rest) = span isDigit s
-- | The LLVM Version that is currently supported.
supportedLlvmVersionMin, supportedLlvmVersionMax :: LlvmVersion
supportedLlvmVersionMin = LlvmVersion (sUPPORTED_LLVM_VERSION_MIN NE.:| [])
supportedLlvmVersionMax = LlvmVersion (sUPPORTED_LLVM_VERSION_MAX NE.:| [])
-- | The (inclusive) lower bound on the LLVM Version that is currently supported.
supportedLlvmVersionLowerBound :: LlvmVersion
supportedLlvmVersionLowerBound = LlvmVersion (sUPPORTED_LLVM_VERSION_MIN NE.:| [])
-- | The (not-inclusive) upper bound bound on the LLVM Version that is currently supported.
supportedLlvmVersionUpperBound :: LlvmVersion
supportedLlvmVersionUpperBound = LlvmVersion (sUPPORTED_LLVM_VERSION_MAX NE.:| [])
llvmVersionSupported :: LlvmVersion -> Bool
llvmVersionSupported v =
v > supportedLlvmVersionMin && v <= supportedLlvmVersionMax
v >= supportedLlvmVersionLowerBound && v < supportedLlvmVersionUpperBound
llvmVersionStr :: LlvmVersion -> String
llvmVersionStr = intercalate "." . map show . llvmVersionList
......
......@@ -460,6 +460,12 @@ genCall target res args = runStmtsDecls $ do
The native code generator only handles StdCall and CCallConv.
-}
let arg_type (hint, expr) =
case expr of
ty@(LMInt n) | n < 64 && lmconv == CC_Ccc && platformCConvNeedsExtension platform
-> (ty, if hint == Signed then [SignExt] else [ZeroExt])
ty -> (ty, [])
-- call attributes
let fnAttrs | never_returns = NoReturn : llvmStdFunAttrs
| otherwise = llvmStdFunAttrs
......@@ -477,7 +483,7 @@ genCall target res args = runStmtsDecls $ do
let retTyCmm = ret_type_cmm ress_hints
let argTy = tysToParams $ map (snd . primRepToLlvmTy) args_rep
let argTy = map arg_type $ map primRepToLlvmTy args_rep
let retTy = snd $ primRepToLlvmTy ret_rep
let funTy = \name -> LMFunction $ LlvmFunctionDecl name ExternallyVisible
lmconv retTy FixedArgs argTy (llvmFunAlign dflags)
......@@ -524,6 +530,15 @@ genCall target res args = runStmtsDecls $ do
v2 <- doExprW ty $ Cast op v1 ty
statement $ Store v2 vreg
doReturn
where
-- | For some architectures the C calling convention is that any
-- integer shorter than 64 bits is replaced by its 64 bits
-- representation using sign or zero extension.
platformCConvNeedsExtension :: Platform -> Bool
platformCConvNeedsExtension platform = case platformArch platform of
ArchPPC_64 _ -> True
ArchS390X -> True
_ -> False
-- | Generate a call to an LLVM intrinsic that performs arithmetic operation
-- with overflow bit (i.e., returns a struct containing the actual result of the
......
......@@ -1731,7 +1731,7 @@ linkBinary' staticLink dflags o_files dep_packages = do
(l `makeRelativeTo` full_output_fn)
else l
-- See Note [-Xlinker -rpath vs -Wl,-rpath]
rpath = if gopt Opt_RPath dflags
rpath = if useXLinkerRPath dflags (platformOS platform)
then ["-Xlinker", "-rpath", "-Xlinker", libpath]
else []
-- Solaris 11's linker does not support -rpath-link option. It silently
......@@ -1747,7 +1747,7 @@ linkBinary' staticLink dflags o_files dep_packages = do
| osMachOTarget (platformOS platform) &&
dynLibLoader dflags == SystemDependent &&
WayDyn `elem` ways dflags &&
gopt Opt_RPath dflags
useXLinkerRPath dflags (platformOS platform)
= let libpath = if gopt Opt_RelativeDynlibPaths dflags
then "@loader_path" </>
(l `makeRelativeTo` full_output_fn)
......
......@@ -234,6 +234,7 @@ module DynFlags (
-- * Linker/compiler information
LinkerInfo(..),
CompilerInfo(..),
useXLinkerRPath,
-- * File cleanup
FilesToClean(..), emptyFilesToClean,
......@@ -4607,7 +4608,8 @@ defaultFlags settings
Opt_ProfCountEntries,
Opt_SharedImplib,
Opt_SimplPreInlining,
Opt_VersionMacros
Opt_VersionMacros,
Opt_RPath
]
++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
......@@ -4615,8 +4617,6 @@ defaultFlags settings
++ default_PIC platform
++ default_RPath platform
++ concatMap (wayGeneralFlags platform) (defaultWays settings)
++ validHoleFitDefaults
......@@ -4672,29 +4672,6 @@ default_PIC platform =
-- information.
_ -> []
-- We usually want to use RPath, except on macOS (OSDarwin). On recent macOS
-- versions the number of load commands we can embed in a dynamic library is
-- restricted. Hence since b592bd98ff2 we rely on -dead_strip_dylib to only
-- link the needed dylibs instead of linking the full dependency closure.
--
-- If we split the library linking into injecting -rpath and -l @rpath/...
-- components, we will reduce the number of libraries we link, however we will
-- still inject one -rpath entry for each library, independent of their use.
-- That is, we even inject -rpath values for libraries that we dead_strip in
-- the end. As such we can run afoul of the load command size limit simply
-- by polluting the load commands with RPATH entries.
--
-- Thus, we disable Opt_RPath by default on OSDarwin. The savvy user can always
-- enable it with -use-rpath if they so wish.
--
-- See Note [Dynamic linking on macOS]
default_RPath :: Platform -> [GeneralFlag]
default_RPath platform | platformOS platform == OSDarwin = []
default_RPath _ = [Opt_RPath]
-- General flags that are switched on/off when other general flags are switched
-- on
impliedGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)]
......@@ -5933,6 +5910,40 @@ data CompilerInfo
| UnknownCC
deriving Eq
-- | Should we use `-XLinker -rpath` when linking or not?
-- See Note [-fno-use-rpaths]
useXLinkerRPath :: DynFlags -> OS -> Bool
useXLinkerRPath _ OSDarwin = False -- See Note [Dynamic linking on macOS]
useXLinkerRPath dflags _ = gopt Opt_RPath dflags
{-
Note [-fno-use-rpaths]
~~~~~~~~~~~~~~~~~~~~~~
First read, Note [Dynamic linking on macOS] to understand why on darwin we never
use `-XLinker -rpath`.
The specification of `Opt_RPath` is as follows:
The default case `-fuse-rpaths`:
* On darwin, never use `-Xlinker -rpath -Xlinker`, always inject the rpath
afterwards, see `runInjectRPaths`. There is no way to use `-Xlinker` on darwin
as things stand but it wasn't documented in the user guide before this patch how
`-fuse-rpaths` should behave and the fact it was always disabled on darwin.
* Otherwise, use `-Xlinker -rpath -Xlinker` to set the rpath of the executable,
this is the normal way you should set the rpath.
The case of `-fno-use-rpaths`
* Never inject anything into the rpath.
When this was first implemented, `Opt_RPath` was disabled on darwin, but
the rpath was still always augmented by `runInjectRPaths`, and there was no way to
stop this. This was problematic because you couldn't build an executable in CI
with a clean rpath.
-}
-- -----------------------------------------------------------------------------
-- RTS hooks
......
......@@ -248,6 +248,8 @@ linkDynLib dflags0 o_files dep_packages
pkgs <- getPreloadPackagesAnd dflags dep_packages
let platform = targetPlatform dflags
os = platformOS platform
let pkg_lib_paths = collectLibraryPaths dflags pkgs
let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
get_pkg_lib_path_opts l
......@@ -257,7 +259,7 @@ linkDynLib dflags0 o_files dep_packages
-- Only if we want dynamic libraries
WayDyn `elem` ways dflags &&
-- Only use RPath if we explicitly asked for it
gopt Opt_RPath dflags
useXLinkerRPath dflags os
= ["-L" ++ l, "-Xlinker", "-rpath", "-Xlinker", l]
-- See Note [-Xlinker -rpath vs -Wl,-rpath]
| otherwise = ["-L" ++ l]
......@@ -272,9 +274,7 @@ linkDynLib dflags0 o_files dep_packages
-- not allow undefined symbols.
-- The RTS library path is still added to the library search path
-- above in case the RTS is being explicitly linked in (see #3807).
let platform = targetPlatform dflags
os = platformOS platform
pkgs_no_rts = case os of
let pkgs_no_rts = case os of
OSMinGW32 ->
pkgs
_ ->
......
......@@ -18,19 +18,22 @@ import GHC.Platform
import Util
import Data.List
import Data.Char
import Data.Maybe
import System.IO
import System.Process
import GhcPrelude
import LlvmCodeGen.Base (LlvmVersion, llvmVersionStr, supportedLlvmVersionMin, supportedLlvmVersionMax, llvmVersionStr, parseLlvmVersion)
import LlvmCodeGen.Base (LlvmVersion, llvmVersionStr, supportedLlvmVersionLowerBound, supportedLlvmVersionUpperBound, llvmVersionStr, parseLlvmVersion)
import SysTools.Process
import SysTools.Info
import Control.Monad (join, forM, filterM)
import Control.Monad (join, forM, filterM, void)
import System.Directory (doesFileExist)
import System.FilePath ((</>))
import Text.ParserCombinators.ReadP as Parser
{-
************************************************************************
......@@ -236,10 +239,11 @@ figureLlvmVersion dflags = traceToolCommand dflags "llc" $ do
errorMsg dflags $ vcat
[ text "Warning:", nest 9 $
text "Couldn't figure out LLVM version!" $$
text ("Make sure you have installed LLVM between "
++ llvmVersionStr supportedLlvmVersionMin
text ("Make sure you have installed LLVM between ["
++ llvmVersionStr supportedLlvmVersionLowerBound
++ " and "
++ llvmVersionStr supportedLlvmVersionMax) ]
++ llvmVersionStr supportedLlvmVersionUpperBound
++ ")") ]
return Nothing)
......@@ -260,15 +264,15 @@ figureLlvmVersion dflags = traceToolCommand dflags "llc" $ do
--
-- See Note [Dynamic linking on macOS]
runInjectRPaths :: DynFlags -> [FilePath] -> FilePath -> IO ()
runInjectRPaths dflags _ _ | not (gopt Opt_RPath dflags) = return ()
runInjectRPaths dflags lib_paths dylib = do
info <- lines <$> askOtool dflags Nothing [Option "-L", Option dylib]
-- filter the output for only the libraries. And then drop the @rpath prefix.
let libs = fmap (drop 7) $ filter (isPrefixOf "@rpath") $ fmap (head.words) $ info
-- find any pre-existing LC_PATH items
info <- fmap words.lines <$> askOtool dflags Nothing [Option "-l", Option dylib]
let paths = concatMap f info
where f ("path":p:_) = [p]
f _ = []
info <- lines <$> askOtool dflags Nothing [Option "-l", Option dylib]
let paths = mapMaybe get_rpath info
lib_paths' = [ p | p <- lib_paths, not (p `elem` paths) ]
-- only find those rpaths, that aren't already in the library.
rpaths <- nub.sort.join <$> forM libs (\f -> filterM (\l -> doesFileExist (l </> f)) lib_paths')
......@@ -277,6 +281,24 @@ runInjectRPaths dflags lib_paths dylib = do
[] -> return ()
_ -> runInstallNameTool dflags $ map Option $ "-add_rpath":(intersperse "-add_rpath" rpaths) ++ [dylib]
get_rpath :: String -> Maybe FilePath
get_rpath l = case readP_to_S rpath_parser l of
[(rpath, "")] -> Just rpath
_ -> Nothing
rpath_parser :: ReadP FilePath
rpath_parser = do
skipSpaces
void $ string "path"