[GHC] #7097: linker fails to load package with binding to foreign library

GHC cvs-ghc at haskell.org
Tue Aug 7 14:44:29 CEST 2012


#7097: linker fails to load package with binding to foreign library
----------------------------------+-----------------------------------------
    Reporter:  nus                |       Owner:              
        Type:  bug                |      Status:  new         
    Priority:  normal             |   Milestone:              
   Component:  Runtime System     |     Version:  7.4.2       
    Keywords:                     |          Os:  Windows     
Architecture:  x86                |     Failure:  None/Unknown
  Difficulty:  Unknown            |    Testcase:              
   Blockedby:                     |    Blocking:              
     Related:  #2283 #3242 #1883  |  
----------------------------------+-----------------------------------------

Comment(by nus):

 Replying to [comment:10 simonmar]:
 > Could you explain what is special about the `WSACleanup` symbol here?
 Why is it different from any other symbol that we import from a DLL?
 After all, we call a lot of functions that live in DLLs.
 Rephrasing that made the issue become more apparent, thanks. Why is it
 that only some packages that import from foreign libraries get references
 to the `__imp_` prefixed symbols and most others don't? Most foreign
 functionality gets explictly declared and refered to using the Haskell FFI
 `foreign import` declarations. Some functionality, though, gets declared
 and refered to implicitly, via C headers, as in the case with the
 `network` package:
  network-2.3.0.14/Network/Socket/Internal.hsc:
 {{{
 [...snip...]
 withSocketsDo :: IO a -> IO a
 #if !defined(WITH_WINSOCK)
 withSocketsDo x = x
 #else
 withSocketsDo act = do
     x <- initWinSock
 [...snip...]
 foreign import ccall unsafe "initWinSock" initWinSock :: IO Int
 foreign import ccall unsafe "shutdownWinSock" shutdownWinSock :: IO ()

 #endif
 [...snip...]
 }}}
  network-2.3.0.14/cbits/initWinSock.c:
 {{{
 #include "HsNet.h"
 #include "HsFFI.h"

 #if defined(HAVE_WINSOCK2_H) && !defined(__CYGWIN__)
 [...snip...]
 int
 initWinSock ()
 {
 [...snip...]
     err = WSAStartup ( wVersionRequested, &wsaData );
 [...snip...]
       WSACleanup();
 [...snip...]
 }}}
  network-2.3.0.14/include/HsNet.h:
 {{{
 [...snip...]
 #if defined(HAVE_WINSOCK2_H) && !defined(__CYGWIN__)
 #include <winsock2.h>
 [...snip...]
 }}}
  i686-w64-mingw32/include/winsock2.h:
 {{{
 [...snip...]
 #define WINSOCK_API_LINKAGE     DECLSPEC_IMPORT
 [...snip...]
   WINSOCK_API_LINKAGE int WSAAPI WSAStartup(WORD
 wVersionRequested,LPWSADATA lpWSAData);
   WINSOCK_API_LINKAGE int WSAAPI WSACleanup(void);
 [...snip...]
 }}}
  i686-w64-mingw32/include/winnt.h:
 {{{
 [...snip...]
 #if defined(_X86_) || defined(__ia64__) || defined(__x86_64)
 #define DECLSPEC_IMPORT __declspec(dllimport)
 #else
 #define DECLSPEC_IMPORT
 #endif
 [...snip...]
 }}}
  [http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html GCC:
 Declaring Attributes of Functions]:
 {{{
   On Microsoft Windows and Symbian OS targets, the dllimport attribute
 causes the compiler to reference a function or variable via a global
 pointer to a pointer that is set up by the DLL exporting the symbol. The
 attribute implies extern. On Microsoft Windows targets, the pointer name
 is formed by combining _imp__ and the function or variable name.
 }}}
 The codegen has no control over the symbol name emitted, unlike the
 explicitly declared imports cases:
 {{{
 $ cabal build network
 Building network-2.3.0.14...
 [...snip...]
 Building C Sources...
 creating dist\build
 ("c:\\mnt\\data1\\ghc32b\\bin\\ghc.exe",["-Idist\\build","-Iinclude","-no-
 user-package-conf","-package-
 id","base-4.5.1.0-724fe8b5495aa663f22c79d0a09b2abb","-package-
 id","bytestring-0.9.2.1-0c74e8abeebb3c3d794fd93f5313ffd8","-package-
 id","parsec-3.1.3-2f82092583ddf7939f1cf390c7cadc1c","-optc-
 DCALLCONV=stdcall","-optc-O2","-odir","dist\\build","-v","-c","cbits/initWinSock.c"])
 [...snip...]
 Linking...
 ("c:\\mnt\\data1\\ghc32b\\mingw\\bin\\ar.exe",["-r","-v","dist\\build\\libHSnetwork-2.3.0.14.a","dist\\build\\Network.o","dist\\build\\Network\\BSD.o","dist\\build\\Network\\Socket.o","dist\\build\\Network\\Socket\\ByteString.o","dist\\build\\Network\\Socket\\ByteString\\Lazy.o","dist\\build\\Network\\Socket\\Internal.o","dist\\build\\Network\\URI.o","dist\\build\\Network\\Socket\\ByteString\\Internal.o","dist\\build\\cbits/initWinSock.o","dist\\build\\cbits/winSockErr.o","dist\\build\\cbits/asyncAccept.o","dist\\build\\cbits/HsNet.o"])
 a - dist\build\Network.o
 a - dist\build\Network\BSD.o
 a - dist\build\Network\Socket.o
 a - dist\build\Network\Socket\ByteString.o
 a - dist\build\Network\Socket\ByteString\Lazy.o
 a - dist\build\Network\Socket\Internal.o
 a - dist\build\Network\URI.o
 a - dist\build\Network\Socket\ByteString\Internal.o
 a - dist\build\cbits/initWinSock.o
 a - dist\build\cbits/winSockErr.o
 a - dist\build\cbits/asyncAccept.o
 a - dist\build\cbits/HsNet.o
 ("c:\\mnt\\data1\\ghc32b\\mingw\\bin\\ld.exe",["-x","--hash-size=31
 ","--reduce-memory-
 overheads","-r","-o","dist\\build\\HSnetwork-2.3.0.14.o","dist\\build\\Network.o","dist\\build\\Network\\BSD.o","dist\\build\\Network\\Socket.o","dist\\build\\Network\\Socket\\ByteString.o","dist\\build\\Network\\Socket\\ByteString\\Lazy.o","dist\\build\\Network\\Socket\\Internal.o","dist\\build\\Network\\URI.o","dist\\build\\Network\\Socket\\ByteString\\Internal.o","dist\\build\\cbits/initWinSock.o","dist\\build\\cbits/winSockErr.o","dist\\build\\cbits/asyncAccept.o","dist\\build\\cbits/HsNet.o"])
 [...snip...]
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7097#comment:14>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list