[commit: ghc] master: Fix #9438 by converting a panic to an error message (7613a81)

git at git.haskell.org git at git.haskell.org
Fri Apr 13 16:08:13 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7613a812888424b49cb334a4e63bd7280adf2774/ghc

>---------------------------------------------------------------

commit 7613a812888424b49cb334a4e63bd7280adf2774
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Fri Apr 13 11:33:54 2018 -0400

    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


>---------------------------------------------------------------

7613a812888424b49cb334a4e63bd7280adf2774
 compiler/ghci/Linker.hs                                   | 15 +++++++++++++--
 testsuite/.gitignore                                      |  1 +
 testsuite/tests/ghci/linking/Makefile                     |  8 ++++++++
 .../{driver/withRtsOpts.hs => ghci/linking/T14708.hs}     |  1 -
 testsuite/tests/ghci/linking/T14708.stderr                |  4 ++++
 testsuite/tests/ghci/linking/add.c                        |  1 +
 testsuite/tests/ghci/linking/all.T                        |  8 ++++++++
 7 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
index a91df32..8d0338a 100644
--- a/compiler/ghci/Linker.hs
+++ b/compiler/ghci/Linker.hs
@@ -71,7 +71,10 @@ import System.Win32.Info (getSystemDirectory)
 
 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
        = do b <- doesFileExist name
             if not b then return False
                      else do if dynamicGhc
-                                 then panic "Loading archives not supported"
+                                 then throwGhcExceptionIO $
+                                      CmdLineError dynamic_msg
                                  else loadArchive hsc_env name
                              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."
+          ]
 
 
 {- **********************************************************************
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index e6934f9..7c4453e 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -776,6 +776,7 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk
 /tests/ghci/linking/dir004/
 /tests/ghci/linking/dir005/
 /tests/ghci/linking/dir006/
+/tests/ghci/linking/T14708scratch/
 /tests/ghci/prog001/C.hs
 /tests/ghci/prog001/D.hs
 /tests/ghci/prog002/A.hs
diff --git a/testsuite/tests/ghci/linking/Makefile b/testsuite/tests/ghci/linking/Makefile
index 793152d..793998e 100644
--- a/testsuite/tests/ghci/linking/Makefile
+++ b/testsuite/tests/ghci/linking/Makefile
@@ -126,3 +126,11 @@ endif
 T3333:
 	"$(TEST_HC)" -c T3333.c -o 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
diff --git a/testsuite/tests/driver/withRtsOpts.hs b/testsuite/tests/ghci/linking/T14708.hs
similarity index 96%
copy from testsuite/tests/driver/withRtsOpts.hs
copy to testsuite/tests/ghci/linking/T14708.hs
index 0634af0..377b6b5 100644
--- a/testsuite/tests/driver/withRtsOpts.hs
+++ b/testsuite/tests/ghci/linking/T14708.hs
@@ -1,3 +1,2 @@
-
 main :: IO ()
 main = return ()
diff --git a/testsuite/tests/ghci/linking/T14708.stderr b/testsuite/tests/ghci/linking/T14708.stderr
new file mode 100644
index 0000000..fabbdb4
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T14708.stderr
@@ -0,0 +1,4 @@
+<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.
+
diff --git a/testsuite/tests/ghci/linking/add.c b/testsuite/tests/ghci/linking/add.c
new file mode 100644
index 0000000..538880c
--- /dev/null
+++ b/testsuite/tests/ghci/linking/add.c
@@ -0,0 +1 @@
+int add2(int x, int y) { return x + y; }
diff --git a/testsuite/tests/ghci/linking/all.T b/testsuite/tests/ghci/linking/all.T
index 124b3a4..f9617c5 100644
--- a/testsuite/tests/ghci/linking/all.T
+++ b/testsuite/tests/ghci/linking/all.T
@@ -31,3 +31,11 @@ test('T3333',
       unless(opsys('linux') or opsys('darwin') or ghc_dynamic(),
              expect_broken(3333))],
      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'])



More information about the ghc-commits mailing list