Skip to content

Commit bbef9e5

Browse files
xclercmshinwell
andauthored
flambda-backend: Fix for stack checks / frame pointers (#2603)
* CI job to test frame pointers with runtime5 * Avoid warning about rewrite_frame_pointers being unused * Fix frame pointers tests (cherry picked from commit 4184a7150d754a7d4903566ed5851e2d8f56e8a9) * Fix for stack checks / frame pointers. * Backtrace * Handle non-segfaulting paths... * Specialized version of ENTER_FUNCTION for caml_raise_stack_overflow_nat. * Review --------- Co-authored-by: Mark Shinwell <mshinwell@pm.me>
1 parent d6b1dfe commit bbef9e5

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

runtime/amd64.S

+1-7
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ ENDFUNCTION(G(caml_call_gc))
548548
FUNCTION(G(caml_raise_stack_overflow_nat))
549549
CFI_STARTPROC
550550
CFI_SIGNAL_FRAME
551-
ENTER_FUNCTION
552551
SAVE_ALL_REGS
553552
movq %r15, Caml_state(gc_regs)
554553
/* We assume that we are always on the OCaml stack at this point.
@@ -558,12 +557,7 @@ CFI_STARTPROC
558557
in practice this seems most unlikely. The current situation will
559558
suffice as this patch is only a temporary measure in any case. */
560559
SWITCH_OCAML_TO_C
561-
C_call (GCALL(caml_raise_stack_overflow))
562-
SWITCH_C_TO_OCAML
563-
movq Caml_state(gc_regs), %r15
564-
RESTORE_ALL_REGS
565-
LEAVE_FUNCTION
566-
ret
560+
CHECK_STACK_ALIGNMENT; jmp GCALL(caml_raise_stack_overflow)
567561
CFI_ENDPROC
568562
ENDFUNCTION(G(caml_raise_stack_overflow_nat))
569563

runtime/fiber.c

+2
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ void caml_rewrite_exception_stack(struct stack_info *old_stack,
749749
}
750750

751751
#ifdef WITH_FRAME_POINTERS
752+
#if defined(STACK_CHECKS_ENABLED)
752753
/* Update absolute base pointers for new stack */
753754
static void rewrite_frame_pointers(struct stack_info *old_stack,
754755
struct stack_info *new_stack)
@@ -803,6 +804,7 @@ static void rewrite_frame_pointers(struct stack_info *old_stack,
803804
}
804805
#endif
805806
#endif
807+
#endif
806808

807809
int caml_try_realloc_stack(asize_t required_space)
808810
{

testsuite/tests/frame-pointers/c_call.ml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
native;
77
*)
88

9+
(* Force -O3 to ensure the "_code" symbols are present (see the
10+
reference file). *)
11+
[@@@ocaml.flambda_o3]
12+
913
external fp_backtrace : unit -> unit = "fp_backtrace"
1014
external fp_backtrace_no_alloc : unit -> unit = "fp_backtrace" [@@noalloc]
1115
external fp_backtrace_many_args : int -> int -> int -> int -> int -> int -> int

testsuite/tests/frame-pointers/c_call.reference

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
fp_backtrace_many_args
22
caml_c_call_stack_args
3-
camlC_call.f
3+
camlC_call.f_0_1_code
44
camlC_call.entry
55
caml_program
66
caml_start_program
77
caml_main/caml_startup
88
main
99
caml_c_call
10-
camlC_call.f
10+
camlC_call.f_0_1_code
1111
camlC_call.entry
1212
caml_program
1313
caml_start_program
1414
caml_main/caml_startup
1515
main
16-
camlC_call.f
16+
camlC_call.f_0_1_code
1717
camlC_call.entry
1818
caml_program
1919
caml_start_program

testsuite/tests/frame-pointers/exception_handler.ml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
native;
77
*)
88

9+
(* Force -O3 to ensure the "_code" symbols are present (see the
10+
reference file). *)
11+
[@@@ocaml.flambda_o3]
12+
913
(* https://github.com/ocaml/ocaml/pull/11031 *)
1014
external fp_backtrace : unit -> unit = "fp_backtrace" [@@noalloc]
1115

testsuite/tests/frame-pointers/exception_handler.reference

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
camlException_handler.handler
2-
camlException_handler.bare
1+
camlException_handler.handler_2_7_code
2+
camlException_handler.bare_4_9_code
33
camlException_handler.entry
44
caml_program
55
caml_start_program
66
caml_main/caml_startup
77
main
8-
camlException_handler.handler
9-
camlException_handler.bare
8+
camlException_handler.handler_2_7_code
9+
camlException_handler.bare_4_9_code
1010
camlException_handler.entry
1111
caml_program
1212
caml_start_program
1313
caml_main/caml_startup
1414
main
15-
camlException_handler.handler
16-
camlException_handler.nested
15+
camlException_handler.handler_2_7_code
16+
camlException_handler.nested_3_8_code
1717
camlException_handler.entry
1818
caml_program
1919
caml_start_program
2020
caml_main/caml_startup
2121
main
22-
camlException_handler.handler
23-
camlException_handler.nested
22+
camlException_handler.handler_2_7_code
23+
camlException_handler.nested_3_8_code
2424
camlException_handler.entry
2525
caml_program
2626
caml_start_program

0 commit comments

Comments
 (0)