Ticket #6107: REPORT

File REPORT, 1.7 KB (added by exFalso, 2 years ago)
Line 
1GHCi'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".
2This means that for example one cannot link using the FFI with libraries having multiple common symbols if TH splices are used.
3
4To illustrate let's create two object files both defining the same common symbol:
5
6commonSym.c
7{{{
8volatile commonSym;
9}}}
10
11{{{
12$ gcc -o commonSym.o commonSym.c -c
13$ gcc -o commonSym2.o commonSym.c -c
14$ nm commonSym.o commonSym2.o
15
16commonSym.o:
170000000000000004 C commonSym
18
19commonSym2.o:
200000000000000004 C commonSym
21}}}
22
23Now we create two dummy .hs files, one having a TH splice which (i'm guessing) triggers the runtime linker.
24
25Works.hs
26{{{
27module Works where
28}}}
29
30DoesntWork.hs
31{{{
32{-# LANGUAGE TemplateHaskell #-}
33module DoesntWork where
34$(return [])
35}}}
36
37{{{
38$ ghc Works.hs commonSym.o commonSym2.o
39[1 of 1] Compiling Works            ( Works.hs, Works.o )
40
41$ ghc DoesntWork.hs commonSym.o commonSym2.o
42[1 of 1] Compiling DoesntWork       ( DoesntWork.hs, DoesntWork.o )
43Loading package ghc-prim ... linking ... done.
44Loading package integer-gmp ... linking ... done.
45Loading package base ... linking ... done.
46Loading object (static) commonSym.o ... done
47Loading object (static) commonSym2.o ...
48
49GHCi runtime linker: fatal error: I found a duplicate definition for symbol
50   commonSym
51whilst processing object file
52   commonSym2.o
53(...)
54}}}
55
56Just to make sure that this -should- link:
57
58works.c
59{{{
60extern commonSym;
61int main (void)
62{
63    int _ = commonSym;
64}
65}}}
66
67{{{
68$ gcc -o works.o works.c -c
69$ nm works.o
70                 U commonSym
710000000000000000 T main
72$ gcc -o works works.o commonSym.o commonSym2.o
73$ ./works ; echo $?
740
75}}}