From 80aa89831c18162ce5591400c41b4cd8f77db0e4 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Fri, 4 Oct 2024 00:00:41 +0000
Subject: [PATCH] driver: use interpreterDynamic predicate in preloadLib

This commit use the interpreterDynamic predicate in preloadLib to
decide if we should do dynLoadObjs instead of loadObj. Previously we
used hostIsDynamic which was only written with non-cross internal
interpreter in mind.

The testsuite is also adjusted to remove hard-wired -fPIC flag for
cbits (doesn't work in i386 RTS linker in vanilla way, #25260) and
properly pass ghc_th_way_flags to ghc.
---
 compiler/GHC/Linker/Loader.hs           | 4 ++--
 testsuite/tests/quasiquotation/Makefile | 6 +++---
 testsuite/tests/quasiquotation/all.T    | 2 +-
 testsuite/tests/th/all.T                | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs
index 8f5a013d6c4..c3f9a8de2e1 100644
--- a/compiler/GHC/Linker/Loader.hs
+++ b/compiler/GHC/Linker/Loader.hs
@@ -566,7 +566,7 @@ preloadLib interp hsc_env lib_paths framework_paths pls lib_spec = do
     preload_statics _paths names
        = do b <- or <$> mapM doesFileExist names
             if not b then return (False, pls)
-                     else if hostIsDynamic
+                     else if interpreterDynamic interp
                              then  do pls1 <- dynLoadObjs interp hsc_env pls names
                                       return (True, pls1)
                              else  do mapM_ (loadObj interp) names
@@ -575,7 +575,7 @@ preloadLib interp hsc_env lib_paths framework_paths pls lib_spec = do
     preload_static_archive _paths name
        = do b <- doesFileExist name
             if not b then return False
-                     else do if hostIsDynamic
+                     else do if interpreterDynamic interp
                                  then throwGhcExceptionIO $
                                       CmdLineError dynamic_msg
                                  else loadArchive interp name
diff --git a/testsuite/tests/quasiquotation/Makefile b/testsuite/tests/quasiquotation/Makefile
index 9a9db1ead9b..0f246c31eb0 100644
--- a/testsuite/tests/quasiquotation/Makefile
+++ b/testsuite/tests/quasiquotation/Makefile
@@ -10,6 +10,6 @@ T4150:
 	-'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -c T4150.hs
 
 T14028:
-	'$(TEST_HC)' $(TEST_HC_OPTS) -v0 T14028Quote.hs
-	'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -fPIC -c T14028C.c
-	'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -fexternal-interpreter T14028 T14028C.o
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) -v0 T14028Quote.hs
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) -v0 -c T14028C.c -o T14028C.o
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) -v0 -fexternal-interpreter T14028 T14028C.o
diff --git a/testsuite/tests/quasiquotation/all.T b/testsuite/tests/quasiquotation/all.T
index 875d38a6016..5c9e7560ec7 100644
--- a/testsuite/tests/quasiquotation/all.T
+++ b/testsuite/tests/quasiquotation/all.T
@@ -10,4 +10,4 @@ test('T14028',
       only_ways([config.ghc_th_way]),
       unless(config.have_ext_interp, skip),
       when(opsys('freebsd'), expect_broken(19723))],
-     makefile_test, ['T14028'])
+     makefile_test, ['T14028 ghcThWayFlags=' + config.ghc_th_way_flags])
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index dddfbdaca22..c590d1ba90f 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -591,7 +591,7 @@ test('T23829_hasty', normal, compile_fail, [''])
 test('T23829_hasty_b', normal, compile_fail, [''])
 test('T23927', normal, compile_and_run, [''])
 test('T23954', normal, compile_and_run, [''])
-test('T23309', [extra_files(['T23309A.hs']), req_c], multimod_compile, ['T23309', '-v0 T23309.c -optc-fPIC'])
+test('T23309', [extra_files(['T23309A.hs']), req_c], multimod_compile, ['T23309', '-v0 T23309.c ' + config.ghc_th_way_flags])
 test('T23378', [extra_files(['T23378A.hs']), js_skip], multimod_compile, ['T23378', '-v0'])
 test('T23962', normal, compile_and_run, [''])
 test('T23968', normal, compile_and_run, [''])
-- 
GitLab