[Template-haskell] Templates + FFI + shared libs = segfault?

Simon Peyton-Jones simonpj at microsoft.com
Thu May 6 11:41:06 EDT 2004


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 at haskell.org
[mailto:template-haskell-bounces at haskell.org] On
| Behalf Of Robert Dockins
| Sent: 30 April 2004 00:51
| To: template-haskell at 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



More information about the template-haskell mailing list