[PATCH v4 4/5] x86: Add SFrame support for x86 architecture

Sam James sam@gentoo.org
Sat Apr 19 05:27:31 GMT 2025


claudiu.zissulescu-ianculescu@oracle.com writes:

> From: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
>
> The SFrame is well supported by x86 architecture since binutils 2.41.
> Enable it to be used as default frame tracer.
>
> Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
> ---
>  sysdeps/unix/sysv/linux/x86/uw-sigframe.h | 61 +++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/x86/uw-sigframe.h
>
> diff --git a/sysdeps/unix/sysv/linux/x86/uw-sigframe.h b/sysdeps/unix/sysv/linux/x86/uw-sigframe.h
> new file mode 100644
> index 0000000000..79b2b4e40d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/x86/uw-sigframe.h
> @@ -0,0 +1,61 @@
> +/* Signal frame backtracing support for SFrame on AMD, x86-64 and x86.
> +   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/i386/gnu-unwind.h  */

At a glance, it looks closer to libgcc/config/i386/linux-unwind.h but I
didn't check in detail. If I'm wrong, juts ignore.

> +
> +#include <signal.h>
> +#include <sys/ucontext.h>
> +
> +#ifdef __x86_64__
> +
> +/* SFrame is only supported by x86_64 targets.  */
> +
> +#define MD_DECODE_SIGNAL_FRAME x86_64_decode_signal_frame
> +
> +static _Unwind_Reason_Code
> +x86_64_decode_signal_frame (frame *frame)
> +{
> +  unsigned char *pc = (unsigned char *) frame->pc;
> +  struct sigcontext *sc;
> +
> +  /* movq $__NR_rt_sigreturn, %rax ; syscall.  */
> +#ifdef __LP64__
> +#define RT_SIGRETURN_SYSCALL	0x050f0000000fc0c7ULL
> +#else
> +#define RT_SIGRETURN_SYSCALL	0x050f40000201c0c7ULL
> +#endif
> +  if (*(unsigned char *)(pc+0) == 0x48
> +      && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
> +    {
> +      ucontext_t *uc_ = (ucontext_t *)frame->sp;
> +      /* The void * cast is necessary to avoid an aliasing warning.
> +         The aliasing warning is correct, but should not be a problem
> +         because it does not alias anything.  */
> +      sc = (struct sigcontext *) (void *) &uc_->uc_mcontext;
> +    }
> +  else
> +    return _URC_END_OF_STACK;
> +
> +  frame->pc = (_Unwind_Ptr) sc->rip;
> +  frame->sp = (_Unwind_Ptr) sc->rsp;
> +  frame->fp = (_Unwind_Ptr) sc->rbp;
> +  return _URC_NO_REASON;
> +}
> +#endif /* ifdef __x86_64__  */


More information about the Libc-alpha mailing list