[Haskell-cafe] Haskell plugin dynamic linking issue

Lana Black lanablack at amok.cc
Mon Apr 10 20:58:26 UTC 2017


On 10/04/17 18:41, Harendra Kumar wrote:
> You can try using ghc directly (instead of cabal) so that you have full
> control over what flags are passed, like this:
> 
> ghc -fPIC -dynamic -package xx -c plugin.hs
> ld -shared -Bsymbolic -L<path to rts lib> -lHSrts-ghc8.0.2 -o plugin.so
> plugin.o
> 
> If this works then you can find what is wrong/different with your cabal
> setup by using verbose flags and looking at what is being passed to ghc.
> 
> -harendra

Thank you for the idea. That way everything works.

I created a repo with a small demo of this issue [1]. For some reason,
when options -fPIC -dynamic -shared are present, cabal creates an
executable a.out and links in with RTS instead. The shared library on
the other hand isn't linked with RTS in any case unless ghc is called
directly.

~/devel/hs/cabal-bug> cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring cabal-bug-0.1...
Building cabal-bug-0.1...
Preprocessing library cabal-bug-0.1...
[1 of 1] Compiling Cabal.Bug        ( src/Cabal/Bug.hs,
dist/build/Cabal/Bug.o )
Linking a.out ...

~/devel/hs/cabal-bug> ldd a.out
	linux-vdso.so.1 (0x00007ffc403e6000)
	libHSrts-ghc8.0.2.so => /usr/lib64/ghc-8.0.2/rts/libHSrts-ghc8.0.2.so
(0x00007f62fb591000)
	libHSbase-4.9.1.0-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0-ghc8.0.2.so
(0x00007f62fa987000)
	libHSinteger-gmp-1.0.0.1-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/integer-gmp-1.0.0.1/libHSinteger-gmp-1.0.0.1-ghc8.0.2.so
(0x00007f62fa751000)
	libHSghc-prim-0.5.0.0-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/ghc-prim-0.5.0.0/libHSghc-prim-0.5.0.0-ghc8.0.2.so
(0x00007f62fa366000)
	libgmp.so.10 => /usr/lib64/libgmp.so.10 (0x00007f62fa0c8000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f62f9dc5000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f62f9a2c000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f62f9823000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f62f961f000)
	libffi.so.6 => /usr/lib64/libffi.so.6 (0x00007f62f9416000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f62f91f9000)
	/lib64/ld-linux-x86-64.so.2 (0x000055768de76000)

~/devel/hs/cabal-bug> ldd
dist/build/libHScabal-bug-0.1-50NTk4EdDNe8utEsR21Nft-ghc8.0.2.so
	linux-vdso.so.1 (0x00007fff249d9000)
	libHSbase-4.9.1.0-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0-ghc8.0.2.so
(0x00007f6c90bb4000)
	libHSinteger-gmp-1.0.0.1-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/integer-gmp-1.0.0.1/libHSinteger-gmp-1.0.0.1-ghc8.0.2.so
(0x00007f6c9097d000)
	libHSghc-prim-0.5.0.0-ghc8.0.2.so =>
/usr/lib64/ghc-8.0.2/ghc-prim-0.5.0.0/libHSghc-prim-0.5.0.0-ghc8.0.2.so
(0x00007f6c90592000)
	libgmp.so.10 => /usr/lib64/libgmp.so.10 (0x00007f6c902f5000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f6c8fff1000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f6c8fc58000)
	/lib64/ld-linux-x86-64.so.2 (0x000055f911c1d000)


Is this a bug in cabal?

[1]: https://github.com/greydot/cabal-bug


More information about the Haskell-Cafe mailing list