summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Trommler <ptrommler@acm.org>2020-02-16 18:48:25 +0100
committerPeter Trommler <ptrommler@acm.org>2020-03-25 13:55:17 +0100
commit883f59332c53f23a77bdbda69fa54d37a5ab708d (patch)
tree6af255a63c83471de303a6b0799997ca0a9e13dd
parent2643ba465cd2a133b6f495f34fc59cd1a6d23525 (diff)
downloadhaskell-wip/T11531.tar.gz
Do not panic on linker errorswip/T11531
-rw-r--r--compiler/GHC/Runtime/Linker.hs8
-rw-r--r--testsuite/tests/ghci/linking/Makefile5
-rw-r--r--testsuite/tests/ghci/linking/T11531.c9
-rw-r--r--testsuite/tests/ghci/linking/T11531.h2
-rw-r--r--testsuite/tests/ghci/linking/T11531.hs3
-rw-r--r--testsuite/tests/ghci/linking/T11531.stderr11
-rw-r--r--testsuite/tests/ghci/linking/all.T6
7 files changed, 41 insertions, 3 deletions
diff --git a/compiler/GHC/Runtime/Linker.hs b/compiler/GHC/Runtime/Linker.hs
index 331b460c06..c8b4b63a78 100644
--- a/compiler/GHC/Runtime/Linker.hs
+++ b/compiler/GHC/Runtime/Linker.hs
@@ -187,7 +187,7 @@ getHValue hsc_env name = do
m <- lookupClosure hsc_env (unpackFS sym_to_find)
case m of
Just hvref -> mkFinalizedHValue hsc_env hvref
- Nothing -> linkFail "GHC.ByteCode.Linker.lookupCE"
+ Nothing -> linkFail "GHC.Runtime.Linker.getHValue"
(unpackFS sym_to_find)
linkDependencies :: HscEnv -> PersistentLinkerState
@@ -472,7 +472,7 @@ preloadLib hsc_env lib_paths framework_paths pls lib_spec = do
Nothing -> maybePutStrLn dflags "done"
Just mm -> preloadFailed mm framework_paths lib_spec
return pls
- else panic "preloadLib Framework"
+ else throwGhcExceptionIO (ProgramError "preloadLib Framework")
where
dflags = hsc_dflags hsc_env
@@ -964,7 +964,9 @@ dynLoadObjs hsc_env pls@PersistentLinkerState{..} objs = do
m <- loadDLL hsc_env soFile
case m of
Nothing -> return $! pls { temp_sos = (libPath, libName) : temp_sos }
- Just err -> panic ("Loading temp shared object failed: " ++ err)
+ Just err -> linkFail msg err
+ where
+ msg = "GHC.Runtime.Linker.dynLoadObjs: Loading temp shared object failed"
rmDupLinkables :: [Linkable] -- Already loaded
-> [Linkable] -- New linkables
diff --git a/testsuite/tests/ghci/linking/Makefile b/testsuite/tests/ghci/linking/Makefile
index bfbcf24350..085e81765b 100644
--- a/testsuite/tests/ghci/linking/Makefile
+++ b/testsuite/tests/ghci/linking/Makefile
@@ -127,6 +127,11 @@ T3333:
"$(TEST_HC)" -c T3333.c -o T3333.o
echo "weak_test 10" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) T3333.hs T3333.o
+.PHONY: T11531
+T11531:
+ "$(TEST_HC)" -dynamic -fPIC -c T11531.c -o T11531.o
+ - echo ":q" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) T11531.o T11531.hs 2>&1 | sed -e '/undefined symbol:/d' 1>&2
+
.PHONY: T14708
T14708:
$(RM) -rf T14708scratch
diff --git a/testsuite/tests/ghci/linking/T11531.c b/testsuite/tests/ghci/linking/T11531.c
new file mode 100644
index 0000000000..9871afd7db
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T11531.c
@@ -0,0 +1,9 @@
+extern void undefined_function(void);
+
+int some_function(int d) {
+ return 64;
+}
+
+void __attribute__ ((constructor)) setup(void) {
+ undefined_function();
+}
diff --git a/testsuite/tests/ghci/linking/T11531.h b/testsuite/tests/ghci/linking/T11531.h
new file mode 100644
index 0000000000..084f0bbd41
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T11531.h
@@ -0,0 +1,2 @@
+int some_function(int d);
+
diff --git a/testsuite/tests/ghci/linking/T11531.hs b/testsuite/tests/ghci/linking/T11531.hs
new file mode 100644
index 0000000000..f75e8bb996
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T11531.hs
@@ -0,0 +1,3 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+foreign import ccall "T11531.h some_function" someFunction :: Int -> Int
diff --git a/testsuite/tests/ghci/linking/T11531.stderr b/testsuite/tests/ghci/linking/T11531.stderr
new file mode 100644
index 0000000000..98b9219530
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T11531.stderr
@@ -0,0 +1,11 @@
+
+GHC.Runtime.Linker.dynLoadObjs: Loading temp shared object failed
+During interactive linking, GHCi couldn't find the following symbol:
+This may be due to you not asking GHCi to load extra object files,
+archives or DLLs needed by your current session. Restart GHCi, specifying
+the missing library using the -L/path/to/object/dir and -lmissinglibname
+flags, or simply by naming the relevant files on the GHCi command line.
+Alternatively, this link failure might indicate a bug in GHCi.
+If you suspect the latter, please report this as a GHC bug:
+ https://www.haskell.org/ghc/reportabug
+
diff --git a/testsuite/tests/ghci/linking/all.T b/testsuite/tests/ghci/linking/all.T
index 6318fc22e9..ae93349f70 100644
--- a/testsuite/tests/ghci/linking/all.T
+++ b/testsuite/tests/ghci/linking/all.T
@@ -43,6 +43,12 @@ test('T3333',
expect_broken(3333))],
makefile_test, ['T3333'])
+test('T11531',
+ [extra_files(['T11531.hs', 'T11531.c', 'T11531.h']),
+ unless(doing_ghci, skip),
+ unless(opsys('linux'), skip)],
+ makefile_test, ['T11531'])
+
test('T14708',
[extra_files(['T14708.hs', 'add.c']),
unless(doing_ghci, skip),