@@ -0,0 +1,78 @@
1+diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
2+index 01628dcad1..209704d034 100644
3+--- a/compiler/ghc.cabal.in
4++++ b/compiler/ghc.cabal.in
5+@@ -45,6 +45,11 @@ Flag terminfo
6+ Default: True
7+ Manual: True
8+
9++Flag dynamic-system-linker
10++ Description: The system can load dynamic code. This is not the case for musl.
11++ Default: True
12++ Manual: False
13++
14+ Library
15+ Default-Language: Haskell2010
16+ Exposed: False
17+@@ -84,6 +89,9 @@ Library
18+ CPP-Options: -DGHCI
19+ Include-Dirs: ../rts/dist/build @FFIIncludeDir@
20+
21++ if flag(dynamic-system-linker)
22++ CPP-Options: -DCAN_LOAD_DLL
23++
24+ Other-Extensions:
25+ BangPatterns
26+ CPP
27+diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
28+index 3b030be2d3..879c5c19ee 100644
29+--- a/compiler/ghci/Linker.hs
30++++ b/compiler/ghci/Linker.hs
31+@@ -1295,13 +1295,13 @@ linkPackage hsc_env pkg
32+
33+ maybePutStr dflags
34+ ("Loading package " ++ sourcePackageIdString pkg ++ " ... ")
35+-
36+ -- See comments with partOfGHCi
37++#if defined(CAN_LOAD_DLL)
38+ when (packageName pkg `notElem` partOfGHCi) $ do
39+ loadFrameworks hsc_env platform pkg
40+ mapM_ (load_dyn hsc_env)
41+ (known_dlls ++ map (mkSOName platform) dlls)
42+-
43++#endif
44+ -- After loading all the DLLs, we can load the static objects.
45+ -- Ordering isn't important here, because we do one final link
46+ -- step to resolve everything.
47+@@ -1382,10 +1382,15 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
48+ -- O(n). Loading an import library is also O(n) so in general we prefer
49+ -- shared libraries because they are simpler and faster.
50+ --
51+- = findDll user `orElse`
52++ =
53++#if defined(CAN_LOAD_DLL)
54++ findDll user `orElse`
55++#endif
56+ tryImpLib user `orElse`
57++#if defined(CAN_LOAD_DLL)
58+ findDll gcc `orElse`
59+ findSysDll `orElse`
60++#endif
61+ tryImpLib gcc `orElse`
62+ findArchive `orElse`
63+ tryGcc `orElse`
64+@@ -1452,7 +1457,13 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
65+ full = dllpath $ search lib_so_name lib_dirs
66+ gcc name = liftM (fmap Archive) $ search name lib_dirs
67+ files = import_libs ++ arch_files
68+- in apply $ short : full : map gcc files
69++ dlls = [short, full]
70++ archives = map gcc files
71++ in apply $
72++#if defined(CAN_LOAD_DLL)
73++ dlls ++
74++#endif
75++ archives
76+ tryImpLib re = case os of
77+ OSMinGW32 ->
78+ let dirs' = if re == user then lib_dirs else gcc_dirs