summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2020-05-14 08:18:31 +0800
committerMoritz Angermann <moritz.angermann@gmail.com>2020-06-04 04:56:55 -0400
commitaef523ea1254e8bb9e4143ad8f5994ca89ea9d2d (patch)
treec68cba1637655f0be57ba532e56ed82fffe6ae19
parentad44b50484f27beceab8213a061aa60c7a03f7ca (diff)
downloadhaskell-wip/angerman/can-disable-dll-loading.tar.gz
Disable DLL loading if without system linkerwip/angerman/can-disable-dll-loading
Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though.
-rw-r--r--compiler/GHC/Runtime/Linker.hs18
-rw-r--r--compiler/ghc.cabal.in9
2 files changed, 24 insertions, 3 deletions
diff --git a/compiler/GHC/Runtime/Linker.hs b/compiler/GHC/Runtime/Linker.hs
index d6b916ff39..740e3a7a43 100644
--- a/compiler/GHC/Runtime/Linker.hs
+++ b/compiler/GHC/Runtime/Linker.hs
@@ -1328,6 +1328,7 @@ linkPackage hsc_env pkg
("Loading package " ++ unitPackageIdString pkg ++ " ... ")
-- See comments with partOfGHCi
+#if defined(CAN_LOAD_DLL)
when (unitPackageName pkg `notElem` partOfGHCi) $ do
loadFrameworks hsc_env platform pkg
-- See Note [Crash early load_dyn and locateLib]
@@ -1336,7 +1337,7 @@ linkPackage hsc_env pkg
-- For remaining `dlls` crash early only when there is surely
-- no package's DLL around ... (not is_dyn)
mapM_ (load_dyn hsc_env (not is_dyn) . mkSOName platform) dlls
-
+#endif
-- After loading all the DLLs, we can load the static objects.
-- Ordering isn't important here, because we do one final link
-- step to resolve everything.
@@ -1471,10 +1472,15 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
-- O(n). Loading an import library is also O(n) so in general we prefer
-- shared libraries because they are simpler and faster.
--
- = findDll user `orElse`
+ =
+#if defined(CAN_LOAD_DLL)
+ findDll user `orElse`
+#endif
tryImpLib user `orElse`
+#if defined(CAN_LOAD_DLL)
findDll gcc `orElse`
findSysDll `orElse`
+#endif
tryImpLib gcc `orElse`
findArchive `orElse`
tryGcc `orElse`
@@ -1539,7 +1545,13 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
full = dllpath $ search lib_so_name lib_dirs
gcc name = liftM (fmap Archive) $ search name lib_dirs
files = import_libs ++ arch_files
- in apply $ short : full : map gcc files
+ dlls = [short, full]
+ archives = map gcc files
+ in apply $
+#if defined(CAN_LOAD_DLL)
+ dlls ++
+#endif
+ archives
tryImpLib re = case os of
OSMinGW32 ->
let dirs' = if re == user then lib_dirs else gcc_dirs
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index 1024f0c98f..718047f777 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -55,6 +55,11 @@ Flag integer-gmp
Manual: True
Default: False
+Flag dynamic-system-linker
+ Description: The system can load dynamic code. This is not the case for musl.
+ Default: True
+ Manual: False
+
Library
Default-Language: Haskell2010
Exposed: False
@@ -108,6 +113,10 @@ Library
CPP-Options: -DINTEGER_SIMPLE
build-depends: integer-simple >= 0.1.1.1
+ -- if no dynamic system linker is available, don't try DLLs.
+ if flag(dynamic-system-linker)
+ CPP-Options: -DCAN_LOAD_DLL
+
Other-Extensions:
BangPatterns
CPP