|
1
|
+From: Xavier Leroy <xavier.leroy@college-de-france.fr>
|
|
2
|
+Date: Thu, 29 Aug 2024 12:08:16 +0200
|
|
3
|
+Subject: Don't use r12 to pass size to caml_call_realloc_stack
|
|
4
|
+
|
|
5
|
+The temporary r12 can be destroyed by a PLT shim.
|
|
6
|
+Instead, use r27 (a non-temporary register, not used at OCaml function entry).
|
|
7
|
+
|
|
8
|
+Origin: https://github.com/ocaml/ocaml/pull/13410
|
|
9
|
+---
|
|
10
|
+ asmcomp/power/emit.mlp | 3 ++-
|
|
11
|
+ runtime/power.S | 6 +++---
|
|
12
|
+ 2 files changed, 5 insertions(+), 4 deletions(-)
|
|
13
|
+
|
|
14
|
+diff --git a/asmcomp/power/emit.mlp b/asmcomp/power/emit.mlp
|
|
15
|
+index 47f5419..70a6a0f 100644
|
|
16
|
+--- a/asmcomp/power/emit.mlp
|
|
17
|
++++ b/asmcomp/power/emit.mlp
|
|
18
|
+@@ -996,8 +996,9 @@ let fundecl fundecl =
|
|
19
|
+ || max_frame_size >= stack_threshold_size then begin
|
|
20
|
+ let overflow = new_label () and ret = new_label () in
|
|
21
|
+ (* The return address is saved in a register not used for param passing *)
|
|
22
|
++ (* The size is passed in a register normally not used for param passing *)
|
|
23
|
+ `{emit_label overflow}: mflr 28\n`;
|
|
24
|
+- ` li 12, {emit_int (Config.stack_threshold + max_frame_size / 8)}\n`;
|
|
25
|
++ ` li 27, {emit_int (Config.stack_threshold + max_frame_size / 8)}\n`;
|
|
26
|
+ emit_call "caml_call_realloc_stack";
|
|
27
|
+ emit_call_nop ();
|
|
28
|
+ ` mtlr 28\n`;
|
|
29
|
+diff --git a/runtime/power.S b/runtime/power.S
|
|
30
|
+index bfb37fa..9e5b243 100644
|
|
31
|
+--- a/runtime/power.S
|
|
32
|
++++ b/runtime/power.S
|
|
33
|
+@@ -358,16 +358,16 @@
|
|
34
|
+ caml_system__code_begin:
|
|
35
|
+
|
|
36
|
+ /* Reallocate the stack when it is too small. */
|
|
37
|
+-/* Desired size is passed in register TMP2. */
|
|
38
|
++/* Desired size is passed in register r27. */
|
|
39
|
+
|
|
40
|
+ FUNCTION caml_call_realloc_stack
|
|
41
|
+ /* Save return address in caller's frame. */
|
|
42
|
+ mflr 0
|
|
43
|
+ std 0, LR_SAVE(SP)
|
|
44
|
+ /* Save all registers, as well as ALLOC_PTR and TRAP_PTR */
|
|
45
|
+- SAVE_ALL_REGS /* TMP2 is preserved */
|
|
46
|
++ SAVE_ALL_REGS /* r27 is preserved */
|
|
47
|
+ /* Recover desired size, to be passed in r3 */
|
|
48
|
+- mr 3, TMP2
|
|
49
|
++ mr 3, 27
|
|
50
|
+ /* Switch stacks and call caml_try_realloc_stack */
|
|
51
|
+ SWITCH_OCAML_TO_C
|
|
52
|
+ Far_call(caml_try_realloc_stack) |