Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Causes for segfaults
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-11-15 (19:00)
From: Anil Madhavapeddy <anil@r...>
Subject: Re: [Caml-list] Causes for segfaults
On 15 Nov 2010, at 18:50, Daniel de Rauglaudre wrote:

> On Mon, Nov 15, 2010 at 07:38:25PM +0100, Jamie Brandon wrote:
>> jamie@jamie-aspire:~$ cat >
>> let rec ints n = n :: ints (n+1)
>> let _ = ints 0
>> jamie@jamie-aspire:~$ ocamlopt
>> jamie@jamie-aspire:~$ ./a.out
>> Segmentation fault
> Stack overflow in native code triggers a segmentation fault, indeed.
> I think in C, it is the same thing. Not tested in the OCaml runtime
> for efficiency purposes, I think.

The runtime can detect native stack overflow if the OS supports it. See the HAS_STACK_OVERFLOW_DETECTION define in the configure script :

case "$arch,$system" in
    echo "System stack overflow can be detected."
    echo "#define HAS_STACK_OVERFLOW_DETECTION" >> s.h;;
    echo "Cannot detect system stack overflow.";;

This works great for me on both MacOS X 10.6 and x86_64 Linux.

avsm@brolga-0:~$ uname -a
Linux brolga-0 #3 SMP Thu Dec 24 23:39:24 GMT 2009 x86_64 GNU/Linux
avsm@click$ uname -a
Darwin click.local 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov  5 23:19:13 PDT 2010; root:xnu-1504.9.17~1/RELEASE_X86_64 x86_64

avsm@brolga-0:~$ cat >
let rec ints n = n :: ints (n+1)
let _ = ints 0
avsm@brolga-0:~$ ocamlopt 
avsm@brolga-0:~$ ./a.out 
Fatal error: exception Stack_overflow

Take a look at your configure script output to see if it isn't being detected I guess. There may also be some interaction with your shell ulimit that forces a SIGSEGV, perhaps.