Death To __stginit_
Wolfgang Thaller
wolfgang.thaller at gmx.net
Wed Apr 13 17:59:32 EDT 2005
The __stginit_ module initialisation functions are currently used for
two purposes:
a) initialise foreign exports
b) initialise cost centers in profiled builds
So in non-profiled builds, they are only really needed in a few
modules. This is inefficient because:
1) useless code (init functions that are empty except for the call to
sub-modules) is generated
2) code from every module is swapped in at program startup
3) during static linking, a lot of modules are included in the program
just because they are imported, even if nothing from them is used.
Number 2 is not a big problem, because most of the code gets swapped in
anyway when the first garbage collection accesses the info tables.
Number 3 however can have a very big impact with libraries that are
built without split-objs and/or re-export a lot of modules from one big
parent module.
Instead of having a tree of functions which are explicitly invoked from
the RTS at startup, we could use GCC's __attribute__((constructor)) to
have foreign imports registered before main() is run.
Attached is a patch which makes GHC emit such
__attribute__((constructor)) functions to .stub.c files, thus making
__stginit_ functions unnecessary for non-profiled builds.
This greatly improves link times and executable sizes for the
Haskell/Objective-C binding HOC (hoc.sourceforge.net) :-).
Comments?
Cheers,
Wolfgang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stginit.patch
Type: application/octet-stream
Size: 6599 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/cvs-ghc/attachments/20050413/a5434b83/stginit.obj
-------------- next part --------------
More information about the Cvs-ghc
mailing list