Commit 7613a812 authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari

Fix #9438 by converting a panic to an error message

Previously, GHC was quite eager to panic whenever it was fed
an archive file when `DYNAMIC_GHC_PROGRAMS=YES`. This ought to be an
explicit error message instead, so this patch accomplishes just that.

Test Plan: make test TEST=T14708

Reviewers: Phyx, hvr, bgamari

Reviewed By: Phyx

Subscribers: thomie, carter

GHC Trac Issues: #9438, #14708, #15032

Differential Revision: https://phabricator.haskell.org/D4589
parent 6f623030
...@@ -71,7 +71,10 @@ import System.Win32.Info (getSystemDirectory) ...@@ -71,7 +71,10 @@ import System.Win32.Info (getSystemDirectory)
import Exception import Exception
import Foreign (Ptr) -- needed for 2nd stage -- needed for 2nd stage
#if STAGE >= 2
import Foreign (Ptr)
#endif
{- ********************************************************************** {- **********************************************************************
...@@ -504,9 +507,17 @@ preloadLib hsc_env lib_paths framework_paths pls lib_spec = do ...@@ -504,9 +507,17 @@ preloadLib hsc_env lib_paths framework_paths pls lib_spec = do
= do b <- doesFileExist name = do b <- doesFileExist name
if not b then return False if not b then return False
else do if dynamicGhc else do if dynamicGhc
then panic "Loading archives not supported" then throwGhcExceptionIO $
CmdLineError dynamic_msg
else loadArchive hsc_env name else loadArchive hsc_env name
return True return True
where
dynamic_msg = unlines
[ "User-specified static library could not be loaded ("
++ name ++ ")"
, "Loading static libraries is not supported in this configuration."
, "Try using a dynamic library instead."
]
{- ********************************************************************** {- **********************************************************************
......
...@@ -776,6 +776,7 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk ...@@ -776,6 +776,7 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk
/tests/ghci/linking/dir004/ /tests/ghci/linking/dir004/
/tests/ghci/linking/dir005/ /tests/ghci/linking/dir005/
/tests/ghci/linking/dir006/ /tests/ghci/linking/dir006/
/tests/ghci/linking/T14708scratch/
/tests/ghci/prog001/C.hs /tests/ghci/prog001/C.hs
/tests/ghci/prog001/D.hs /tests/ghci/prog001/D.hs
/tests/ghci/prog002/A.hs /tests/ghci/prog002/A.hs
......
...@@ -40,11 +40,11 @@ ghcilink002 : ...@@ -40,11 +40,11 @@ ghcilink002 :
ghcilink003 : ghcilink003 :
echo ":q" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -lstdc++ echo ":q" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -lstdc++
# Test 4: # Test 4:
# package P # package P
# library-dirs: `pwd`/dir004 # library-dirs: `pwd`/dir004
# extra-libraries: foo # extra-libraries: foo
# with # with
# dir004/libfoo.a # dir004/libfoo.a
LOCAL_PKGCONF004=dir004/local.package.conf LOCAL_PKGCONF004=dir004/local.package.conf
...@@ -68,11 +68,11 @@ ghcilink004 : ...@@ -68,11 +68,11 @@ ghcilink004 :
"$(AR)" cqs dir004/libfoo.a dir004/foo.o "$(AR)" cqs dir004/libfoo.a dir004/foo.o
echo "test" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -package-db $(LOCAL_PKGCONF004) -package test TestLink.hs echo "test" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -package-db $(LOCAL_PKGCONF004) -package test TestLink.hs
# Test 5: # Test 5:
# package P # package P
# library-dirs: `pwd`/dir005 # library-dirs: `pwd`/dir005
# extra-libraries: foo # extra-libraries: foo
# with # with
# dir005/libfoo.so # dir005/libfoo.so
LOCAL_PKGCONF005=dir005/ghcilink005.package.conf LOCAL_PKGCONF005=dir005/ghcilink005.package.conf
...@@ -96,7 +96,7 @@ ghcilink005 : ...@@ -96,7 +96,7 @@ ghcilink005 :
"$(TEST_HC)" -no-auto-link-packages -shared -o dir005/$(call DLL,foo) dir005/foo.o "$(TEST_HC)" -no-auto-link-packages -shared -o dir005/$(call DLL,foo) dir005/foo.o
echo "test" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -package-db $(LOCAL_PKGCONF005) -package test TestLink.hs echo "test" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -package-db $(LOCAL_PKGCONF005) -package test TestLink.hs
# Test 6: # Test 6:
# package P # package P
# extra-libraries: stdc++ # extra-libraries: stdc++
...@@ -126,3 +126,11 @@ endif ...@@ -126,3 +126,11 @@ endif
T3333: T3333:
"$(TEST_HC)" -c T3333.c -o T3333.o "$(TEST_HC)" -c T3333.c -o T3333.o
echo "weak_test 10" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) T3333.hs T3333.o echo "weak_test 10" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) T3333.hs T3333.o
.PHONY: T14708
T14708:
$(RM) -rf T14708scratch
mkdir T14708scratch
"$(TEST_HC)" -c add.c -o T14708scratch/add.o
"$(AR)" cqs T14708scratch/libadd.a T14708scratch/add.o
-"$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -LT14708scratch -ladd T14708.hs
main :: IO ()
main = return ()
<command line>: User-specified static library could not be loaded (T14708scratch/libadd.a)
Loading static libraries is not supported in this configuration.
Try using a dynamic library instead.
int add2(int x, int y) { return x + y; }
...@@ -31,3 +31,11 @@ test('T3333', ...@@ -31,3 +31,11 @@ test('T3333',
unless(opsys('linux') or opsys('darwin') or ghc_dynamic(), unless(opsys('linux') or opsys('darwin') or ghc_dynamic(),
expect_broken(3333))], expect_broken(3333))],
run_command, ['$MAKE -s --no-print-directory T3333']) run_command, ['$MAKE -s --no-print-directory T3333'])
test('T14708',
[extra_files(['T14708.hs', 'add.c']),
unless(doing_ghci, skip),
unless(ghc_dynamic(), skip),
extra_clean(['T14708scratch/*', 'T14708'])],
run_command,
['$MAKE -s --no-print-directory T14708'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment