GHC compiling shared library linking problem
Richard Zetterberg
richard.zetterberg at googlemail.com
Mon Oct 15 15:25:20 CEST 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
6 import Foreign.Ptr (Ptr)
7 import Foreign.Storable (poke)
8 import Foreign.Marshal.Utils (copyBytes)
9 import Foreign.Marshal.Alloc (mallocBytes)
10 import Foreign.C.Types (CSize, CChar)
11 import Foreign.C.String
12 import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
13 import Assembly.Data
14 import qualified Assembly as ASM
15
16 type PPString = Ptr (Ptr CChar)
17 type PSize = Ptr CSize
18
19 foreign export ccall assemble :: PPString -> PSize -> CString ->
IO Int
And the module_init.c contains initialization of the module:
1 #define CAT(a,b) XCAT(a,b)
2 #define XCAT(a,b) a ## b
3 #define STR(a) XSTR(a)
4 #define XSTR(a) #a
5
6 #include <HsFFI.h>
7
8 extern void CAT(__stginit_, MODULE)(void);
9
10 static void library_init(void) __attribute__((constructor));
11 static void library_init(void)
12 {
13 static char *argv[] = { STR(MODULE) ".so", 0 }, **argv_ = argv;
14 static int argc = 1;
15
16 hs_init(&argc, &argv_);
17 hs_add_root(CAT(__stginit_, MODULE));
18 }
19
20 static void library_exit(void) __attribute__((destructor));
21 static void library_exit(void)
22 {
23 hs_exit();
24 }
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
So the question is, what could it be? Have I missed something? Or
should I report this as a bug?
Best regards
Richard Zetterberg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
iQIcBAEBAgAGBQJQfA6/AAoJEP99n2Mvs+maKp4P/iznMCLd73Os0tOarCHcyiK4
b96Zi1ibD5jqiojAWseoX3xCj4uNKIGy20GzDKRS5gZi3rXkw+wuCyLfj/RetrbN
8sy3RNVpbNulwRn/0HnFDOINpAOlO/y+6l45YcfhTSJGRCR0Hv7yhhlHbcyezZ+G
i4UORXygc2TnCVL1Vc0RdmmPOAehfmla1oo1bwmmQ6l6hhdrHJpo0jVukN+Dy+qv
enGF4Z9IMVjtgZizmEHmFA9UbMpKDDCXHKTsCSliSKErx4ebz0VeEkCCXWXE9c5M
0sUkAmDkiV8+CJ+RPJBMjIDihuothQ4Hpt2ZWBXo6I4D7J9MkkW8Qe9kmwvzLQQO
d7+w2qsHkI9x3bSnH6D3Co+crgqUnHf2OGDI8Hhbc2Ra82wcobCxHyxNWWAa8P07
q3/cu9xNDceTRnJ0tx9R2e9qByp5+eOAhtabNcX3yTsWWKSD2P0FNC2sjxMH/Psz
mWIDAiFfOGrKRAilm3CxokeX5k+tPMP+piU3b2WNPEJHaS/Hgl9Xl4eHi/DRnzJ7
9Fu09ynoB3yllPyIzLijXdOrwaTt7qWwxt48D1TwX+hl7CRxwOCFJKXyeZoRiSTc
D+Lbts5ST5skqnRHiQNxdrCODCvGoLhUJTDHEyVm3b9fFstkpR7tQc3nVywJ9DFH
p9Sh9UdEAc9a1URkCXS4
=ZU3J
-----END PGP SIGNATURE-----
More information about the Glasgow-haskell-users
mailing list