Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1018 closed bug (fixed)

ghci dynamic loading of X11 - unknown symbol `_printf$LDBLStub'

Reported by: ykardia Owned by:
Priority: normal Milestone: 6.6.1
Component: GHCi Version: 6.6
Keywords: X11, dynamic loading Cc: wolfgang.thaller@…, gwright@…
Operating System: MacOS X Architecture: powerpc
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Hello.

I have a problem with using ghci to dynamically load the X11 library on Mac OS X.

I create the following file: -- test.hs -- module Main where import Graphics.X11.Xlib main = do print "Hello, world!"


When I compile this with ghc --make test.hs, I get an executable that is properly linked and works.

With dynamic loading, there are two issues:

1) A minor issue (easy workaround): When I try to load this with ghci, i.e.


$ ghci test.hs [... ascii graphics ...] Loading package base ... linking ... done. Ok, modules loaded: Main. Prelude Main> main Loading package X11-1.1 ... can't load .so/.DLL for: X11 (dlopen(libX11.dylib, 10): image not found)


I can fix this by running ghci setting DYLD_LIBRARY_PATH=/usr/X11R6/lib, which is where the Apple X11 lives.

2) Maybe a more serious issue?


$ DYLD_LIBRARY_PATH=/usr/X11R6/lib ghci test.hs [... ascii graphics ...] Loading package base ... linking ... done. Ok, modules loaded: Main. Prelude Main> main Loading package X11-1.1 ... linking ... <interactive>: /opt/local/lib/ghc-6.6/HSX11_cbits.o: unknown symbol `_printf$LDBLStub' ghc-6.6: unable to load package `X11-1.1'


Issue (1) is probably trivial, I am only pointing it out in case it is related to issue (2).

When I pointed this out on darcs-users, there were some suggestion that this might be due to SystemStubs not being linked in, or some problem with the compiler - apparently X11 is meant to be compiled with gcc 3.3, and it should work if compiled with gcc 4 as long as SystemStubs is linked in (?).

I have replicated this with the following combinations of software and hardware: Mac OS X 10.4.8, dual G5, Xcode 2.4.1 (gcc 4.0.1), Apple X11 1.1.3, macports ghc 6.6_1

Mac OS X 10.4.8, dual G5, Xcode 2.3 (gcc 4.0.1), Apple X11 1.1.2, macports ghc 6.6_1

Mac OS X 10.4.8, dual G5, Xcode 2.3 (gcc 4.0.1), Apple X11 1.1.2, binary distribution of ghc 6.6 for Mac OS X.

Mac OS X 10.4.8, G4 (Powerbook), Xcode 2.3 (gcc 4.0.1), Apple X11 1.1.2, macports ghc 6.6_1

What's wrong?

Change History (5)

comment:1 Changed 12 years ago by ykardia

I need to learn to use WikiFormatting and the Preview button...

The file:

-- test.hs --
module Main where
import Graphics.X11.Xlib
main = do print "Hello, world!"
-------------

Output from issue number 1:

----------------
$ ghci test.hs
[... ascii graphics ...]
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> main
Loading package X11-1.1 ... can't load .so/.DLL for: X11 (dlopen(libX11.dylib, 10): image not found)
----------------

Output from issue number 2:

----------------
$ DYLD_LIBRARY_PATH=/usr/X11R6/lib ghci test.hs
[... ascii graphics ...]
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> main
Loading package X11-1.1 ... linking ... <interactive>:
/opt/local/lib/ghc-6.6/HSX11_cbits.o: unknown symbol `_printf$LDBLStub'
ghc-6.6: unable to load package `X11-1.1'
----------------

comment:2 Changed 12 years ago by wolfgang

Architecture: Unknownpowerpc
Milestone: 6.6.1
Resolution: fixed
Status: newclosed
  • Issue 1: This is a problem with the configure script for the X11 package. I've created a separate ticket (#1019) for it.
  • Issue 2: the main issue: I had fixed this problem a *long* time ago, and then I forgot one crucial line of code. The real fix (I hope) will be in GHC 6.6.1.

comment:3 Changed 12 years ago by gwright@…

Cc: wolfgang.thaller@… added

Wolfgang,

Can you post a patch (or just tell me which file has the crucial line of code)? I would like to fix this for 6.6 in MacPorts.

The library issue (now ticket #1019) I can fix by editing the package.conf file before it is copied to the final installation directory.

-Greg

comment:4 Changed 12 years ago by wolfgang

Cc: gwright@… added

The patch modifies Linker.c, where the LDBLStub symbols where declared but not included in the symbol list, and configure.ac, where incorrect escaping would lead configure.ac to check for printf instead of printf$LDBLStub, leading to false positives.

Tue Nov 21 01:49:53 CET 2006  wolfgang.thaller@gmx.net
  * Fix printf$LDBLStub workaround for Darwin
  
  Apparently, the original fix never really worked due to typos and oversights.
diff -rN -u old-stable-ghc/configure.ac new-stable-ghc/configure.ac
--- old-stable-ghc/configure.ac 2006-11-21 15:08:22.000000000 +0100
+++ new-stable-ghc/configure.ac 2006-11-21 15:08:23.000000000 +0100
@@ -1169,8 +1169,8 @@
 AC_CHECK_FUNCS(clock_gettime)
 
 dnl ** check for Apple's "interesting" long double compatibility scheme
-AC_MSG_CHECKING(for printf$LDBLStub)
-AC_TRY_LINK_FUNC(printf$LSBLStub,
+AC_MSG_CHECKING(for printf\$LDBLStub)
+AC_TRY_LINK_FUNC(printf\$LDBLStub,
     [
         AC_MSG_RESULT(yes)
         AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
diff -rN -u old-stable-ghc/rts/Linker.c new-stable-ghc/rts/Linker.c
--- old-stable-ghc/rts/Linker.c 2006-11-21 15:08:22.000000000 +0100
+++ new-stable-ghc/rts/Linker.c 2006-11-21 15:08:23.000000000 +0100
@@ -797,6 +797,7 @@
       RTS_POSIX_ONLY_SYMBOLS
       RTS_MINGW_ONLY_SYMBOLS
       RTS_CYGWIN_ONLY_SYMBOLS
+      RTS_DARWIN_ONLY_SYMBOLS
       RTS_LIBGCC_SYMBOLS
 #if defined(darwin_HOST_OS) && defined(i386_HOST_ARCH)
       // dyld stub code contains references to this,

comment:5 Changed 12 years ago by gwright@…

For ghc-6.6 built using MacPorts, I have applied Wolfgang's patch and also patched libraries/X11/package.conf.in to include /usr/X11R6/lib in the search path. It seems to work properly:

crossroads-able> ghci -package X11
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package X11-1.1 ... linking ... done.
Prelude> 

To get the patched ghc, make sure you are building revision 2 of the ghc-6.6 port. (As always, "port info ghc" is your friend.)

Note: See TracTickets for help on using tickets.