id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
3252	having to call hs_add_root(__stginit_Foo) is a bit of a pain	duncan	simonmar	"For C code calling C functions exported from Haskell code, it has to jump through a couple hoops first. The call to `hs_init()` is fair enough and is specified by the FFI, however GHC also makes us call:
{{{
hs_add_root(__stginit_Foo);
}}}
for the top level Haskell module that exports the function we're interested in. If there are multiple such modules and they don't depend on each other then presumably we have to call them all.

Doing this is a bit annoying. It's not just that we have to call it, but we have to work out which symbols we need exactly. Are there any ways we could automate it? If the `__stginit_*` functions are really cheap then can we just have them called as constructor functions using gcc's `__attribute__ ((constructor))` system. If they're slightly more expensive then perhaps they could be registered in a constructor and called by `hs_init()`. Or can we have them run lazily, eg have the exported C functions check that the module they're in has been initialised."	feature request	closed	high	7.2.1	Compiler (FFI)	6.10.2	fixed		michal.terepeta@…	Unknown/Multiple	Unknown/Multiple	None/Unknown	Unknown				
