summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-10-01 10:36:59 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2021-10-04 07:54:18 +0000
commit8c46913229942887c27d4d2c40fc8acff761501d (patch)
treec1eba01eee33550453184b059d1ff0a0b8238fdf
parente8693713a40072a0dec5e83b1a31ffb0ee881633 (diff)
downloadhaskell-wip/T20436.tar.gz
Disable -dynamic-too if -dynamic is also passedwip/T20436
Before if you passed both options then you would generate two identical hi/dyn_hi and o/dyn_o files, both in the dynamic way. It's better to warn this is happening rather than duplicating the work and causing potential confusion. -dynamic-too should only be used with -static. Fixes #20436
-rw-r--r--compiler/GHC/Driver/Session.hs6
-rw-r--r--docs/users_guide/phases.rst2
-rw-r--r--testsuite/tests/driver/T20436/A.hs1
-rw-r--r--testsuite/tests/driver/T20436/Makefile23
-rw-r--r--testsuite/tests/driver/T20436/T20436.stderr3
-rw-r--r--testsuite/tests/driver/T20436/all.T1
6 files changed, 36 insertions, 0 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index f69f2da243..12f0e8be33 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -4609,6 +4609,12 @@ makeDynFlagsConsistent dflags
= let dflags' = gopt_unset dflags Opt_BuildDynamicToo
warn = "-dynamic-too is not supported on Windows"
in loop dflags' warn
+ -- Disable -dynamic-too if we are are compiling with -dynamic already, otherwise
+ -- you get two dynamic object files (.o and .dyn_o). (#20436)
+ | ways dflags `hasWay` WayDyn && gopt Opt_BuildDynamicToo dflags
+ = let dflags' = gopt_unset dflags Opt_BuildDynamicToo
+ warn = "-dynamic-too is ignored when using -dynamic"
+ in loop dflags' warn
-- Via-C backend only supports unregisterised ABI. Switch to a backend
-- supporting it if possible.
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst
index 6833ce36d7..0c334f037f 100644
--- a/docs/users_guide/phases.rst
+++ b/docs/users_guide/phases.rst
@@ -707,6 +707,8 @@ Options affecting code generation
and ``-dynhisuf`` are the counterparts of ``-o``, ``-osuf``, and
``-hisuf`` respectively, but applying to the dynamic compilation.
+ ``-dynamic-too`` is ignored if :ghc-flag:`-dynamic` is also specified.
+
.. ghc-flag:: -split-objs
:shortdesc: Split generated object files into smaller files
:type: dynamic
diff --git a/testsuite/tests/driver/T20436/A.hs b/testsuite/tests/driver/T20436/A.hs
new file mode 100644
index 0000000000..d843c00b78
--- /dev/null
+++ b/testsuite/tests/driver/T20436/A.hs
@@ -0,0 +1 @@
+module A where
diff --git a/testsuite/tests/driver/T20436/Makefile b/testsuite/tests/driver/T20436/Makefile
new file mode 100644
index 0000000000..de28eab08d
--- /dev/null
+++ b/testsuite/tests/driver/T20436/Makefile
@@ -0,0 +1,23 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+# Test for passing -dynamic and -dynamic-too together
+
+checkExists = [ -f $1 ] || echo $1 missing
+checkNotExists = [ ! -f $1 ] || echo $1 not missing
+
+clean:
+ rm -f *.o
+ rm -f *.hi
+ rm -f *.dyn_o
+ rm -f *.dyn_hi
+
+T20436: clean
+ '$(TEST_HC)' $(TEST_HC_OPTS) -dynamic -dynamic-too -v0 A.hs
+ $(call checkExists,A.hi)
+ $(call checkExists,A.o)
+ $(call checkNotExists,A.dyn_hi)
+ $(call checkNotExists,A.dyn_o)
+
+
diff --git a/testsuite/tests/driver/T20436/T20436.stderr b/testsuite/tests/driver/T20436/T20436.stderr
new file mode 100644
index 0000000000..1fda220263
--- /dev/null
+++ b/testsuite/tests/driver/T20436/T20436.stderr
@@ -0,0 +1,3 @@
+
+when making flags consistent: warning:
+ -dynamic-too is ignored when using -dynamic
diff --git a/testsuite/tests/driver/T20436/all.T b/testsuite/tests/driver/T20436/all.T
new file mode 100644
index 0000000000..3a2aa6a46a
--- /dev/null
+++ b/testsuite/tests/driver/T20436/all.T
@@ -0,0 +1 @@
+test('T20436', [extra_files(['A.hs']), when(opsys('mingw32'), skip)], makefile_test, [])