RE: [Template-haskell] Templates + FFI + shared libs = segfault?
Robert You seem to have stumbled on a bug somewhere involved in dynamic linking. I rather doubt it has anything to do with TH. Step 1 is to separate out Template Haskell. Does this happen with ghci? ghci -lsmokeqt then do some ghci stuff. It'd help if you could crash it that way. Next, we'll need to be able to reproduce it here. Can you boil out the smallest thing that demonstrates the problem and send it, with instructions? We'll need to get smokeqt, I suppose. It probably won't be identical to yours, because our Linux will be slightly different. I hope that doesn't hide the problem. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Robert Dockins | Sent: 30 April 2004 00:51 | To: template-haskell@haskell.org | Subject: [Template-haskell] Templates + FFI + shared libs = segfault? | | Greetings, | | I'm new to Template Haskell and I'm working on a project to get my feet | wet. I'm working on bindings for Qt using the smoke library. (Some | info about smoke here:http://developer.kde.org/language-bindings/smoke/ | ). Smoke is essentially a language independant binding library with | some introspection built in. | | So, I'm trying to use the introspection features of smoke + template | haskell to generate type, class and instance declarations to model the | Qt class structure. | | The problem occurs when I try to link to the smoke shared libray at | splice time. When I do, ghc segfaults: | | ghc -c -fffi -fth smokeglue.o -lsmokeqt testtemp.hs | Loading package base ... linking ... done. | Loading object (static) smokeglue.o ... done | Loading object (dynamic) smokeqt ... done | Segmentation fault | | | Now this next one is really weird. The code in the next listing doesn't | have any symbols to resolve; it doesn't even use FFI, but it still | segfaults when I link to the library (although apparently in a different | place?) : | | $ ghc --make -fth main.hs | Chasing modules from: main.hs | Skipping Template ( ./Template.hs, ./Template.o ) | Compiling Main ( main.hs, main.o ) | Loading package base ... linking ... done. | Loading package haskell98 ... linking ... done. | Loading package template-haskell ... linking ... done. | Linking ... | | $ touch *.hs | | $ ghc --make -fth -lsmokeqt main.hs | Chasing modules from: main.hs | Compiling Template ( ./Template.hs, ./Template.o ) | Compiling Main ( main.hs, main.o ) | Loading package base ... linking ... done. | Loading object (dynamic) smokeqt ... done | final link ... done | Loading package haskell98 ... linking ... done. | Loading package template-haskell ... linking ... done. | Segmentation fault | | | Other shared libs work though: | | $ ghc --make -fth -lxine main.hs | Chasing modules from: main.hs | Skipping Template ( ./Template.hs, ./Template.o ) | Compiling Main ( main.hs, main.o ) | Loading package base ... linking ... done. | Loading object (dynamic) xine ... done | final link ... done | Loading package haskell98 ... linking ... done. | Loading package template-haskell ... linking ... done. | Linking ... | | I haven't been able to find any other libs that cause ghc to segfault | like this; it appears just to not like this one. Also, if I link | against the lib normally (ie, not during a splice) it works, and the | resulting executable works as well. | | My guess is that something isn't quite right with the code that links | shared libraries at splice time, but... its just a guess. | | Any ideas? | | Thanks, | Robert Dockins
Simon,
You seem to have stumbled on a bug somewhere involved in dynamic linking. I rather doubt it has anything to do with TH.
That appears to be the case. ghci crashes just loading the .so (listings below). After playing around, the problem seems to be with loading the dependancies. If I load -lqt also (very carefully), then ghci doesn't crash, and, in fact, the origninal TH module also loads and works with the correct command line. In short here is the scoop: ghci -lsmokeqt segfault ghci -lqt -lsmokeqt can't find .so ghci -L/usr/qt/3/lib -lqt -lsmokeqt works! ghci -L/usr/qt/3/lib -lsmokeqt -lqt segfaults ghci -lqt can't find .so ghci -L/usr/qt/3/lib -lqt works So, it appears that libqt.so (or libqt-mt.so also works) must be loaded before libsmokeqt.so. The same thing occurs when I insert the above options into the command line to compile my TH module. I am attaching output from LD_DEBUG=files listings from three different situations 1) ldrun.txt output from a simple program which uses smoke 2) ghcismokeqt.txt output from ghci -lsmokeqt 3) ghciqtsmokeqt.txt output from ghci -L/usr/qt/3/lib -lqt-mt -lsmokeqt 2) is the interesting one. It cuts off after calling init on libsmokeqt.so. It also contains an error while binding the symbol 'pthread_key_create' in the libGL module, which looks very odd. I can only assume this is related somehow. The error in question looks like: 12500: /usr/X11R6/lib/libGL.so.1: error: relocation error: undefined symbol: pthread_key_create (fatal) This error does not occur in 1) nor in 3).
Next, we'll need to be able to reproduce it here. Can you boil out the smallest thing that demonstrates the problem and send it, with instructions? We'll need to get smokeqt, I suppose. It probably won't be identical to yours, because our Linux will be slightly different. I hope that doesn't hide the problem.
The simplist thing that does it here is ghci -lsmokeqt The easiest way to get smoke is to grab the kdebindings package (http://kde.gnusoft.net/stable/3.2.1/src/kdebindings-3.2.1.tar.bz2) and ./configure cd smoke/qt make I am using CVS code, but I had the same behavior with 3.2.1 stable code. Please, let me know if I can help further. Finally, the crash listings: --------------------------------------------------------- $ghci -lsmokeqt ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.3.20040426, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. Loading object (dynamic) smokeqt ... done final link ... done Segmentation fault $ ghci -lqt -lsmokeqt ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.3.20040426, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. Loading object (dynamic) qt ... failed. Dynamic linker error message was: libqt.so: cannot open shared object file: No such file or directory Whilst trying to load: (dynamic) qt Directories to search are: ghc-6.3.20040426: user specified .o/.so/.DLL could not be loaded. $ ghci -L/usr/qt/3/lib -lqt -lsmokeqt ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.3.20040426, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. Loading object (dynamic) qt ... done Loading object (dynamic) smokeqt ... done final link ... done Prelude> :q Leaving GHCi. $ ghci -L/usr/qt/3/lib -lsmokeqt -lqt ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.3.20040426, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. Loading object (dynamic) smokeqt ... done Loading object (dynamic) qt ... Segmentation fault Robert Dockins
participants (2)
-
Robert Dockins -
Simon Peyton-Jones