summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorAdam Sandberg Ericsson <adam@sandbergericsson.se>2020-05-03 11:49:46 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-07-07 13:56:02 -0400
commitf496c9550098ffaa3bf25a3447c138626d79bae0 (patch)
treea0be56bcc35f868f33b60bede633707065aec782 /testsuite
parentcdfeb3f24f76e8fd30452016676e56fbc827789a (diff)
downloadhaskell-f496c9550098ffaa3bf25a3447c138626d79bae0.tar.gz
add -flink-rts flag to link the rts when linking a shared or static library #18072
By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/dynlibs/Makefile32
-rw-r--r--testsuite/tests/dynlibs/T18072.hs10
-rw-r--r--testsuite/tests/dynlibs/all.T9
3 files changed, 50 insertions, 1 deletions
diff --git a/testsuite/tests/dynlibs/Makefile b/testsuite/tests/dynlibs/Makefile
index 2a530a5aeb..19009605ea 100644
--- a/testsuite/tests/dynlibs/Makefile
+++ b/testsuite/tests/dynlibs/Makefile
@@ -14,7 +14,7 @@ T3807:
# libraries. This is done to allow the RTS flavour to be chosen later (i.e.
# when linking an executable).
# Hence we must explicitly linking with the RTS here.
- '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 --make -dynamic -fPIC -shared T3807Export.hs T3807-export.c -o T3807test.so -lHSrts-ghc`'$(TEST_HC)' $(TEST_HC_OPTS) --numeric-version`
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 --make -dynamic -fPIC -shared T3807Export.hs T3807-export.c -o T3807test.so -flink-rts
'$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -no-auto-link-packages -no-hs-main T3807-load.c -o T3807-load -ldl
./T3807-load
@@ -61,3 +61,33 @@ T5373:
T13702:
'$(TEST_HC)' -v0 -dynamic -rdynamic -fPIC -pie T13702.hs
./T13702
+
+.PHONY: T18072
+T18072:
+ $(RM) -rf T18072/
+ mkdir T18072
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072 \
+ -dynamic -fPIC -c T18072.hs
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072 \
+ -dynamic -shared -flink-rts T18072/T18072.o -o T18072/T18072.so
+ ldd T18072/T18072.so | grep libHSrts >/dev/null
+
+.PHONY: T18072debug
+T18072debug:
+ $(RM) -rf T18072debug/
+ mkdir T18072debug
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072debug \
+ -dynamic -fPIC -c T18072.hs
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072debug \
+ -dynamic -shared -flink-rts -debug T18072debug/T18072.o -o T18072debug/T18072.so
+ ldd T18072debug/T18072.so | grep libHSrts | grep _debug >/dev/null
+
+.PHONY: T18072static
+T18072static:
+ $(RM) -rf T18072static/
+ mkdir T18072static
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072static \
+ -c T18072.hs
+ '$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 -outputdir T18072static \
+ -staticlib -fno-link-rts T18072static/T18072.o -o T18072static/T18072.a
+ ar t T18072static/T18072.a | grep RtsSymbols.o > /dev/null && exit 1 || exit 0
diff --git a/testsuite/tests/dynlibs/T18072.hs b/testsuite/tests/dynlibs/T18072.hs
new file mode 100644
index 0000000000..39a174f2ae
--- /dev/null
+++ b/testsuite/tests/dynlibs/T18072.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module T18072 where
+
+import Foreign.C
+
+foo :: IO CInt
+foo = return 3
+
+foreign export ccall foo :: IO CInt
diff --git a/testsuite/tests/dynlibs/all.T b/testsuite/tests/dynlibs/all.T
index aaa7a62774..b7272d4bac 100644
--- a/testsuite/tests/dynlibs/all.T
+++ b/testsuite/tests/dynlibs/all.T
@@ -7,3 +7,12 @@ test('T5373', [req_shared_libs], makefile_test, [])
# It's not clear exactly what platforms we can expect this to succeed on.
test('T13702', unless(opsys('linux'), skip), makefile_test, [])
+
+# test that -shared and -flink-rts actually links the rts
+test('T18072', [req_shared_libs, unless(opsys('linux'), skip)], makefile_test, [])
+
+# test that -shared and -flink-rts respects alternative RTS flavours
+test('T18072debug', [extra_files(['T18072.hs']), req_shared_libs, unless(opsys('linux'), skip)], makefile_test, [])
+
+# check that -staticlib and -fno-link-rts results in an archive without the RTR libary
+test('T18072static', [extra_files(['T18072.hs']), unless(opsys('linux'), skip)], makefile_test, [])