[ ghc-Bugs-419930 ] FFI stubs cpd w/out -DSTOLEN-X86-REGS=?
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 30 Apr 2001 05:13:02 -0700
Bugs item #419930, was updated on 2001-04-29 02:59
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=419930&group_id=8032
Category: Driver
Group: 5.00
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Simon Marlow (simonmar)
Summary: FFI stubs cpd w/out -DSTOLEN-X86-REGS=?
Initial Comment:
Symptom:
Callbacks with more than one parameter exported using
"foreign export dynamic" cause a segmentation fault.
This fault was first detected when using the OpenGL
binding in hslibs with the supplied redbook examples.
Version Information:
OS: Linux, RedHat 7.0
GCC: 2.96 (rpm gcc-2.96-69)
CLIB: glibc 2.2 (rpm glibc-2.2-12)
GHC: 5.00 (from rpm ghc-5.00-2)
Example: (compiled / linked using flags "-fglasgow-exts
-package lang")
--- Main.hsc (preprocessed to Main.hs using hsc2hs) ---
#include <test.h>
module Main where
import Int
import Addr
import Foreign
main :: IO ()
main = do
testPrintAddr <- mkTestPrint testPrint
test testPrintAddr
freeHaskellFunctionPtr testPrintAddr
foreign import ccall "test_main" test :: Addr -> IO ()
type CBType = #{type int} -> #{type int} -> IO ()
testPrint :: CBType
testPrint i j = putStrLn ("Hello number " ++ (show i)
++ " and " ++ (show j))
foreign export dynamic mkTestPrint :: CBType -> IO Addr
--- test.c ---
#include <stdio.h>
void test_main(void *testPrint(int,int))
{
testPrint(1,2);
}
--- test.h ---
void test_main(void *testPrint(int,int));
--- Cut here ---
Fix: It appears that the new ghc driver does not pass
the flag -DSTOLEN_X86_REGS=num to gcc when compiling
FFI stubs. In the case above, adding the flag
"-optc-DSTOLEN_X86_REGS=4" when compiling Main.hs
causes Main_stub.c to be compiled correctly and fixes
the segmentation fault.
Regards
Dominic Verity
P.S. It would also be nice if the stub generator were
to add newlines at the end of stubs and their headers,
to avoid unsightly "warning: no newline at end of file"
massages from gcc.
----------------------------------------------------------------------
Comment By: Dominic Verity (dominicv)
Date: 2001-04-30 05:13
Message:
Logged In: YES
user_id=125019
Yup, -DIN_STG_CODE=0 also does the trick.
I've also had problems reproducing this wrinkle on other
platforms -
both of my i686 machines running RedHat 7.0 suffer, but it
seems to be fine on my NT box.
I'm also having problems with foreign imports, which again
show up in the OpenGL binding. Specifically, I can now get
all but one of the supplied examples to run OK. However, in
the AAPoly.hs example when it calls out to the 4 parameter
GL function "drawElements " it appears to be passing
corrupted parameters. As far as I can tell everything is
being
marshalled into C side stuff OK, its just the foreign call
that is
sick.
Again this is specific to my Linux boxes not NT - could the
problems be related?
Regards, Dominic
----------------------------------------------------------------------
Comment By: Simon Marlow (simonmar)
Date: 2001-04-30 02:28
Message:
Logged In: YES
user_id=48280
I can't repro this one, but I think I know what's causing
it.
Could you verify that compiling the stub with -
DIN_STG_CODE=0 also makes the example work?
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=419930&group_id=8032