[RFC,5/5] aarch64: Add SFrame support for aarch64 architecture

Message ID 20250318130333.18829-6-claudiu.zissulescu-ianculescu@oracle.com (mailing list archive)
State New
Headers
Series glibc: Add SFrame support for stack backtracking |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 fail Patch failed to apply
redhat-pt-bot/TryBot-32bit fail Patch series failed to apply
linaro-tcwg-bot/tcwg_glibc_build--master-arm fail Patch failed to apply

Commit Message

Claudiu Zissulescu-Ianculescu March 18, 2025, 1:03 p.m. UTC
  From: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>

    The SFrame is supported for AArch64 architecture.
    Enable SFrame stack tracer for AArch64 too.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
---
 sysdeps/aarch64/bits/dl_find_object.h         | 28 ++++++++
 sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h | 70 +++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 sysdeps/aarch64/bits/dl_find_object.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
  

Comments

Jens Remus April 3, 2025, 9:20 a.m. UTC | #1
On 18.03.2025 14:03, claudiu.zissulescu-ianculescu@oracle.com wrote:

>      The SFrame is supported for AArch64 architecture.
>      Enable SFrame stack tracer for AArch64 too.

> diff --git a/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h

> +static _Unwind_Reason_Code
> +aarch64_decode_signal_frame (frame *frame)
> +{
> +  /* Linux kernel's rt_sigframe structure.  */
> +  struct rt_sigframe
> +  {
> +    siginfo_t info;
> +    ucontext_t uc;
> +  };

Maybe struct kernel_rt_sigframe could be used instead?
See sysdeps/unix/sysv/linux/aarch64/kernel_rt_sigframe.h.

Regards,
Jens
  

Patch

diff --git a/sysdeps/aarch64/bits/dl_find_object.h b/sysdeps/aarch64/bits/dl_find_object.h
new file mode 100644
index 0000000000..edcccfe31f
--- /dev/null
+++ b/sysdeps/aarch64/bits/dl_find_object.h
@@ -0,0 +1,28 @@ 
+/* System dependent definitions for finding objects by address.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _DLFCN_H
+# error "Never use <bits/dl_find_object.h> directly; include <dlfcn.h> instead."
+#endif
+
+#define DLFO_STRUCT_HAS_EH_DBASE 0
+#define DLFO_STRUCT_HAS_EH_COUNT 0
+#define DLFO_EH_SEGMENT_TYPE PT_GNU_EH_FRAME
+
+#define DLFO_SFRAME_SEGMENT_TYPE PT_GNU_SFRAME
+#define DLFO_STRUCT_HAS_SFRAME 1
diff --git a/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
new file mode 100644
index 0000000000..c41474fc6e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
@@ -0,0 +1,70 @@ 
+/* Signal frame backtracing support for SFrame on AARCH64.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* This code is inspired from libgcc's MD_FALLBACK_FRAME_STATE_FOR
+   implementation.  See libgcc/config/aarch64/gnu-unwind.h  */
+
+#include <signal.h>
+#include <sys/ucontext.h>
+
+#if __AARCH64EL__
+#define MOVZ_X8_8B      0xd2801168
+#define SVC_0           0xd4000001
+#else
+#error SFrame is not supported on big endian systems
+#endif
+
+#define MD_DECODE_SIGNAL_FRAME aarch64_decode_signal_frame
+
+static _Unwind_Reason_Code
+aarch64_decode_signal_frame (frame *frame)
+{
+  /* Linux kernel's rt_sigframe structure.  */
+  struct rt_sigframe
+  {
+    siginfo_t info;
+    ucontext_t uc;
+  };
+
+  unsigned int *pc = (unsigned int *) frame->pc;
+  struct sigcontext *sc;
+  struct rt_sigframe *rt_;
+
+  /* A signal frame will have a return address pointing to
+     __default_sa_restorer. This code is hardwired as:
+
+     0xd2801168         movz x8, #0x8b
+     0xd4000001         svc  0x0
+   */
+  if (pc[0] != MOVZ_X8_8B || pc[1] != SVC_0)
+    {
+      return _URC_END_OF_STACK;
+    }
+  rt_ = (struct rt_sigframe *) frame->sp;
+  sc = (struct sigcontext *) &rt_->uc.uc_mcontext;
+
+#define SP_REGNUM 31
+#define LR_REGNUM 29
+#define FP_REGNUM 30
+
+  frame->pc = (_Unwind_Ptr) sc->pc;
+  frame->sp = (_Unwind_Ptr) sc->sp;
+  frame->fp = (_Unwind_Ptr) sc->regs[FP_REGNUM];
+  return _URC_NO_REASON;
+}