New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation error on a simple program #4843
Comments
Comment author: @mshinwell This looks like a problem with the heuristic that determines whether a faulting address is in the stack. It may be related to issue 4746. I suggest doing the following, which should collect the necessary information to determine what is wrong. (In case anyone is wondering, I think this will indeed give the stack pointer before it is switched to the alternate signal stack.) $ ulimit -s Then before exiting the debugger, in another terminal, use vmmap (I think that's the right program on Mac OS X; it's called pmap on Linux) specifying the process ID of the Caml program -- not the debugger -- and note what it reports as the stack size. |
Comment author: kwakita Shinwell, thank you for your suggestion. I followed your instruction and get the following outputs. I hope they are helpful. dasher:bug$ ulimit -s dasher:bug$ gdb ./bug2 (gdb) handle SIGSEGV stop nopass Program received signal EXC_BAD_ACCESS, Could not access memory. Virtual Memory Map of process 17079 (bug2) ==== Non-writable regions for process 17079 ==== Writable regions for process 17079 ==== Legend ==== Summary for process 17079 REGION TYPE [ VIRTUAL] |
Comment author: @mshinwell Can you confirm whether the output you posted is from the program that normally causes a segfault, or from the one which produces a Stack_overflow exception? Whichever output you posted, please also paste the equivalent output from running the other program in the same manner. |
Comment author: kwakita I might have been confused when I posted the note #5032. To make things more clear, I modified the program little bit, as follows. ---- begin bug3.ml ----------------- module Make(Ord: Set.OrderedType) =
end module IntSet = let _ = It accepts one command-line argument, either "segv" or "overflow". When I execute this program with "./bug3 segv", it dies from SEGV signal. It finishes by receiving a Stack_overflow exception, when it is run by "./bug3 overflow". The following is a copy of gdb interaction and vmmap information obtained from "./bug3 segv" (the case when the program is killed from SEGV signal). ---- begin gdb interaction with "./bug3 segv" ----------------- dasher:bug$ gdb ./bug3 (gdb) handle SIGSEGV stop nopass Program received signal EXC_BAD_ACCESS, Could not access memory. ---- begin vmmap of "./bug3 segv" ----------------- ==== Non-writable regions for process 17706 ==== Writable regions for process 17706 ==== Legend ==== Summary for process 17706 REGION TYPE [ VIRTUAL] Then the following is the output of gdb session running "./bug3 overflow". This session stops from receiving Stack_overflow exception. ---- begin gdb interaction with "./bug3 overflow" ----------------- (gdb) handle SIGSEGV stop nopass Program received signal EXC_BAD_ACCESS, Could not access memory. The vmmap output for this session is exactly the same as the previous output, except for their process IDs. |
Comment author: @mshinwell Can you post the executable for bug3 itself? I assume it isn't too big, especially if compressed. |
Comment author: kwakita Yes, bug3.gz is the gzip'ed native code for bug3.ml. |
Comment author: @mshinwell I've reproduced the problem; give me a few days... |
Comment author: kwakita Thank you very much for your time and enormous effort! |
Comment author: @mshinwell I realized over the weekend what causes this. The difference in behaviour is because the faulting instruction lies in Caml compiler-generated code in one case, but in the runtime (C-compiler generated) code in another. The segfault will only be translated into a Stack_overflow exception in the former case. It isn't clear to me how this behaviour can be improved, since if for example the fault happened in the middle of the GC, it might not be safe to raise an exception and continue running Caml code. Xavier? :) |
Comment author: @xavierleroy Mark Shinwell's analysis is correct. We can catch SEGV arising from stack overflows in Caml code reasonably well, but we cannot recover from a SEGV arising in the middle of C code. I'm afraid this is a "cannot fix" situation. |
Original bug ID: 4843
Reporter: kwakita
Status: closed (set by @xavierleroy on 2009-09-16T09:16:41Z)
Resolution: not fixable
Priority: normal
Severity: crash
Version: 3.11.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @mshinwell till @mmottl
Bug description
Attached is a small program (bug2.ml) that exhibits segmentation violation error when it is compiled by ocamlopt and run on Intel/Mac OS X 10.5.7.
Interestingly, if I remove line 11 (the one that starts with 'ignore'), SEGV error disappears and the program reports Stack_overflow exception, which is the expected behavior.
Additional information
My platform is Intel/Mac OS X 10.5.7
The ocaml source distribution 3.11.1 was downloaded and compiled by myself.
File attachments
The text was updated successfully, but these errors were encountered: