Ticket #6107 (new bug)
GHCi runtime linker cannot link with duplicate common symbols
| Reported by: | exFalso | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.8.1 |
| Component: | Compiler | Version: | 7.4.1 |
| Keywords: | Cc: | ||
| Operating System: | Linux | Architecture: | Unknown/Multiple |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | Blocked By: | #3658 | |
| Blocking: | Related Tickets: |
Description
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
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

