[PATCH v6 3/5] aarch64: Add SFrame support for aarch64 architecture
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Jul 2 12:28:35 GMT 2025
On 10/06/25 04:33, claudiu.zissulescu-ianculescu@oracle.com wrote:
> 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/unix/sysv/linux/aarch64/uw-sigframe.h | 75 +++++++++++++++++++
> 1 file changed, 75 insertions(+)
> create mode 100644 sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
>
> 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..31ac90dc92
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
> @@ -0,0 +1,75 @@
> +/* 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/linux-unwind.h */
> +
> +#include <signal.h>
> +#include <sys/ucontext.h>
> +#include <kernel_rt_sigframe.h>
> +
> +#if __AARCH64EL__
> +#define MOVZ_X8_8B 0xd2801168
> +#define SVC_0 0xd4000001
> +#else
> +#define MOVZ_X8_8B 0x681180d2
> +#define SVC_0 0x010000d4
> +#endif
> +
> +#define MD_DECODE_SIGNAL_FRAME aarch64_decode_signal_frame
> +
> +static _Unwind_Reason_Code
> +aarch64_decode_signal_frame (frame *frame)
> +{
> + unsigned int *pc = (unsigned int *) frame->pc;
> + struct sigcontext *sc;
> + struct kernel_rt_sigframe *rt_;
> +
> + /* A signal frame will have a return address pointing to
> + __default_sa_restorer. This code is hardwired as:
I think you mean __kernel_rt_sigreturn here, since it is the vDSO symbol
used on aarch64.
> +
> + 0xd2801168 movz x8, #0x8b
> + 0xd4000001 svc 0x0
> + */
> + if (pc[0] != MOVZ_X8_8B || pc[1] != SVC_0)
As for x86_64 this is strictly UB, although like x86_64 aarch64 does
support unaligned memory operation by default.
> + return _URC_END_OF_STACK;
> +
> + rt_ = (struct kernel_rt_sigframe *) frame->sp;
> + sc = (struct sigcontext *) &rt_->uc.uc_mcontext;
> +
> + /* Frame pointer register number. */
> +#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;
As for x86_64, it is not clear to me why you need to access it through
a sigcontext alias instead of using the mcontext_t fields.
> +}
> +
> +#define MD_DETECT_OUTERMOST_FRAME aarch64_detect_outermost_frame
> +
> +static _Unwind_Reason_Code
> +aarch64_detect_outermost_frame (frame *frame)
> +{
> + /* Initial frame has LR and FP set to zero. We track only FP. */
> + if (frame->fp == 0)
> + return _URC_END_OF_STACK;
> +
> + return _URC_NO_REASON;
> +}
More information about the Libc-alpha
mailing list