diff --git a/compiler/GHC.hs b/compiler/GHC.hs
index 3538bac52bbc8c71ae271696489a4dfb48d1aea2..776fb7e7632181c456a22d778e7d4fcd7c3d1bcc 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 ""