[GHC] #12606: Linux (ELF) Support for "ghc -static -shared"
GHC
ghc-devs at haskell.org
Tue Sep 20 22:40:24 UTC 2016
#12606: Linux (ELF) Support for "ghc -static -shared"
----------------------------------------+---------------------------------
Reporter: tmobile | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: ⊥
Component: Compiler | Version: 8.0.1
Keywords: | Operating System: Linux
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
----------------------------------------+---------------------------------
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.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12606>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list