[GHC] #12388: Don't barf on failures in the RTS linker

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime | Version: 8.0.1 System (Linker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The RTS linker currently calls `barf()` when it fails. This is a problem because: 1. It appears that there is a bug in GHC, when there is no bug. 2. Failures to load code really should be recoverable. According to a `TODO` in the code, the culprit is resource deallocation, which is very difficult due to the code being written in C and having complicated control flow. There are a few solutions: - Port the RTS linker to C++ and use RAII for resource management. Failures would be handled (internally to the linker) by throwing a C++ exception. This is actually my favorite, but might not be popular with the GHC devs. - Build a huge context struct containing all needed resources and free it before returning. Signal errors with `longjmp()`. - Try to find each and every place where resources need to be free, and free them by hand. Signal errors with return codes. This seems too error-prone. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: erikd, bgamari, simonmar (added) Comment: Ccing the usual RTS people. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): I would be the first to agree that the RTS Linker code is nowhere near as nice as it should be be. This code has been put together via accretion over a decade or more. I has had over a dozen people work on it and all of those people know C but would prefer to write Haskell. Another problem is that code has to support at least 6 CPU architecture about 5 different Unix variants and Windows. I personally think porting the linker to C++ is a really bad idea. The linker is already under-resourced (in terms of people working on it) and using C++ instead of C would make it significantly more difficult for newcomers to work on it. As for your other two suggestions I have no strong feelings for or against, but would happy to have anyone work on the linker to help improve it. One last thought, a system using or based on talloc (https://talloc.samba.org/talloc/doc/html/index.html) may help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): I already fixed a bunch of these in 5300099edf106c1f5938c0793bd6ca199a0eebf0, but there are definitely more. I think you're talking about `loadArchive`, right? That's where I ran out of energy, because it needs a lot of refactoring. C++ would make it easy, but I don't think it's worth going to C++ just for this one bit of code. I would refactor it carefully, splitting up the function into smaller pieces and building a decent test suite. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): Something that might help here is gcc's cleanup attribute: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html which gives you some of the benefits of RAII in plain C. Going to C++ even for a small bit of the codebase would be a big step because we would have to use g++ as the linker and we get dependencies on C++ standard libs etc. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dobenour): I have a patch. It doesn't solve the problem completely, but it solves the problem in `loadArchive()`. Failures in that function now cause an error return and a message to be written via `errorBelch()`. This isn't great, but it is better than the current situation. Currently running `./validate --slow` to test. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2570 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => patch * differential: => Phab:D2570 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker
-------------------------------------+-------------------------------------
Reporter: dobenour | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2570
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12388: Don't barf on failures in the RTS linker
-------------------------------------+-------------------------------------
Reporter: dobenour | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2570
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12388: Don't barf on failures in the RTS linker
-------------------------------------+-------------------------------------
Reporter: dobenour | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2570
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2570 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2570 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: closed => new * resolution: fixed => Comment: Actually, there are plenty more `barf`s in the linker. This will be a long road... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12388#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12388: Don't barf on failures in the RTS linker
-------------------------------------+-------------------------------------
Reporter: dobenour | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2570
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari
participants (1)
-
GHC