Richard Zetterberg | 15 Oct 15:25 2012

GHC compiling shared library linking problem


Hello

This is the first time I'm mailing to this list, so I hope I have come
to the right place.

The problem I have is that I get a linker error when compiling a
shared library with GHC. This problem occurred after I updated GHC
from 7.0.3 to 7.4.1. Here is the error itself:

    /usr/bin/ld: ../src/Shared.so relocation R_X86_64_32S against
`ghczmprim_GHCziTypes_ZC_con_info` can not be used when making a
shared object; recompile with -fPIC
    ../src/Shared.so: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status

Here is the ghc command:

    ghc -O2 --make -no-hs-main -optl '-shared' -optc '-DMODULE=Shared'
-o ../bin/pet_assembler_core.so Shared ../src/shared/module_init.c
-i../src/;

Shared.hs is the file where I specify the interface for the library,
it only has one function:

    1 {-# LANGUAGE ForeignFunctionInterface #-}
    2
    3 module Shared where
    4
    5 import qualified Data.ByteString as BS
(Continue reading)

Carter Schonwald | 15 Oct 18:44 2012
Picon

Re: GHC compiling shared library linking problem

Hello Richard,

it sounds like you're using a ghc build that doesn't have the -dyn versions of the builtin libraries, do you have the same problem when doing a shared build without the foreign call ?

On Mon, Oct 15, 2012 at 9:25 AM, Richard Zetterberg <richard.zetterberg <at> googlemail.com> wrote:
GHCziTypes_ZC_con_info` can not be used when making a
shared object; recompile with -fPIC
    ../src/Shared.so: could not read

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Richard Zetterberg | 17 Oct 09:43 2012

Re: GHC compiling shared library linking problem


Hello

Thank you for the response!

I have two parts of my application; one which builds a cli application
which uses my module and one which builds a shared library which uses
the same module. I have no problems compiling my cli application. And if
I try to compile the shared library without the foreign export and the
functions in Shared.hs I get another linker error:

    /usr/bin/ld: ../src/Assembly.o: relocation R_X86_64_32S against
`stg_CAF_BLACKHOLE_info` can not be used when making a shared object;
recompile with -fPIC
    ../src/Assembly.o: could not read symbols: Bad value
    	collect2: error: ld returned 1 exit status

(I forgot to add that I'm using the haskell-platform package in Debian
sid (unstable). Here is the package and it's dependencies:
http://packages.debian.org/sid/haskell-platform.)

Best regards
Richard

On 10/15/12 6:44 PM, Carter Schonwald wrote:

Simon Marlow | 22 Oct 13:24 2012
Picon

Re: GHC compiling shared library linking problem

On 17/10/2012 08:43, Richard Zetterberg wrote:
> I have two parts of my application; one which builds a cli application
> which uses my module and one which builds a shared library which uses
> the same module. I have no problems compiling my cli application. And if
> I try to compile the shared library without the foreign export and the
> functions in Shared.hs I get another linker error:
>
>      /usr/bin/ld: ../src/Assembly.o: relocation R_X86_64_32S against
> `stg_CAF_BLACKHOLE_info` can not be used when making a shared object;
> recompile with -fPIC
>      ../src/Assembly.o: could not read symbols: Bad value
>      	collect2: error: ld returned 1 exit status
>
> (I forgot to add that I'm using the haskell-platform package in Debian
> sid (unstable). Here is the package and it's dependencies:
> http://packages.debian.org/sid/haskell-platform.)

I think you're trying to make a shared library from Haskell code, right? 
  You don't say what platform, but it looks like x86_64/Linux or maybe 
OS X.  On these platforms, code that goes into a shared library must be 
compiled with -fPIC.  You will also need to compile with -dynamic, in 
order to link against the shared versions of the RTS and the other 
Haskell libraries.

Cheers,
	Simon

>
> Best regards
> Richard
>
> On 10/15/12 6:44 PM, Carter Schonwald wrote:
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJQfmGPAAoJEP99n2Mvs+ma5KwP/1ZMZzZtNmQ7EUJSPg1mB3w7
> Wh1KQtgLrfcCggfeMlA/XOtUE+pgtN66uarbi9iaqLULH4fLm/h6v12zSmaqG1uU
> XKuaIRtr886+bcFG/fXO0pW7OGbaF/w0nQN06iRqbFrce0f/U3VGHp8BqJNZFhSK
> qIHRM+WweM95LV9tgrCAeI3C2sGR4GkzhUunCCAOSZ8MfEwFxPV4OsmuCjKGcCcb
> GZXXhOynGhbLa8mg29dQNytt01AMgBBiRSWLHVFW6IfUxPk7uuQp33Q6wvjOUyA4
> kJIUz9BU9IiPUeVdO2sg+fBB1ehOV2qPiqHf0xoJ1mpH6qd3KnUcJXsXrTXK4piz
> lo2lCOlqxspBiByX4HzyLE6pA+8OZcREO5GOHo5V4iI0RQAwkjaqARAU/6VVXHC0
> fQbPJf8U1CQZZamkuoTgUfKcOHLFYIqVq9p8Ar1dykT74okAyMR+FU0ExWTbr/Xs
> 7oGD+Q44geh65FkkeLUoKIUD+aV35HQE6GL9O/OjKm1aMg3yGA5bM6UUiAw2FgqE
> jfZoHc9frO/WMP1XgEkKQjtupUCH92ol/PpyPbFJqfnxMvvvI+lYEEIL90XPudmS
> 5ygqeinIVwBKGVb6D08rLC1OzaS0dFasOjOeWYM12epbZsy9WCzIl+U14TFgy/Ze
> la4rqefI8sdBK1cQslYu
> =RN8H
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users <at> haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
Richard Zetterberg | 22 Oct 14:16 2012

Re: GHC compiling shared library linking problem


Hello and thank you for the reply

Yes! It seems the details from my first mail (10/15/12 3:25 PM) fell
out. Here is the relevant parts from that mail:

"
The problem I have is that I get a linker error when compiling a
shared library with GHC. This problem occurred after I updated GHC
from 7.0.3 to 7.4.1. Here is the error itself:

    /usr/bin/ld: ../src/Shared.so relocation R_X86_64_32S against
`ghczmprim_GHCziTypes_ZC_con_info` can not be used when making a
shared object; recompile with -fPIC
    ../src/Shared.so: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status

Here is the ghc command:

    ghc -O2 --make -no-hs-main -optl '-shared' -optc '-DMODULE=Shared'
-o ../bin/pet_assembler_core.so Shared ../src/shared/module_init.c
-i../src/;

Information about the system:

Linux 2.6.32-5-amd64 Debian 6.0.6
GHC 7.4.1
GCC 4.7.2
GNU ld 2.22
"

I tried adding -fPIC and -dynamic to the ghc command:

   ghc -O2 --make -no-hs-main -optl '-shared' -optc '-DMODULE=Shared'
-o ../bin/pet_assembler_core.so Shared ../src/shared/module_init.c
-i../src/ -fPIC -dynamic;

And got this error:

    ../src/Shared.hs:1:1:
        Could not find module `Prelude`
        Perhaps you haven't installed the "dyn" libraries for package
`base'? 	
        Locations searched:
            Prelude.hs
            Prelude.lhs
            ../src/Prelude.hs
            ../src/Prelude.lhs
            /usr/lib/ghc/base-4.5.0.0/Prelude.dyn_hi

Does that mean I can just install those libraries or do have to
compile ghc from source and pass some flags to include those librares?

Best regards
Richard

On 10/22/12 1:24 PM, Simon Marlow wrote:

> I think you're trying to make a shared library from Haskell code,
> right? You don't say what platform, but it looks like x86_64/Linux
> or maybe OS X.  On these platforms, code that goes into a shared
> library must be compiled with -fPIC.  You will also need to compile
> with -dynamic, in order to link against the shared versions of the
> RTS and the other Haskell libraries.
> 
> Cheers, Simon
> 
> 
> 
> 
> 
>> 
>> Best regards Richard
>> 
>> On 10/15/12 6:44 PM, Carter Schonwald wrote:
>> 
>> 
>> 

Gmane