ghci attempts to link entire package

Related to some of the problems Takusen users have had, I have a question about ghci's linker/loader: why does it appear to try to link an entire package archive, rather than just the modules that are used? This is in contrast to the GNU ld program which the compiler uses, which only tries to link modules which are actually used. Is this a feature or a bug? Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. *****************************************************************

Bayley, Alistair wrote:
Related to some of the problems Takusen users have had, I have a question about ghci's linker/loader: why does it appear to try to link an entire package archive, rather than just the modules that are used? This is in contrast to the GNU ld program which the compiler uses, which only tries to link modules which are actually used.
Is this a feature or a bug?
Neither really, just a consequence of the design. GHCi's linker only knows how to link object files, and when it links a package it actually linked a specially generated single .o file constructed by linking together all the object files in the package. There has been talk of adding support to link .a files which would simplify package management, but I guess it might make linking slower. If there's a use case that requires partial linking of a package, then we could consider the lack of partial linking a bug - can you describe why you need it? Cheers, Simon

From: Simon Marlow [mailto:simonmarhaskell@gmail.com]
Is this a feature or a bug?
Neither really, just a consequence of the design.
Well, that would make it a feature, then ;-)
There has been talk of adding support to link .a files which would simplify package management, but I guess it might make linking slower.
If there's a use case that requires partial linking of a package, then we could consider the lack of partial linking a bug - can you describe why you need it?
With Takusen, all modules, including the DBMS-specific modules, are compiled into a single library. At present we have 3 DBMS's: Sqlite, Oracle, and PostgreSQL. For example, suppose you had just the Oracle DBMS client libraries installed, and you write a program which only uses the Oracle modules from Takusen. When you link, the gnu ld program attempts to resolve the symbols in only the modules that you've used. You don't need to have PostgreSQL or Sqlite installed, and the linker ignores these modules from the package archive. This is quite nice, because we can distribute the entire library as a single package, and it will work even if the user does not have all of the DBMS client libraries installed. In contrast, when ghci (or runhaskell) attempts to link it tries to resolve all of the symbols in the PostgreSQL and Sqlite modules, and fails because you don't have them installed. The result is that a user of Takusen can't easily use the library with ghci/runhaskell "out of the box", unless they have the full set of DBMS client libraries installed. There are a couple of workarounds, but they're both a bit fiddly, so it'd be nicer (from my POV) if the ghci linker behaved like gnu ld. Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. *****************************************************************

From: Bayley, Alistair
The result is that a user of Takusen can't easily use the library with ghci/runhaskell "out of the box", unless they have the full set of DBMS client libraries installed.
I forgot to mention that there's another difference between ghci and gnu ld: if the external library is called libxx.dll, rather than xx.dll (which is the convention on Windows, it seems), then gnu ld is still able to locate & link to it when you say -lxx, but ghci fails to find it. You have to say -llibxx to ghci for it to work. This also makes distributing the Takusen library as a single package awkward, because 1. the cabal installation detects the presence of the library and configures the package with the -lxx option 2. ghc --make passes -lxx to gnu ld, which is nice... 3. ... but ghci tries to use -lxx also, and fails. So PostgreSQL users can't use ghci with the installed package unless they're willing to re-configure/build/install and change the -l option to from -lpq to -llibpq, which breaks normal compilation with ghc, because gnu ld can't find the library when you say -llibpq. (This affects the PostgreSQL client library on Windows, which is called libpq.dll.) Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. *****************************************************************
participants (2)
-
Bayley, Alistair
-
Simon Marlow