From bc833406244ce6e5d95a5ce9d40c3dfbcf783c46 Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Wed, 16 Oct 2024 18:31:54 +0000 Subject: [PATCH] driver: fix getGccSearchDirectory for wasm target This commit fixes getGccSearchDirectory logic for wasm target, ensures the correct search directory containing libc.so etc can be found by GHC. getGccSearchDirectory is also exported so it can be used elsewhere to obtain the wasi-sdk libdir and pass to the dyld script. (cherry picked from commit b562e3a6fab87422f40997f84b11a05505df2fcb) --- compiler/GHC/Linker/Loader.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs index adc729f31ed..a612a395d26 100644 --- a/compiler/GHC/Linker/Loader.hs +++ b/compiler/GHC/Linker/Loader.hs @@ -33,6 +33,7 @@ module GHC.Linker.Loader , modifyLoaderState , initLinkDepsOpts , partitionLinkable + , getGccSearchDirectory ) where @@ -1491,12 +1492,11 @@ searchForLibUsingGcc logger dflags so dirs = do -- libraries and components. See Note [Fork/Exec Windows]. getGCCPaths :: Logger -> DynFlags -> OS -> IO [FilePath] getGCCPaths logger dflags os - = case os of - OSMinGW32 -> + | os == OSMinGW32 || platformArch (targetPlatform dflags) == ArchWasm32 = do gcc_dirs <- getGccSearchDirectory logger dflags "libraries" sys_dirs <- getSystemDirectories return $ nub $ gcc_dirs ++ sys_dirs - _ -> return [] + | otherwise = return [] -- | Cache for the GCC search directories as this can't easily change -- during an invocation of GHC. (Maybe with some env. variable but we'll) @@ -1529,7 +1529,7 @@ getGccSearchDirectory logger dflags key = do modifyIORef' gccSearchDirCache ((key, dirs):) return val where split :: FilePath -> [FilePath] - split r = case break (==';') r of + split r = case break (`elem` [';', ':']) r of (s, [] ) -> [s] (s, (_:xs)) -> s : split xs -- GitLab