Don't use r12 to pass size to caml_call_realloc_stack
authorXavier Leroy <xavier.leroy@college-de-france.fr>
Thu, 29 Aug 2024 10:08:16 +0000 (12:08 +0200)
committerStéphane Glondu <glondu@debian.org>
Thu, 29 Aug 2024 16:03:23 +0000 (18:03 +0200)
The temporary r12 can be destroyed by a PLT shim.
Instead, use r27 (a non-temporary register, not used at OCaml function entry).

Origin: https://github.com/ocaml/ocaml/pull/13410

Gbp-Pq: Name 0011-Don-t-use-r12-to-pass-size-to-caml_call_realloc_stac.patch

asmcomp/power/emit.mlp
runtime/power.S

index 47f5419a92c05c08182a15cab55b70726e527807..70a6a0f70e431d14cd0ea492ff8678b785f4ad3a 100644 (file)
@@ -996,8 +996,9 @@ let fundecl fundecl =
   || max_frame_size >= stack_threshold_size then begin
     let overflow = new_label () and ret = new_label () in
     (* The return address is saved in a register not used for param passing *)
+    (* The size is passed in a register normally not used for param passing *)
     `{emit_label overflow}:    mflr    28\n`;
-    `  li      12, {emit_int (Config.stack_threshold + max_frame_size / 8)}\n`;
+    `  li      27, {emit_int (Config.stack_threshold + max_frame_size / 8)}\n`;
     emit_call "caml_call_realloc_stack";
     emit_call_nop ();
     `  mtlr    28\n`;
index bfb37fa989caacc20e3b61f332de119a658dd90b..9e5b243aa1d9eb7e457081524010a655fada3a4c 100644 (file)
 caml_system__code_begin:
 
 /* Reallocate the stack when it is too small. */
-/* Desired size is passed in register TMP2. */
+/* Desired size is passed in register r27. */
 
 FUNCTION caml_call_realloc_stack
    /* Save return address in caller's frame. */
         mflr    0
         std     0, LR_SAVE(SP)
    /* Save all registers, as well as ALLOC_PTR and TRAP_PTR */
-        SAVE_ALL_REGS  /* TMP2 is preserved */
+        SAVE_ALL_REGS  /* r27 is preserved */
    /* Recover desired size, to be passed in r3 */
-        mr      3, TMP2
+        mr      3, 27
    /* Switch stacks and call caml_try_realloc_stack */
         SWITCH_OCAML_TO_C
         Far_call(caml_try_realloc_stack)