Re: [Newbie]Unexpected signal from FFI on Solaris 8
[redirected to hugs-bugs]
Marco Vezzoli
Hi, I'm learning how to use ffi with hugs (latest version, on Solaris 8). I can compile this simple example without errors [...] Hugs loads correctly the module but fails one of the tests: [...]
Thanks for an excellent bug report. I was easily able to repeat what you did! On my machine (Linux/x86 running the CVS copy of Hugs), things worked fine and I got this output: Test> testIncr 2 Test> testTimes times running 3 aaa Test> [Leaving Hugs] Looks like a bug. The major possibilities are: 1) The problem is a Solaris specific bug in Hugs. This is highly likely since Sparcs have some peculiar calling conventions and, more importantly, most testing has been on my Linux/x86 and Windows/x86 machines. 2) The problem is a C compiler specific bug in Hugs. Solaris boxes usually have a Sun compiler and it's often true that gcc isn't installed, properly maintained or the default compiler. Again, most testing has been with gcc. 3) The problem was present in the official release but has been fixed in the CVS repository. I don't recall any fixes - but it's been a busy 6 months for me since the release. 4) The problem is in your code. I don't see an obvious problem. Can someone who uses the standard release check whether the bug shows up on solaris and/or non-solaris machines? Can you (Marco) rerun ffihugs with the additional flag '+L"-v"' to find out which compiler you're using: ffihugs -P{Hugs}/libraries/:{Hugs}/oldlib +G +L"test.c" Test.hs +L"-v" If you're using gcc, this will produce about 50 lines of output which will start with something like: Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs which says that I use gcc 3.2.3. If you're using another compiler, the flag may be --version or -h or whatever. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/
Thank you for your answer. alastair@reid-consulting-uk.ltd.uk wrote:
Looks like a bug. The major possibilities are:
1) The problem is a Solaris specific bug in Hugs.
2) The problem is a C compiler specific bug in Hugs.
Solaris boxes usually have a Sun compiler and it's often true that gcc isn't installed, properly maintained or the default compiler. Again, most testing has been with gcc.
I used gcc 3.0.2 building hugs. Sadly upgrading to a newer version can probably break some of the tools we compiled.
3) The problem was present in the official release but has been fixed in the CVS repository.
Due to my employer's strict internet access policy, I cannot use the cvs command; there is another way to get the latest source?
4) The problem is in your code.
I don't see an obvious problem.
Me too.
Can you (Marco) rerun ffihugs with the additional flag '+L"-v"' to find out which compiler you're using:
ffihugs -P{Hugs}/libraries/:{Hugs}/oldlib +G +L"test.c" Test.hs +L"-v"
[vezzoli@web:885] ffi ->ffihugs -P{Hugs}/libraries/:{Hugs}/oldlib +G +L"test.c" +L"-v" Test.hs Reading specs from /usr/local/extra/gcc-3.0.2_sol8/lib/gcc-lib/sparc-sun-solaris2.8/3.0.2/specs [many lines follows] It seems that ffihugs uses the same compiler I used to build hugs (gcc 3.0.2). -- Marco Vezzoli tel. +39 039 603 6852 STMicroelectronics fax. +39 039 603 5055
I found myself a solaris box and was able to reproduce your bug. To try to track down what was happening, I modified the code generated by ffihugs and modified your test.c and Test.hs to check that the function 'times' gave the same result. Test.c and Test.hs both saw a return value of -1 (hence the segfault) but the modified version of test.c didn't print anything. Hypothesis: there is a standard library function on solaris called 'times' which is shadowing your definition of times. To test this hypothesis, I renamed the C function being called to 'times_adr', recompiled, reloaded and... it worked just fine. Does anyone know of a flag you can pass to a linker to make it report an error instead of silently doing the wrong thing? -- Alastair Reid
alastair@reid-consulting-uk.ltd.uk wrote:
I found myself a solaris box and was able to reproduce your bug.
To try to track down what was happening, I modified the code generated by ffihugs and modified your test.c and Test.hs to check that the function 'times' gave the same result. Test.c and Test.hs both saw a return value of -1 (hence the segfault) but the modified version of test.c didn't print anything.
Hypothesis: there is a standard library function on solaris called 'times' which is shadowing your definition of times.
To test this hypothesis, I renamed the C function being called to 'times_adr', recompiled, reloaded and... it worked just fine.
Thank you very much! This is enough for me to continue my learning.
Does anyone know of a flag you can pass to a linker to make it report an error instead of silently doing the wrong thing?
I tried with '--warn-common' but without success. Then I tried to repeat the error with C only: -I compiled a shared lib with gcc -c test.c ld -o libtest.so -shared test.o -then I linked a simple test --------main.c------------- #include "test.h" int main(int argc,char** argv){ printf("%s",times('a',2)); } --------main.c------------- with the command gcc -ltest -L. main.c but the program worked correctly. Maybe the 'times' symbol is defined in some other library that ffihugs uses by default. -- Marco Vezzoli tel. +39 039 603 6852 STMicroelectronics fax. +39 039 603 5055
participants (2)
-
Alastair Reid -
Marco Vezzoli