GHCi runtime linker cannot link with duplicate common symbols
GHCi's runtime linker reports duplicate common symbols as fatal error. According to the nm manual: "When linking, multiple common symbols may appear with the same name". This means that for example one cannot link using the FFI with libraries having multiple common symbols if TH splices are used.
To illustrate let's create two object files both defining the same common symbol:
commonSym.c
volatile commonSym;
$ gcc -o commonSym.o commonSym.c -c
$ gcc -o commonSym2.o commonSym.c -c
$ nm commonSym.o commonSym2.o
commonSym.o:
0000000000000004 C commonSym
commonSym2.o:
0000000000000004 C commonSym
Now we create two dummy .hs files, one having a TH splice which (i'm guessing) triggers the runtime linker.
Works.hs
module Works where
DoesntWork.hs
{-# LANGUAGE TemplateHaskell #-}
module DoesntWork where
$(return [])
$ ghc Works.hs commonSym.o commonSym2.o
[1 of 1] Compiling Works ( Works.hs, Works.o )
$ ghc DoesntWork.hs commonSym.o commonSym2.o
[1 of 1] Compiling DoesntWork ( DoesntWork.hs, DoesntWork.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading object (static) commonSym.o ... done
Loading object (static) commonSym2.o ...
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
commonSym
whilst processing object file
commonSym2.o
(...)
Just to make sure that this -should- link:
works.c
extern commonSym;
int main (void)
{
int _ = commonSym;
}
$ gcc -o works.o works.c -c
$ nm works.o
U commonSym
0000000000000000 T main
$ gcc -o works works.o commonSym.o commonSym2.o
$ ./works ; echo $?
0
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Linux |
Architecture |