[GHC] #15729: Static GHCi can segfault when accessing .bss section in C
GHC
ghc-devs at haskell.org
Tue Oct 9 14:20:04 UTC 2018
#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
More information about the ghc-tickets
mailing list