From aef523ea1254e8bb9e4143ad8f5994ca89ea9d2d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 14 May 2020 08:18:31 +0800 Subject: Disable DLL loading if without system linker 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. --- compiler/GHC/Runtime/Linker.hs | 18 +++++++++++++++--- compiler/ghc.cabal.in | 9 +++++++++ 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 -- cgit v1.2.1