From 28b18d26601f6a4321bd53c735b0ddb7256ac415 Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Fri, 21 Feb 2025 20:38:00 +0000 Subject: [PATCH] driver: fix wasm backend sysroot lookup logic when -flto is passed For the wasm target, the driver calls `wasm32-wasi-clang --print-search-dirs` and finds the sysroot directory that contains libc.so etc, then passes the directory path to dyld. However, when GHC is configured with -flto as a part of C/C++ compiler flags, the clang driver would insert a llvm-lto specific directory in the --print-search-dirs output and the driver didn't take that into account. This patch fixes it and always selects the non-lto sysroot directory to be passed to dyld. This is one small step towards supporting building all cbits with lto for wasm. (cherry picked from commit 7eea38c838c9d839e9efea0e6d9f79034e99fa4f) --- compiler/GHC.hs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/GHC.hs b/compiler/GHC.hs index 3538bac52bb..776fb7e7632 100644 --- a/compiler/GHC.hs +++ b/compiler/GHC.hs @@ -713,11 +713,7 @@ setTopSessionDynFlags dflags = do #if defined(wasm32_HOST_ARCH) let libdir = sorry "cannot spawn child process on wasm" #else - libdir <- liftIO $ do - libdirs <- Loader.getGccSearchDirectory logger dflags "libraries" - case libdirs of - [_, libdir] -> pure libdir - _ -> panic "corrupted wasi-sdk installation" + libdir <- liftIO $ last <$> Loader.getGccSearchDirectory logger dflags "libraries" #endif let profiled = ways dflags `hasWay` WayProf way_tag = if profiled then "_p" else "" -- GitLab