Skip to content

Commit ad7ca31

Browse files
committed
merge
2 parents d892a4f + 7814eeb commit ad7ca31

File tree

83 files changed

+4500
-911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4500
-911
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
# run: HOMEBREW_NO_INSTALL_CLEANUP=TRUE brew install afl-fuzz
115115

116116
- name: Cache OCaml 4.14, dune and menhir
117-
uses: actions/cache@v2
117+
uses: actions/cache@v4
118118
id: cache
119119
with:
120120
path: ${{ github.workspace }}/ocaml-414/_install

HACKING.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ To rebuild after making changes, you can just type `make`. You need to
9696
have a working OCaml 4.14 or 4.14.1 compiler on your PATH before doing so,
9797
e.g. installed via OPAM. You also need to have dune and menhir.
9898

99-
<!-- CR someone: investigate this -->
100-
The build currently fails when using the latest version of `dune` (3.11.1).
101-
To install a known-good dune, run `opam pin add dune 3.8.1`. `menhir` should be pinned to a specific
102-
version as well: `opam pin add menhir 20210419`.
99+
`menhir` should be pinned to a specific version: `opam pin add menhir 20210419`.
103100

104101
There is a special target `make hacking` which starts Dune in polling mode. The rebuild
105102
performed here is equivalent to `make ocamlopt` in the upstream distribution: it rebuilds the

backend/amd64/emit.mlp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -474,31 +474,44 @@ let emit_call_safety_errors () =
474474
type stack_realloc = {
475475
sc_label : Label.t; (* Label of the reallocation code. *)
476476
sc_return : Label.t; (* Label to return to after reallocation. *)
477-
sc_max_frame_size_in_bytes : int; (* Size for reallocation. *)
477+
sc_size_in_bytes : int; (* Size for reallocation. *)
478478
}
479479

480-
let stack_realloc = ref (None : stack_realloc option)
480+
let stack_realloc = ref ([] : stack_realloc list)
481481

482482
let clear_stack_realloc () =
483-
stack_realloc := None
483+
stack_realloc := []
484484

485485
let emit_stack_realloc () =
486-
begin match !stack_realloc with
487-
| None -> ()
488-
| Some { sc_label; sc_return; sc_max_frame_size_in_bytes; } -> begin
489-
def_label sc_label;
490-
(* Pass the desired frame size on the stack, since all of the
491-
argument-passing registers may be in use.
492-
Also serves to align the stack properly before the call *)
493-
I.push (int (Config.stack_threshold + sc_max_frame_size_in_bytes / 8));
494-
cfi_adjust_cfa_offset 8;
495-
(* measured in words *)
496-
emit_call (Cmm.global_symbol "caml_call_realloc_stack");
497-
I.add (int 8) rsp;
498-
cfi_adjust_cfa_offset (-8);
499-
I.jmp (label sc_return)
500-
end
501-
end
486+
List.iter
487+
(fun { sc_label; sc_return; sc_size_in_bytes; } ->
488+
def_label sc_label;
489+
(* Pass the desired frame size on the stack, since all of the
490+
argument-passing registers may be in use.
491+
Also serves to align the stack properly before the call *)
492+
I.push (int (Config.stack_threshold + sc_size_in_bytes / 8));
493+
cfi_adjust_cfa_offset 8;
494+
(* measured in words *)
495+
emit_call (Cmm.global_symbol "caml_call_realloc_stack");
496+
I.add (int 8) rsp;
497+
cfi_adjust_cfa_offset (-8);
498+
I.jmp (label sc_return))
499+
!stack_realloc
500+
501+
let emit_stack_check ~size_in_bytes ~save_registers =
502+
let overflow = new_label () and ret = new_label () in
503+
let threshold_offset = Domainstate.stack_ctx_words * 8 + Stack_check.stack_threshold_size in
504+
if save_registers then I.push r10;
505+
I.lea (mem64 NONE (-(size_in_bytes + threshold_offset)) RSP) r10;
506+
I.cmp (domain_field Domainstate.Domain_current_stack) r10;
507+
if save_registers then I.pop r10;
508+
I.jb (label overflow);
509+
def_label ret;
510+
stack_realloc := {
511+
sc_label = overflow;
512+
sc_return = ret;
513+
sc_size_in_bytes = size_in_bytes;
514+
} :: !stack_realloc
502515

503516
(* Record jump tables *)
504517
type jump_table =
@@ -1856,20 +1869,7 @@ let emit_instr ~first ~fallthrough i =
18561869
I.jmp r11
18571870
end
18581871
| Lstackcheck { max_frame_size_bytes; } ->
1859-
let save_registers = not first in
1860-
let overflow = new_label () and ret = new_label () in
1861-
let threshold_offset = Domainstate.stack_ctx_words * 8 + Stack_check.stack_threshold_size in
1862-
if save_registers then I.push r10;
1863-
I.lea (mem64 NONE (-(max_frame_size_bytes + threshold_offset)) RSP) r10;
1864-
I.cmp (domain_field Domainstate.Domain_current_stack) r10;
1865-
if save_registers then I.pop r10;
1866-
I.jb (label overflow);
1867-
def_label ret;
1868-
stack_realloc := Some {
1869-
sc_label = overflow;
1870-
sc_return = ret;
1871-
sc_max_frame_size_in_bytes = max_frame_size_bytes;
1872-
}
1872+
emit_stack_check ~size_in_bytes:max_frame_size_bytes ~save_registers:(not first)
18731873

18741874
let rec emit_all ~first ~fallthrough i =
18751875
match i.desc with
@@ -1933,7 +1933,7 @@ let fundecl fundecl =
19331933
D.label (label_name (emit_symbol fundecl.fun_name));
19341934
emit_debug_info fundecl.fun_dbg;
19351935
cfi_startproc ();
1936-
if Config.runtime5 && !Clflags.runtime_variant = "d" then begin
1936+
if Config.runtime5 && (not Config.no_stack_checks) && !Clflags.runtime_variant = "d" then begin
19371937
emit_call (Cmm.global_symbol "caml_assert_stack_invariants");
19381938
end;
19391939
emit_all ~first:true ~fallthrough:true fundecl.fun_body;
@@ -2199,6 +2199,8 @@ let emit_probe_handler_wrapper p =
21992199
let padding = if ((wrapper_frame_size k) mod 16) = 0 then 0 else 8 in
22002200
let n = k + padding in
22012201
(* Allocate stack space *)
2202+
if Config.runtime5 && (not Config.no_stack_checks) && (n >= Stack_check.stack_threshold_size) then
2203+
emit_stack_check ~size_in_bytes:n ~save_registers:true;
22022204
emit_stack_offset n;
22032205
(* Save all live hard registers *)
22042206
let offset = aux_offset + tmp_offset + loc_offset in

backend/cfg/cfg_dominators.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module List = ListLabels
88

99
let fatal = Misc.fatal_errorf
1010

11-
(* CR-soon xclerc for xclerc: switch back to `false`. *)
12-
let debug = true
11+
let debug = false
1312

1413
type doms = Label.t Label.Tbl.t
1514

backend/cfg/cfg_stack_checks.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@ let cfg (cfg_with_layout : Cfg_with_layout.t) =
217217
| false -> cfg_with_layout
218218
| true ->
219219
let cfg = Cfg_with_layout.cfg cfg_with_layout in
220-
let { max_frame_size; blocks_needing_stack_checks; max_instr_id } =
221-
build_cfg_info cfg
222-
in
223-
if not (Label.Set.is_empty blocks_needing_stack_checks)
220+
(if not Config.no_stack_checks
224221
then
225-
insert_stack_checks cfg ~max_frame_size ~blocks_needing_stack_checks
226-
~max_instr_id;
222+
let { max_frame_size; blocks_needing_stack_checks; max_instr_id } =
223+
build_cfg_info cfg
224+
in
225+
if not (Label.Set.is_empty blocks_needing_stack_checks)
226+
then
227+
insert_stack_checks cfg ~max_frame_size ~blocks_needing_stack_checks
228+
~max_instr_id);
227229
cfg_with_layout

0 commit comments

Comments
 (0)