Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

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 ``` <details><summary>Trac metadata</summary> | 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 | | </details> <!-- {"blocked_by":[],"summary":"GHCi runtime linker cannot link with duplicate common symbols","status":"New","operating_system":"Linux","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.4.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","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\".\r\nThis means that for example one cannot link using the FFI with libraries having multiple common symbols if TH splices are used.\r\n\r\nTo illustrate let's create two object files both defining the same common symbol:\r\n\r\ncommonSym.c\r\n{{{\r\nvolatile commonSym;\r\n}}}\r\n\r\n{{{\r\n$ gcc -o commonSym.o commonSym.c -c\r\n$ gcc -o commonSym2.o commonSym.c -c\r\n$ nm commonSym.o commonSym2.o\r\n\r\ncommonSym.o:\r\n0000000000000004 C commonSym\r\n\r\ncommonSym2.o:\r\n0000000000000004 C commonSym\r\n}}}\r\n\r\nNow we create two dummy .hs files, one having a TH splice which (i'm guessing) triggers the runtime linker.\r\n\r\nWorks.hs\r\n{{{\r\nmodule Works where\r\n}}}\r\n\r\nDoesntWork.hs\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\nmodule DoesntWork where\r\n$(return [])\r\n}}}\r\n\r\n{{{\r\n$ ghc Works.hs commonSym.o commonSym2.o\r\n[1 of 1] Compiling Works ( Works.hs, Works.o )\r\n\r\n$ ghc DoesntWork.hs commonSym.o commonSym2.o\r\n[1 of 1] Compiling DoesntWork ( DoesntWork.hs, DoesntWork.o )\r\nLoading package ghc-prim ... linking ... done.\r\nLoading package integer-gmp ... linking ... done.\r\nLoading package base ... linking ... done.\r\nLoading object (static) commonSym.o ... done\r\nLoading object (static) commonSym2.o ... \r\n\r\nGHCi runtime linker: fatal error: I found a duplicate definition for symbol\r\n commonSym\r\nwhilst processing object file\r\n commonSym2.o\r\n(...)\r\n}}}\r\n\r\nJust to make sure that this -should- link:\r\n\r\nworks.c\r\n{{{\r\nextern commonSym;\r\nint main (void)\r\n{\r\n int _ = commonSym;\r\n}\r\n}}}\r\n\r\n{{{\r\n$ gcc -o works.o works.c -c\r\n$ nm works.o\r\n U commonSym\r\n0000000000000000 T main\r\n$ gcc -o works works.o commonSym.o commonSym2.o\r\n$ ./works ; echo $?\r\n0\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue