
#12031: GHCi segfaults on Windows when compiling C code using extern-declared
variable
----------------------------------------+-------------------------------
Reporter: RyanGlScott | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 8.0.1
Keywords: | Operating System: Windows
Architecture: Unknown/Multiple | Type of failure: GHCi crash
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
----------------------------------------+-------------------------------
Phyx- and I [https://phabricator.haskell.org/D1805#59850 noticed] that
`bindings-GLFW` unpredictably segfaults when running this simple program
in interpreted code:
{{{#!hs
module Main where
import qualified Graphics.UI.GLFW as G
main :: IO ()
main = do
successfulInit <- G.init
return ()
}}}
Phyx- [https://phabricator.haskell.org/D1805#60275 suspected] that it had
something to do with the `extern`-declared variables used in the GLFW
library itself. To avoid requiring a dependency on GLFW, I boiled the
issue down to a small, reproducible example with no dependencies, located
at https://github.com/RyanGlScott/extern-bug. I will reproduce the code
below:
{{{#!c
// foo.h
#ifndef FOO_H
#define FOO_H
extern int foo;
void bar(void);
void baz(void);
#endif
}}}
{{{#!c
// bar.c
#include "foo.h"
int foo = 0;
void bar(void) {
foo = 1;
baz();
}
}}}
{{{#!c
// baz.c
#include "foo.h"
#include