Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared libraries produced by GHC can't see libffi libraries #1081

Closed
ocharles opened this issue Oct 16, 2013 · 2 comments
Closed

Shared libraries produced by GHC can't see libffi libraries #1081

ocharles opened this issue Oct 16, 2013 · 2 comments
Assignees
Labels
0.kind: bug Something is broken

Comments

@ocharles
Copy link
Contributor

Example:

[ollie@io:~]$ cat Test.hs
module Foo where
five = 5

[ollie@io:~]$ ghc -o test.so -c -shared -fPIC -dynamic --make Test.hs -lHSrts_debug-ghc7.6.3
Linking test.so ...

[ollie@io:~]$ ldd test.so
    linux-vdso.so.1 (0x00007fff5c5fe000)
    libHSrts_debug-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/libHSrts_debug-ghc7.6.3.so (0x00007fa499304000)
    libHSbase-4.6.0.1-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/base-4.6.0.1/libHSbase-4.6.0.1-ghc7.6.3.so (0x00007fa498a17000)
    libHSinteger-gmp-0.5.0.0-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/integer-gmp-0.5.0.0/libHSinteger-gmp-0.5.0.0-ghc7.6.3.so (0x00007fa498805000)
    libgmp.so.10 => /nix/store/xhi96qw8i4ms3q1z1grh6jsgwgz3sm4i-gmp-5.0.5/lib/libgmp.so.10 (0x00007fa49858d000)
    libHSghc-prim-0.3.0.0-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/ghc-prim-0.3.0.0/libHSghc-prim-0.3.0.0-ghc7.6.3.so (0x00007fa498319000)
    libc.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libc.so.6 (0x00007fa497f69000)
    libffi.so.6 => not found
    libm.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libm.so.6 (0x00007fa497c6a000)
    librt.so.1 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/librt.so.1 (0x00007fa497a62000)
    libdl.so.2 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libdl.so.2 (0x00007fa49785d000)
    /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib64/ld-linux-x86-64.so.2 (0x00007fa499798000)
    libpthread.so.0 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libpthread.so.0 (0x00007fa497641000)

[ollie@io:~]$ ghc -o test.so -c -shared -fPIC -dynamic --make Test.hs -lHSrts_debug-ghc7.6.3 -lffi
Linking test.so ...

[ollie@io:~]$ ldd test.so
    linux-vdso.so.1 (0x00007ffff97fe000)
    libHSrts_debug-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/libHSrts_debug-ghc7.6.3.so (0x00007f12790a8000)
    libffi.so.6 => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/libffi.so.6 (0x00007f1278e9a000)
    libHSbase-4.6.0.1-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/base-4.6.0.1/libHSbase-4.6.0.1-ghc7.6.3.so (0x00007f12785ae000)
    libHSinteger-gmp-0.5.0.0-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/integer-gmp-0.5.0.0/libHSinteger-gmp-0.5.0.0-ghc7.6.3.so (0x00007f127839b000)
    libgmp.so.10 => /nix/store/xhi96qw8i4ms3q1z1grh6jsgwgz3sm4i-gmp-5.0.5/lib/libgmp.so.10 (0x00007f1278123000)
    libHSghc-prim-0.3.0.0-ghc7.6.3.so => /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/ghc-prim-0.3.0.0/libHSghc-prim-0.3.0.0-ghc7.6.3.so (0x00007f1277eb0000)
    libc.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libc.so.6 (0x00007f1277aff000)
    libm.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libm.so.6 (0x00007f1277801000)
    librt.so.1 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/librt.so.1 (0x00007f12775f9000)
    libdl.so.2 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libdl.so.2 (0x00007f12773f4000)
    /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib64/ld-linux-x86-64.so.2 (0x00007f127953c000)
    libpthread.so.0 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libpthread.so.0 (0x00007f12771d8000)
@edolstra
Copy link
Member

The reason is that libHSrts_debug-ghc7.6.3.so lacks a proper RPATH:

# ldd /nix/store/xq36g6s6gy2ww14pqaspvm6ma98n6dc3-ghc-7.6.3/lib/ghc-7.6.3/libHSrts_debug-ghc7.6.3.so
        linux-vdso.so.1 (0x00007fffde198000)
        libffi.so.6 => not found
        libm.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libm.so.6 (0x00007fe475c0f000)
        librt.so.1 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/librt.so.1 (0x00007fe475a06000)
        libdl.so.2 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libdl.so.2 (0x00007fe475802000)
        libc.so.6 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libc.so.6 (0x00007fe475452000)
        libpthread.so.0 => /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib/libpthread.so.0 (0x00007fe475235000)
        /nix/store/zm4bhsm8lprkzvrjgqr0klfkvr21als4-glibc-2.17/lib64/ld-linux-x86-64.so.2 (0x00007fe4761a0000)

So applications that link against libHSrts_debug-ghc7.6.3.so will fail unless they explicitly link against libffi themselves.

This suggests that GHC should be built with NIX_LDFLAGS set to -rpath $out/lib/ghc-<version> or something like that.

(Ping @peti, @kosmikus)

peti added a commit that referenced this issue Oct 18, 2013
…other

Prior to this patch, libHSrts.so didn't know how to load libffi.so.
See issue #1081 for further details.
@peti
Copy link
Member

peti commented Oct 18, 2013

There is a whole bunch of Haskell-related improvements in stdenv-updates that would be nice to have in master -- including this one. When I get the chance, I'll try to merge those patches into master separately, so that we can have those improvements soon.

@ghost ghost assigned peti Oct 18, 2013
@peti peti closed this as completed Oct 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants