[Git][ghc/ghc][wip/T11531] Do not panic on linker errors

Peter Trommler gitlab at gitlab.haskell.org
Tue Mar 24 17:26:30 UTC 2020



Peter Trommler pushed to branch wip/T11531 at Glasgow Haskell Compiler / GHC


Commits:
f7334c1b by Peter Trommler at 2020-03-24T18:19:13+01:00
Do not panic on linker errors

- - - - -


7 changed files:

- compiler/GHC/Runtime/Linker.hs
- testsuite/tests/ghci/linking/Makefile
- + testsuite/tests/ghci/linking/T11531.c
- + testsuite/tests/ghci/linking/T11531.h
- + testsuite/tests/ghci/linking/T11531.hs
- + testsuite/tests/ghci/linking/T11531.stderr
- testsuite/tests/ghci/linking/all.T


Changes:

=====================================
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 at 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


=====================================
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


=====================================
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();
+}


=====================================
testsuite/tests/ghci/linking/T11531.h
=====================================
@@ -0,0 +1,2 @@
+int some_function(int d);
+


=====================================
testsuite/tests/ghci/linking/T11531.hs
=====================================
@@ -0,0 +1,3 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+foreign import ccall "T11531.h some_function" someFunction :: Int -> Int


=====================================
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
+


=====================================
testsuite/tests/ghci/linking/all.T
=====================================
@@ -43,6 +43,11 @@ test('T3333',
              expect_broken(3333))],
      makefile_test, ['T3333'])
 
+test('T11531',
+     [extra_files(['T11531.hs', 'T11531.c', 'T11531.h']),
+      unless(doing_ghci, skip)],
+     makefile_test, ['T11531'])
+
 test('T14708',
      [extra_files(['T14708.hs', 'add.c']),
       unless(doing_ghci, skip),



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f7334c1bca3d151aed224d708e65feb9afa22fd8

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f7334c1bca3d151aed224d708e65feb9afa22fd8
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200324/314755d6/attachment-0001.html>


More information about the ghc-commits mailing list