Bug#583291: Acknowledgement (menhir: segmentation fault)
clone 583291 -1
reassign -1 ocaml
retitle -1 ocamlopt x86_64: Stack_overflow not always generated properly
thanks
I built a bytecode version of menhir, and used OCAMLRUNPARAM=b, and got
this stacktrace (the bytecode doesn't segfault):
Fatal error: exception Stack_overflow
Raised by primitive operation at file "convert.ml", line 70, characters
27-34
Called from file "engine.ml", line 42, characters 16-32
Called from file "engine.ml", line 101, characters 4-154
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Called from file "referenceInterpreter.ml", line 73, characters 3-30
...
Called from file "referenceInterpreter.ml", line 73, characters 3-30
Here is a gdb backtrace of the segfault though (on the core file):
#0 0x00000000004b933b in caml_equal ()
#1 0x00000000004c49bc in ?? ()
#2 0x00007f42a1a59d20 in ?? ()
#3 0x0000000000000003 in ?? ()
#4 0x0000000000000001 in ?? ()
#5 0x00007f42a1a59d60 in ?? ()
#6 0x00007f42a1a59e88 in ?? ()
#7 0x0000000000000001 in ?? ()
#8 0x00007f42a1a59d60 in ?? ()
#9 0x000000000043bad9 in ?? ()
#10 0x00007ffff54890b0 in ?? ()
#11 0x000000000043b94e in ?? ()
#12 0x00007f42a1a59ec8 in ?? ()
#13 0x00007f42a1a59cc0 in ?? ()
#14 0x00007f42a1a59ea8 in ?? ()
#15 0x00007f42a1a5a898 in ?? ()
Problem is an OCaml stack overflow exception could be caught by the app
(menhir), but a segfault not...
AFAICT in native mode OCaml catches the sigsegv, figures out it is a
stack overflow and raises the appropriate exception
So it must be something wrong in OCaml's segfault -> stack_overflow
exception conversion code on x86_64.
I tried on x86-32 (same machine, in a chroot), and the stack overflow
was always caught, no segfaults.
I'm adding some printfs to the asmrun code in the sigsegv handler, and
here it is:
in asmrun/signals_asm.c:
printf("segv at %p %p, %d %p - %p\n%p, %p - %p: %d", fault_addr,
((uintnat) fault_addr & (sizeof(intnat) - 1)),
getrlimit(RLIMIT_STACK, &limit),
system_stack_top,
system_stack_top - limit.rlim_cur - 0x2000,
CONTEXT_PC,
caml_code_area_start,
caml_code_area_end,
Is_in_code_area(CONTEXT_PC)
);
Output:
segv at 0x7fff38e30ff8 (nil), 0 0x7fff3962ff40 - 0x7fff3962df40
0x4b84a5, 0x41fee0 - 0x4aedd9: 0Segmentation fault
segv at 0x7fff417dfff0 (nil), 0 0x7fff41fdd1b0 - 0x7fff41fdb1b0
0x48b004, 0x41fee0 - 0x4aedd9: 1Fatal error: exception Stack_overflow
So Is_in_code_area is wrong, see above the crash is in caml_equal, yet
caml_code_area_end is below that address, and Is_in_code_area returns
false too.
Best regards,
--Edwin
Reply to: