diff --git a/testsuite/mk/boilerplate.mk b/testsuite/mk/boilerplate.mk
index 53bd81f362441ab27f375983182b92ee82cb8045..6a3030ac065d764a38b40cf22aecaf09dd989a07 100644
--- a/testsuite/mk/boilerplate.mk
+++ b/testsuite/mk/boilerplate.mk
@@ -286,17 +286,17 @@ endif
 # See #11495 and TEST=TH_spliceE5_prof for a complication: trying to compile
 # code that uses TemplateHaskell with -prof, while GhcDynamic=YES.
 ifeq "$(GhcDynamic)" "YES"
-ghcThWayFlags     = -dynamic
-ghciWayFlags      = -dynamic
-ghcPluginWayFlags = -dynamic
+ghcThWayFlags     ?= -dynamic
+ghciWayFlags      ?= -dynamic
+ghcPluginWayFlags ?= -dynamic
 else ifeq "$(GhcProfiled)" "YES"
-ghcThWayFlags     = -prof
-ghciWayFlags      = -prof
-ghcPluginWayFlags = -prof
+ghcThWayFlags     ?= -prof
+ghciWayFlags      ?= -prof
+ghcPluginWayFlags ?= -prof
 else
-ghcThWayFlags     = -static
-ghciWayFlags      = -static
-ghcPluginWayFlags = -static
+ghcThWayFlags     ?= -static
+ghciWayFlags      ?= -static
+ghcPluginWayFlags ?= -static
 endif
 
 # -----------------------------------------------------------------------------
diff --git a/testsuite/tests/ffi/should_run/Makefile b/testsuite/tests/ffi/should_run/Makefile
index 374b24154ba2042a5e9548e96ea3e535fd599bb3..f910b1c3db62c5bdcef5fbad2936135d9cef0b8b 100644
--- a/testsuite/tests/ffi/should_run/Makefile
+++ b/testsuite/tests/ffi/should_run/Makefile
@@ -3,13 +3,13 @@ include $(TOP)/mk/boilerplate.mk
 include $(TOP)/mk/test.mk
 
 ffi018_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) -c ffi018_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c ffi018_ghci_c.c -o ffi018_ghci_c.o
 
 T1288_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T1288_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T1288_ghci_c.c -o T1288_ghci_c.o
 
 T2276_ghci_setup :
-	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T2276_ghci_c.c
+	'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T2276_ghci_c.c -o T2276_ghci_c.o
 
 ffi002_setup :
 	'$(TEST_HC)' $(TEST_HC_OPTS) -c ffi002.hs
diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T
index 6680bcabd07d4b8b792cb93f9267b2c256722ff4..3e430111333d1d97367ed2752c3e6b942bf34747 100644
--- a/testsuite/tests/ffi/should_run/all.T
+++ b/testsuite/tests/ffi/should_run/all.T
@@ -82,7 +82,7 @@ test('ffi018_ghci',
      [extra_files(['ffi018.h']),
       only_ways(['ghci']),
       when(unregisterised(), fragile(16085)),
-      pre_cmd('$MAKE -s --no-print-directory ffi018_ghci_setup'),
+      pre_cmd('$MAKE -s --no-print-directory ffi018_ghci_setup ghciWayFlags=' + config.ghci_way_flags),
       req_c],
      compile_and_run, ['ffi018_ghci_c.o'])
 
@@ -95,12 +95,12 @@ test('T1288', [req_c], compile_and_run, ['T1288_c.c'])
 test('T1288_ghci',
      [only_ghci,
       when(unregisterised(), fragile(16085)),
-      pre_cmd('$MAKE -s --no-print-directory T1288_ghci_setup')],
+      pre_cmd('$MAKE -s --no-print-directory T1288_ghci_setup ghciWayFlags=' + config.ghci_way_flags)],
      compile_and_run, ['T1288_ghci_c.o'])
 
 test('T2276', [req_c], compile_and_run, ['T2276_c.c'])
 test('T2276_ghci', [ only_ghci,
-                     pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup') ],
+                     pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup ghciWayFlags=' + config.ghci_way_flags) ],
                    compile_and_run, ['-fobject-code T2276_ghci_c.o'])
 
 test('T2469', normal, compile_and_run, ['-optc-std=gnu99'])
diff --git a/testsuite/tests/rts/T7040_ghci_c.c b/testsuite/tests/rts/T7040_ghci_c.c
index ee6ddd532863100c030198eb2f1ee2659b88eae7..84e71e18d8e269653a2a7692c85ae42decd033e7 100644
--- a/testsuite/tests/rts/T7040_ghci_c.c
+++ b/testsuite/tests/rts/T7040_ghci_c.c
@@ -7,5 +7,5 @@ void printx() {
   printf("x: %d\n", x);
   x = 1;
   printf("x: %d\n", x);
+  fflush(stdout);
 }
-
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index 5535308d62f32e3e8bb8765fc551356db7576a2c..bac79df1a376e7d7a02b95677f774b0fbcf9109b 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -278,8 +278,8 @@ test('T7040_ghci',
       only_ways(['ghci']),
       # Fragile when unregisterised; see #16085
       when(unregisterised(), skip),
-      pre_cmd('$MAKE -s --no-print-directory T7040_ghci_setup'),
-      when(opsys('linux') and not ghc_dynamic(), expect_broken(20706))],
+      pre_cmd('$MAKE -s --no-print-directory T7040_ghci_setup ghciWayFlags=' + config.ghci_way_flags),
+      when(opsys('linux') and not ghc_dynamic() and not arch('wasm32'), fragile(20706))],
      compile_and_run, ['T7040_ghci_c.o'])
 
 test('T7227', [extra_run_opts('+RTS -tT7227.stat --machine-readable -RTS')],