88f977
From a887f2e04859d288908ddf7c8835108cdcd1be6b Mon Sep 17 00:00:00 2001
88f977
From: Mark Shinwell <mshinwell@janestreet.com>
88f977
Date: Fri, 8 Aug 2014 14:38:12 +0100
88f977
Subject: [PATCH 11/11] aarch64: Fix for mantis 6507.
88f977
88f977
http://caml.inria.fr/mantis/view.php?id=6507
88f977
---
88f977
 asmrun/arm64.S | 26 +++++++++++++++++++++-----
88f977
 1 file changed, 21 insertions(+), 5 deletions(-)
88f977
88f977
diff --git a/asmrun/arm64.S b/asmrun/arm64.S
88f977
index 50abdae..0dcb3a8 100644
88f977
--- a/asmrun/arm64.S
88f977
+++ b/asmrun/arm64.S
88f977
@@ -83,10 +83,10 @@ caml_call_gc:
88f977
         PROFILE
88f977
     /* Record return address */
88f977
         STOREGLOBAL(x30, caml_last_return_address)
88f977
-.Lcaml_call_gc:
88f977
     /* Record lowest stack address */
88f977
         mov     TMP, sp
88f977
         STOREGLOBAL(TMP, caml_bottom_of_stack)
88f977
+.Lcaml_call_gc:
88f977
     /* Set up stack space, saving return address and frame pointer */
88f977
     /* (2 regs RA/GP, 24 allocatable int regs, 24 caller-save float regs) * 8 */
88f977
         stp     x29, x30, [sp, -400]!
88f977
@@ -175,7 +175,14 @@ caml_alloc1:
88f977
         ret
88f977
 2:      stp     x29, x30, [sp, -16]!
88f977
         CFI_ADJUST(16)
88f977
-        add     x29, sp, #0
88f977
+    /* Record the lowest address of the caller's stack frame.  This is the address
88f977
+       immediately above the pair of words (x29 and x30) we just pushed.  Those must
88f977
+       not be included since otherwise the distance from [caml_bottom_of_stack] to the
88f977
+       highest address in the caller's stack frame won't match the frame size contained
88f977
+       in the relevant frame descriptor. */
88f977
+        add     x29, sp, #16
88f977
+        STOREGLOBAL(x29, caml_bottom_of_stack)
88f977
+        sub     x29, x29, #16
88f977
     /* Record return address */
88f977
         STOREGLOBAL(x30, caml_last_return_address)
88f977
     /* Call GC */
88f977
@@ -200,7 +207,10 @@ caml_alloc2:
88f977
         ret
88f977
 2:      stp     x29, x30, [sp, -16]!
88f977
         CFI_ADJUST(16)
88f977
-        add     x29, sp, #0
88f977
+    /* Record the lowest address of the caller's stack frame.  See comment above. */
88f977
+        add     x29, sp, #16
88f977
+        STOREGLOBAL(x29, caml_bottom_of_stack)
88f977
+        sub     x29, x29, #16
88f977
     /* Record return address */
88f977
         STOREGLOBAL(x30, caml_last_return_address)
88f977
     /* Call GC */
88f977
@@ -225,7 +235,10 @@ caml_alloc3:
88f977
         ret
88f977
 2:      stp     x29, x30, [sp, -16]!
88f977
         CFI_ADJUST(16)
88f977
-        add     x29, sp, #0
88f977
+    /* Record the lowest address of the caller's stack frame.  See comment above. */
88f977
+        add     x29, sp, #16
88f977
+        STOREGLOBAL(x29, caml_bottom_of_stack)
88f977
+        sub     x29, x29, #16
88f977
     /* Record return address */
88f977
         STOREGLOBAL(x30, caml_last_return_address)
88f977
     /* Call GC */
88f977
@@ -250,7 +263,10 @@ caml_allocN:
88f977
         ret
88f977
 2:      stp     x29, x30, [sp, -16]!
88f977
         CFI_ADJUST(16)
88f977
-        add     x29, sp, #0
88f977
+    /* Record the lowest address of the caller's stack frame.  See comment above. */
88f977
+        add     x29, sp, #16
88f977
+        STOREGLOBAL(x29, caml_bottom_of_stack)
88f977
+        sub     x29, x29, #16
88f977
     /* Record return address */
88f977
         STOREGLOBAL(x30, caml_last_return_address)
88f977
     /* Call GC.  This preserves ARG */
88f977
-- 
88f977
1.9.3
88f977