Blob Blame History Raw
From d3ca0ccc0eccfecd4aa922decf99ca7d67d40fa7 Mon Sep 17 00:00:00 2001
From: Mark Shinwell <mshinwell@janestreet.com>
Date: Wed, 6 May 2015 17:37:43 +0000
Subject: [PATCH 16/18] Fix PR#6490: incorrect backtraces in gdb on AArch64.
 (Also fixes the same problem for 32-bit ARM.)

git-svn-id: http://caml.inria.fr/svn/ocaml/version/4.02@16091 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
---
 asmcomp/arm/emit.mlp   | 4 +++-
 asmcomp/arm64/emit.mlp | 6 ++++--
 asmcomp/emitaux.ml     | 9 +++++++++
 asmcomp/emitaux.mli    | 1 +
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/asmcomp/arm/emit.mlp b/asmcomp/arm/emit.mlp
index 61035b8..4948fb2 100644
--- a/asmcomp/arm/emit.mlp
+++ b/asmcomp/arm/emit.mlp
@@ -852,8 +852,10 @@ let fundecl fundecl =
   let n = frame_size() in
   if n > 0 then begin
     ignore(emit_stack_adjustment (-n));
-    if !contains_calls then
+    if !contains_calls then begin
+      cfi_offset ~reg:14 (* lr *) ~offset:(-4);
       `	str	lr, [sp, #{emit_int(n - 4)}]\n`
+    end
   end;
   `{emit_label !tailrec_entry_point}:\n`;
   emit_all 0 fundecl.fun_body;
diff --git a/asmcomp/arm64/emit.mlp b/asmcomp/arm64/emit.mlp
index 734bd23..c5c30d4 100644
--- a/asmcomp/arm64/emit.mlp
+++ b/asmcomp/arm64/emit.mlp
@@ -654,8 +654,10 @@ let fundecl fundecl =
   let n = frame_size() in
   if n > 0 then
     emit_stack_adjustment (-n);
-  if !contains_calls then
-    `	str	x30, [sp, #{emit_int (n-8)}]\n`;
+  if !contains_calls then begin
+    cfi_offset ~reg:30 (* return address *) ~offset:(-8);
+    `	str	x30, [sp, #{emit_int (n-8)}]\n`
+  end;
   `{emit_label !tailrec_entry_point}:\n`;
   emit_all fundecl.fun_body;
   List.iter emit_call_gc !call_gc_sites;
diff --git a/asmcomp/emitaux.ml b/asmcomp/emitaux.ml
index 24a621b..ec2e8f0 100644
--- a/asmcomp/emitaux.ml
+++ b/asmcomp/emitaux.ml
@@ -195,6 +195,15 @@ let cfi_adjust_cfa_offset n =
     emit_string "\t.cfi_adjust_cfa_offset\t"; emit_int n; emit_string "\n";
   end
 
+let cfi_offset ~reg ~offset =
+  if is_cfi_enabled () then begin
+    emit_string "\t.cfi_offset ";
+    emit_int reg;
+    emit_string ", ";
+    emit_int offset;
+    emit_string "\n"
+  end
+
 (* Emit debug information *)
 
 (* This assoc list is expected to be very short *)
diff --git a/asmcomp/emitaux.mli b/asmcomp/emitaux.mli
index 486a583..e943da3 100644
--- a/asmcomp/emitaux.mli
+++ b/asmcomp/emitaux.mli
@@ -56,3 +56,4 @@ val is_generic_function: string -> bool
 val cfi_startproc : unit -> unit
 val cfi_endproc : unit -> unit
 val cfi_adjust_cfa_offset : int -> unit
+val cfi_offset : reg:int -> offset:int -> unit
-- 
2.4.1