@@ -191,3 +191,52 @@ index adba60b53c..351103fd4c 100644
191191 loadObj :: FilePath -> IO ArchiveEntry
192192 loadObj fp = do
193193 payload <- B.readFile fp
194+ diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs
195+ index 5cb73b1..99e7d01 100644
196+ --- a/compiler/GHC/Linker/Loader.hs
197+ +++ b/compiler/GHC/Linker/Loader.hs
198+ @@ -61,6 +61,7 @@ import GHC.ByteCode.Asm
199+ import GHC.ByteCode.Types
200+
201+ import GHC.SysTools
202+ + import GHC.SysTools.Ar (loadArchiveOrScript, ArchiveOrScript(..), LinkerScript(..))
203+
204+ import GHC.Types.Basic
205+ import GHC.Types.Name
206+ @@ -1151,7 +1152,7 @@ loadPackage interp hsc_env pkg
207+ #endif
208+ objs = [ obj | Objects objs <- classifieds
209+ , obj <- objs ]
210+ - archs = [ arch | Archive arch <- classifieds ]
211+ + archPaths = [ arch | Archive arch <- classifieds ]
212+
213+ -- Add directories to library search paths
214+ let dll_paths = map takeDirectory known_dlls
215+ @@ -1175,7 +1176,8 @@ loadPackage interp hsc_env pkg
216+ -- Ordering isn't important here, because we do one final link
217+ -- step to resolve everything.
218+ mapM_ (loadObj interp) objs
219+ - mapM_ (loadArchive interp) archs
220+ + resolvedArchives <- resolveArchives interp hsc_env dirs_env gcc_paths archPaths
221+ + mapM_ (loadArchive interp) resolvedArchives
222+
223+ maybePutStr logger "linking ... "
224+ ok <- resolveObjs interp
225+ @@ -1194,6 +1196,16 @@ loadPackage interp hsc_env pkg
226+ <> pprUnitInfoForUser pkg <> text "'"
227+ in throwGhcExceptionIO (InstallationError (showSDoc dflags errmsg))
228+
229+ + resolveArchives :: Interp -> HscEnv -> [FilePath] -> [FilePath] -> [FilePath] -> IO [FilePath]
230+ + resolveArchives interp hsc_env dirs_env gcc_paths paths = fmap concat $ forM paths $ \path -> do
231+ + arOrScript <- loadArchiveOrScript path
232+ + case arOrScript of
233+ + Ar _ -> return [path]
234+ + ImplicitLinkerScript (INPUT libs) -> do
235+ + classifiedLibs <- mapM (locateLib interp hsc_env False dirs_env gcc_paths) libs
236+ + let resolvedPaths = [arch | Archive arch <- classifiedLibs]
237+ + resolveArchives interp hsc_env dirs_env gcc_paths resolvedPaths
238+ +
239+ {-
240+ Note [Crash early load_dyn and locateLib]
241+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242+
0 commit comments