Linux (ELF) Support for "ghc -static -shared"
On some platforms it is possible to create a stand-alone shared library out of some object Foo.o
including foreign exports with something like:
ghc -static -shared Foo.o ...
The resulting library will have Foo
's dependencies including base
as well as the RTS statically linked in. On BSDs this is possible because generating position independent code is the default there, and on Windows this is possible because the dynamic loader uses some magic that doesn't require position independent code. Unfortunately on Linux this is not possible because libHSbase
, libHSrts
, etc. 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.
There are use cases for compiling Haskell code into a single shared object that does not have additional runtime dependencies. Suppose one wishes to write a plugin for a program in Haskell. It would be nice to provide the plugin as a single shared object, rather than requiring GHC's libraries to be present at runtime as well.
An easy solution might be adding a switch to the configure script or build.mk
to make it easier to build GHC+libs with -fPIC
on Linux. Ideally it would be possible to build and install both PIC and non-PIC libraries and have GHC choose the correct one at link time based on the flags and target platform, since PIC code carries a small space/performance overhead and isn't necessary on Linux in most cases.
I don't know my way around GHC(outside of the GHC API) or the build system that well yet, but if adding extra build system flags and GHC link-time flag handling code to make this work is an acceptable solution I'm happy to spend the time to get this working.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |