Duplicate symbol error when loading an archive twice
ghci can load packages from object files (*.o) and from archive files (*.a). When an object file is loaded twice, the second attempt is silently ignored. When an archive file is loaded twice, ghci aborts with the message "fatal error: I found a duplicate definition for symbol s", for the first symbol s in the archive.
Patch
The attached patch changes rts/Linker.c
so that loading an archive file twice silently ignores the second attempt, just like it does with object files.
Repro steps
Install a package using Cabal 1.18.*, as that version only produces archives and not objects.
Then, force ghci to load that package twice. One way to do this is to use hint inside ghci to load a value from the package.
$ ghci
> import Hello
> import Language.Haskell.Interpreter
> r <- runInterpreter $ setImports ["Hello"] >> interpret "Hello" (as :: Hello)
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package filepath-1.3.0.1 ... linking ... done.
Loading package old-locale-1.0.0.5 ... linking ... done.
Loading package time-1.4.0.1 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package unix-2.6.0.1 ... linking ... done.
Loading package directory-1.2.0.1 ... linking ... done.
Loading package old-time-1.1.0.1 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package process-1.1.0.2 ... linking ... done.
Loading package Cabal-1.16.0 ... linking ... done.
Loading package binary-0.5.1.1 ... linking ... done.
Loading package bin-package-db-0.0.0.0 ... linking ... done.
Loading package hoopl-3.9.0.0 ... linking ... done.
Loading package hpc-0.6.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package ghc-7.6.3 ... linking ... done.
Loading package utf8-string-0.3.8 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package hello-0.1.0.0 ... linking ... done.
Loading package mtl-2.1.3.1 ... linking ... done.
Loading package exceptions-0.3.3.1 ... linking ... done.
Loading package extensible-exceptions-0.1.1.4 ... linking ... done.
Loading package ghc-mtl-1.1.0.0 ... linking ... done.
Loading package ghc-paths-0.1.0.9 ... linking ... done.
Loading package random-1.0.1.1 ... linking ... done.
Loading package hint-0.4.0.0 ... linking ... done.
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
___stginit_hellozm0zi1zi0zi0_Hello
whilst processing object file
/Users/gelisam/.cabal/lib/x86_64-osx-ghc-7.6.3/hello-0.1.0.0/libHShello-0.1.0.0.a
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
A minimal definition for the hello package is attached, but doesn't contain anything relevant to the issue. It's just a dummy datatype:
{-# LANGUAGE DeriveDataTypeable #-}
module Hello where
import Data.Typeable
data Hello = Hello deriving Typeable
Workaround
Use Cabal 1.16, which (also) installs object files.
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | simonmar |
Operating system | |
Architecture |