Illegal instruction in GHC 6.5 generated code.

(If this is the wrong list for this, please tell me. I tried Glasgow-Haskell-Bugs, but message got hold in moderation) Hello, Using GHC 6.5 from darcs repo ("pulled" in 19/Jun), the following snippet of code seems to cause illegal instruction error on the generated code. The error disappears if I use the Dummy instance on top of Refeable. The code is from my bindings to Judy library, revision 10752 in subversion. http://svn.openfoundry.org/pugs/third-party/HsJudy/ http://svn.openfoundry.org/pugs/third-party/judy/ # original C lib code To test it you'll need to compile (./configure; make # but not necessarily install) the original library in third-party/judy/Judy-1.0.3. Back in HsJudy, change the Makefile to static link option. HsJudy$ make testmap HsJudy$ ./testmap Sorry, I tried to come up with an simpler instance of the problem but didn't found one. The program depend on WordPtr which isn't available in GHC 6.4.2, so I couldn't test it in stable version. It was tested on my amd64, linux 2.6.16 and in audreyt's machine (OSX I think). ---------8<------------ --class Dummy a --instance Dummy a --instance Dummy a => Refeable a where instance Refeable a where toRef a = do a' <- newStablePtr a return (ptrToWordPtr (castStablePtrToPtr a')) fromRef v = do a <- deRefStablePtr (castPtrToStablePtr (wordPtrToPtr v)) return a -- Don't need to StablePtr "simple" things like Int instance Refeable Int where toRef i = return $ toEnum i fromRef v = return $ fromEnum v ---------->8------------- Thanks in advance, -- Caio Marcelo

Caio Marcelo wrote:
(If this is the wrong list for this, please tell me. I tried Glasgow-Haskell-Bugs, but message got hold in moderation)
Hello,
Using GHC 6.5 from darcs repo ("pulled" in 19/Jun), the following snippet of code seems to cause illegal instruction error on the generated code. The error disappears if I use the Dummy instance on top of Refeable. The code is from my bindings to Judy library, revision 10752 in subversion. http://svn.openfoundry.org/pugs/third-party/HsJudy/ http://svn.openfoundry.org/pugs/third-party/judy/ # original C lib code
To test it you'll need to compile (./configure; make # but not necessarily install) the original library in third-party/judy/Judy-1.0.3. Back in HsJudy, change the Makefile to static link option.
HsJudy$ make testmap HsJudy$ ./testmap
Sorry, I tried to come up with an simpler instance of the problem but didn't found one. The program depend on WordPtr which isn't available in GHC 6.4.2, so I couldn't test it in stable version. It was tested on my amd64, linux 2.6.16 and in audreyt's machine (OSX I think).
I tried to reproduce this without success. I grabbed judy and HsJudy as above using SVN, with -r 10752. Running testmap on x86_64 using last night's GHC build gives me: ~/scratch/HsJudy > ./testmap # Map tests: elems: (NEW on 0x00002ae76b178010) ok simple: (NEW on 0x00002ae76b178100) ok delete: (NEW on 0x00002ae76b178160) ok overwrite: (NEW on 0x00002ae76b178220) ok member: (NEW on 0x00002ae76b1782b0) ok elems: (NEW on 0x00002ae76b178358) ok keys: (NEW on 0x00002ae76b178448) ok int-key map: (NEW on 0x00002ae76b1785b0) ok What did I do wrong? I did have to modify the Makefile a bit to tell it where to find Judy.h, since I don't have Judy installed here. Cheers, Simon

On 6/23/06, Simon Marlow
What did I do wrong?
Did you changed the Judy/Map.hs code to not use Dummy (see below)? The code I commited is the version with the workaround. Anyway, I'm going to darcs pull and recompile GHC to check if the behaviour changes. -----------8<------------ Index: Judy/Map.hs =================================================================== --- Judy/Map.hs (revisão 10752) +++ Judy/Map.hs (cópia de trabalho) @@ -56,7 +56,8 @@ class Dummy a instance Dummy a -instance Dummy a => Refeable a where +--instance Dummy a => Refeable a where +instance Refeable a where toRef a = do a' <- newStablePtr a return (ptrToWordPtr (castStablePtrToPtr a')) ---------->8------------- -- Caio Marcelo

On 6/23/06, Caio Marcelo
Anyway, I'm going to darcs pull and recompile GHC to check if the behaviour changes.
Just updating information: the problem still happening with latest (actually 24/Jun) GHC. In the latest Judy repo, Dummy and Refeable classes are now in Judy/Refeable.hs. -- Caio Marcelo

On 23 June 2006 17:43, Caio Marcelo wrote:
On 6/23/06, Simon Marlow
wrote: What did I do wrong?
Did you changed the Judy/Map.hs code to not use Dummy (see below)? The code I commited is the version with the workaround.
Anyway, I'm going to darcs pull and recompile GHC to check if the behaviour changes.
-----------8<------------ Index: Judy/Map.hs =================================================================== --- Judy/Map.hs (revisão 10752) +++ Judy/Map.hs (cópia de trabalho) @@ -56,7 +56,8 @@ class Dummy a instance Dummy a
-instance Dummy a => Refeable a where +--instance Dummy a => Refeable a where +instance Refeable a where toRef a = do a' <- newStablePtr a return (ptrToWordPtr (castStablePtrToPtr a')) ---------->8-------------
Ok, I reproduced it. I think this may be a bug in your code, but I'm not completely sure. Compiling the program with -debug turns the crash into an assertion failure. Furthermore, running the program with +RTS -DS, which causes all free memory to be filled with 0xaaaaaaaa, turns the crash into this: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 47963533074768 (LWP 15726)] 0x0000003fa1e75b30 in memcpy () from /lib64/libc.so.6 (gdb) where #0 0x0000003fa1e75b30 in memcpy () from /lib64/libc.so.6 #1 0x000000000045329e in JudyHSIterFirst (PArray=0x0, PPIter=Variable "PPIter" is not available. ) at JudyHS.c:983 #2 0x000000000040e2b1 in s2KX_info () #3 0x000000000066fb90 in ?? () #4 0x00002b9f616828d0 in ?? () #5 0x0000000000000000 in ?? () which looks suspicious. Delving a little further: (gdb) up #1 0x000000000045329e in JudyHSIterFirst (PArray=0x0, PPIter=Variable "PPIter" is not available. ) at JudyHS.c:983 983 memcpy(PIter->hsi_String, String, Length); (gdb) p *PIter $1 = {hsi_Alloc = 32, hsi_MaxLength = 0, hsi_Length = 12297829382473034410, hsi_Hash = 0, hsi_String = "\000\000\000\000\000\000\000"} (gdb) p String $2 = (uint8_t *) 0xaaaaaaaaaaaaaaaa
(gdb) p Length $3 = 12297829382473034410 So it looks like you're passing some free memory to a foreign function, perhaps. Is this any help? Cheers, Simon
participants (3)
-
Caio Marcelo
-
Simon Marlow
-
Simon Marlow