Linux (ELF) Support for "ghc -static -shared"

Travis Whitaker pi.boy.travis at gmail.com
Sat Jun 4 05:48:16 UTC 2016


Suppose I have some module Foo with foreign exports. On some platforms I
can do something like:

ghc -static -shared Foo.o ...

The resulting shared library would have the base libraries and the RTS
statically linked in. From what I understand this is possible on BSDs
because generating PIC is the default there (for making PIEs I'd imagine),
and possible on Windows because the dynamic loading process involves some
technique that doesn't require PIC. On Linux (at least x86_64) this doesn't
work by default since libHSbase, libHSrts et al. are not built with -fPIC
unless one specifically asks for it when building GHC. As far as I know
this is the only way to get -static -shared to work on this platform.

While the use cases for such stand-alone shared libraries might be small
niches, I was curious whether or not there was any discussion about
potential strategies for making it easier to build them for Linux. At the
very least, perhaps a single switch for the configure script or build.mk to
make it easier to build GHC+libs with -fPIC on Linux. Another step up might
be providing *_PIC.a objects for the base libraries, so that the non-PIC
objects are still available for the majority of cases in which PIC is not
required.

Thanks for your time,

Travis Whitaker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160604/c266c0e6/attachment.html>


More information about the ghc-devs mailing list