[GHC] #15729: Static GHCi can segfault when accessing .bss section in C
#15729: Static GHCi can segfault when accessing .bss section in C --------------------------------------+------------------------------- Reporter: watashi | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Keywords: | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: GHCi crash Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: --------------------------------------+------------------------------- When an object file is statically linked, GHCi can return junk or segfault when trying to access data defined in .bss section via foreign call. {{{ watashi % ~/gao/ghc/inplace/bin/ghc-stage2 --info | grep Dynamic ,("Dynamic by default","NO") ,("GHC Dynamic","NO") watashi % cat bss.c int read_bss(int i) { static int bss[1 << 20]; return bss[i]; } watashi % ~/gao/ghc/inplace/bin/ghc-stage2 --interactive test.o GHCi, version 8.7.20180920: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/watashi/.ghci Prelude> :m + Foreign Foreign.C Prelude Foreign Foreign.C> foreign import ccall unsafe "read_bss" read_bss :: Int -> IO Int Prelude Foreign Foreign.C> read_bss 0 4294059519 Prelude Foreign Foreign.C> read_bss 1 65535 Prelude Foreign Foreign.C> mapM (read_bss . bit) [0 .. 19] zsh: segmentation fault (core dumped) ~/gao/ghc/inplace/bin/ghc-stage2 --interactive test.o }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------+-------------------------------------- Changes (by watashi): * owner: (none) => watashi -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------+-------------------------------------- Comment (by simonmar): I think this is the same as #781, one of the oldest bugs we still have open. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------+-------------------------------------- Comment (by watashi): @simonmar It's similar, but not exactly the same. I don't know how we can fix #781 with static link, but this one should be fixable by allocating the .bss section in the range of 2G with the object. I will send a fix. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #781 | Differential Rev(s): Phab:D5219 Wiki Page: | -------------------------------+-------------------------------------- Changes (by watashi): * differential: => Phab:D5219 * related: => #781 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #781 | Differential Rev(s): Phab:D5219 Wiki Page: | -------------------------------+-------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"8306141397d6e47a169dbe4b7ff1b3319a502aa7/ghc" 83061413/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="8306141397d6e47a169dbe4b7ff1b3319a502aa7" Allocate bss section within proper range of other sections Allocate bss section within proper range of other sections: * when `+RTS -xp` is passed, allocate it contiguously as we did for jump islands * when we mmap the code to lower 2Gb, we should allocate bss section there too This depends on {D5195} Test Plan: 1. `./validate` 2. with ``` DYNAMIC_GHC_PROGRAMS = NO DYNAMIC_BY_DEFAULT = NO ``` `TEST="T15729" make test` passed in both linux and macos. 3. Also test in a use case where we used to encouter error like: ``` ghc-iserv-prof: R_X86_64_PC32 relocation out of range: (noname) = b90282ba ``` and now, everything works fine. Reviewers: simonmar, bgamari, angerman, erikd Reviewed By: simonmar Subscribers: rwbarton, carter GHC Trac Issues: #15729 Differential Revision: https://phabricator.haskell.org/D5219 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: GHCi | Version: 8.6.1 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #781 | Differential Rev(s): Phab:D5219 Wiki Page: | -------------------------------+-------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.8.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: GHCi | Version: 8.6.1 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #781 | Differential Rev(s): Phab:D5219 Wiki Page: | -------------------------------+-------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"6e96aa2d503ddeeef1fa1f37b45d5c744522b64d/ghc" 6e96aa2/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="6e96aa2d503ddeeef1fa1f37b45d5c744522b64d" Don't use X86_64_ELF_NONPIC_HACK for +RTS -xp Summary: When `+RTS -xp` is passed, when don't need the X86_64_ELF_NONPIC_HACK, becasue the relocation offset should only be out of range if * the object file was not compiled with `-fPIC -fexternal-dynamic-refs`; * ghc generates non-pic code while it should (e.g. #15723) In either case, we should print an error message rather that silently attempt to use a hacky workaround that may not work. This could have made debugging #15723 and #15729 much easier. Test Plan: Run this in a case where ghci used to crash becasue of T15723. Now we see helpful message like: ``` ghc-iserv-prof: R_X86_64_PC32 relocation out of range: stmzm2zi4zi4zi1zmJQn4hNPyYjP5m9AcbI88Ve_ControlziConcurrentziSTMziTMVar_readTMVar_C61n_cc = 9b95ffac ``` Reviewers: simonmar, bgamari, erikd Reviewed By: simonmar, bgamari Subscribers: rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5233 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15729: Static GHCi can segfault when accessing .bss section in C -------------------------------+-------------------------------------- Reporter: watashi | Owner: watashi Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: GHCi | Version: 8.6.1 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #781 | Differential Rev(s): Phab:D5219 Wiki Page: | -------------------------------+-------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"740534d43cf9f1635c60f6311b7e0d89af962617/ghc" 740534d/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="740534d43cf9f1635c60f6311b7e0d89af962617" Allocate bss section within proper range of other sections Summary: This re-applies {D5195} and {D5235}, they were reverted as part of diff stack to unbreak i386. The proper fix is done in {D5289}. Allocate bss section within proper range of other sections: * when `+RTS -xp` is passed, allocate it contiguously as we did for jump islands * when we mmap the code to lower 2Gb, we should allocate bss section there too Test Plan: 1. `./validate` 2. with ``` DYNAMIC_GHC_PROGRAMS = NO DYNAMIC_BY_DEFAULT = NO ``` `TEST="T15729" make test` passed in both linux (both i386 and x86_64) and macos. 3. Also test in a use case where we used to encouter error like: ``` ghc-iserv-prof: R_X86_64_PC32 relocation out of range: (noname) = b90282ba ``` and now, everything works fine. Reviewers: simonmar, bgamari, angerman, erikd Reviewed By: simonmar Subscribers: rwbarton, carter GHC Trac Issues: #15729 Differential Revision: https://phabricator.haskell.org/D5290 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15729#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC