aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rwxr-xr-xsysdeps/aarch64/configure2
-rw-r--r--sysdeps/aarch64/configure.ac2
-rw-r--r--sysdeps/generic/Makefile3
-rw-r--r--sysdeps/generic/sframe-read.c636
-rw-r--r--sysdeps/generic/sframe-read.h112
-rw-r--r--sysdeps/generic/sframe.c187
-rw-r--r--sysdeps/generic/sframe.h378
-rw-r--r--sysdeps/generic/uw-sigframe.h31
-rw-r--r--sysdeps/i386/Makefile27
-rw-r--r--sysdeps/pthread/Makefile1
-rw-r--r--sysdeps/pthread/tst-backtrace1.c84
-rw-r--r--sysdeps/pthread/tst-cond23.c2
-rw-r--r--sysdeps/unix/sysv/linux/Makefile2
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h78
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/ioctls.h36
-rw-r--r--sysdeps/unix/sysv/linux/alpha/termios_arch.h26
-rw-r--r--sysdeps/unix/sysv/linux/bits/ioctls.h14
-rw-r--r--sysdeps/unix/sysv/linux/hppa/bits/ioctls.h36
-rw-r--r--sysdeps/unix/sysv/linux/isatty.c2
-rw-r--r--sysdeps/unix/sysv/linux/isatty_nostatus.c2
-rw-r--r--sysdeps/unix/sysv/linux/mips/termios_arch.h (renamed from sysdeps/unix/sysv/linux/mips/old_termios.h)23
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h27
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/termios_arch.h33
-rw-r--r--sysdeps/unix/sysv/linux/sparc/bits/ioctls.h36
-rw-r--r--sysdeps/unix/sysv/linux/sparc/termios_arch.h (renamed from sysdeps/unix/sysv/linux/sparc/old_termios.h)23
-rw-r--r--sysdeps/unix/sysv/linux/tcgetattr.c2
-rw-r--r--sysdeps/unix/sysv/linux/tcsetattr.c18
-rw-r--r--sysdeps/unix/sysv/linux/termios-kernel-consts.sym26
-rw-r--r--sysdeps/unix/sysv/linux/termios_arch.h23
-rw-r--r--sysdeps/unix/sysv/linux/termios_internals.h42
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/uw-sigframe.h76
-rw-r--r--sysdeps/x86/configure4
-rw-r--r--sysdeps/x86/configure.ac2
-rw-r--r--sysdeps/x86_64/Makefile25
-rw-r--r--sysdeps/x86_64/configure2
-rw-r--r--sysdeps/x86_64/configure.ac2
-rw-r--r--sysdeps/x86_64/fpu/math-use-builtins-trunc.h9
-rw-r--r--sysdeps/x86_64/fpu/multiarch/Makefile23
-rw-r--r--sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1-avx.h41
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modf-avx.c3
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c3
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modf.c41
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modff-avx.c3
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c3
-rw-r--r--sysdeps/x86_64/fpu/multiarch/s_modff.c41
45 files changed, 1962 insertions, 230 deletions
diff --git a/sysdeps/aarch64/configure b/sysdeps/aarch64/configure
index 26a0989..f364e65 100755
--- a/sysdeps/aarch64/configure
+++ b/sysdeps/aarch64/configure
@@ -194,3 +194,5 @@ if test $build_mathvec = no; then
printf "%s\n" "$as_me: WARNING: mathvec is disabled, this results in incomplete ABI." >&2;}
fi
+libc_cv_support_sframe=yes
+
diff --git a/sysdeps/aarch64/configure.ac b/sysdeps/aarch64/configure.ac
index 22fca8b..a9a1b74 100644
--- a/sysdeps/aarch64/configure.ac
+++ b/sysdeps/aarch64/configure.ac
@@ -31,3 +31,5 @@ fi
if test $build_mathvec = no; then
AC_MSG_WARN([mathvec is disabled, this results in incomplete ABI.])
fi
+
+libc_cv_support_sframe=yes
diff --git a/sysdeps/generic/Makefile b/sysdeps/generic/Makefile
index 3ed75dd..1be63b7 100644
--- a/sysdeps/generic/Makefile
+++ b/sysdeps/generic/Makefile
@@ -21,6 +21,9 @@ CFLAGS-wordcopy.c += -Wno-uninitialized
endif
ifeq ($(subdir),elf)
+ifeq ($(enable-gsframe),yes)
+sysdep_routines += sframe-read sframe
+endif
ifeq (yes:yes,$(build-shared):$(unwind-find-fde))
# This is needed to support g++ v2 and v3.
sysdep_routines += framestate unwind-pe
diff --git a/sysdeps/generic/sframe-read.c b/sysdeps/generic/sframe-read.c
new file mode 100644
index 0000000..a6ebc42
--- /dev/null
+++ b/sysdeps/generic/sframe-read.c
@@ -0,0 +1,636 @@
+/* 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 General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+#include <sframe-read.h>
+
+/* Get the SFrame header size. */
+
+static inline uint32_t
+sframe_get_hdr_size (sframe_header *sfh)
+{
+ return SFRAME_V1_HDR_SIZE (*sfh);
+}
+
+/* Access functions for frame row entry data. */
+
+static inline uint8_t
+sframe_fre_get_offset_count (uint8_t fre_info)
+{
+ return SFRAME_V1_FRE_OFFSET_COUNT (fre_info);
+}
+
+static inline uint8_t
+sframe_fre_get_offset_size (uint8_t fre_info)
+{
+ return SFRAME_V1_FRE_OFFSET_SIZE (fre_info);
+}
+
+static inline bool
+sframe_get_fre_ra_mangled_p (uint8_t fre_info)
+{
+ return SFRAME_V1_FRE_MANGLED_RA_P (fre_info);
+}
+
+/* Access functions for info from function descriptor entry. */
+
+static uint32_t
+sframe_get_fre_type (sframe_func_desc_entry *fdep)
+{
+ uint32_t fre_type = 0;
+ if (fdep != NULL)
+ fre_type = SFRAME_V1_FUNC_FRE_TYPE (fdep->sfde_func_info);
+ return fre_type;
+}
+
+static uint32_t
+sframe_get_fde_type (sframe_func_desc_entry *fdep)
+{
+ uint32_t fde_type = 0;
+ if (fdep != NULL)
+ fde_type = SFRAME_V1_FUNC_FDE_TYPE (fdep->sfde_func_info);
+ return fde_type;
+}
+
+/* Check if SFrame header has valid data. Only consider SFrame type
+ 2. */
+
+static bool
+sframe_header_sanity_check_p (sframe_header *hp)
+{
+ /* Check preamble is valid. */
+ if ((hp->sfh_preamble.sfp_magic != SFRAME_MAGIC)
+ || (hp->sfh_preamble.sfp_version != SFRAME_VERSION_2)
+ || (hp->sfh_preamble.sfp_flags & ~SFRAME_V2_F_ALL_FLAGS))
+ return false;
+
+ /* Check offsets are valid. */
+ if (hp->sfh_fdeoff > hp->sfh_freoff)
+ return false;
+
+ return true;
+}
+
+/* Get the FRE start address size. */
+
+static size_t
+sframe_fre_start_addr_size (uint32_t fre_type)
+{
+ size_t addr_size = 0;
+ switch (fre_type)
+ {
+ case SFRAME_FRE_TYPE_ADDR1:
+ addr_size = 1;
+ break;
+ case SFRAME_FRE_TYPE_ADDR2:
+ addr_size = 2;
+ break;
+ case SFRAME_FRE_TYPE_ADDR4:
+ addr_size = 4;
+ break;
+ default:
+ break;
+ }
+ return addr_size;
+}
+
+/* Check if the FREP has valid data. */
+
+static bool
+sframe_fre_sanity_check_p (sframe_frame_row_entry *frep)
+{
+ uint8_t offset_size, offset_cnt;
+ uint8_t fre_info;
+
+ if (frep == NULL)
+ return false;
+
+ fre_info = frep->fre_info;
+ offset_size = sframe_fre_get_offset_size (fre_info);
+
+ if (offset_size != SFRAME_FRE_OFFSET_1B
+ && offset_size != SFRAME_FRE_OFFSET_2B
+ && offset_size != SFRAME_FRE_OFFSET_4B)
+ return false;
+
+ offset_cnt = sframe_fre_get_offset_count (fre_info);
+ if (offset_cnt > MAX_NUM_STACK_OFFSETS)
+ return false;
+
+ return true;
+}
+
+/* Get FRE_INFO's offset size in bytes. */
+
+static size_t
+sframe_fre_offset_bytes_size (uint8_t fre_info)
+{
+ uint8_t offset_size, offset_cnt;
+
+ offset_size = sframe_fre_get_offset_size (fre_info);
+
+ offset_cnt = sframe_fre_get_offset_count (fre_info);
+
+ if (offset_size == SFRAME_FRE_OFFSET_2B
+ || offset_size == SFRAME_FRE_OFFSET_4B) /* 2 or 4 bytes. */
+ return (offset_cnt * (offset_size * 2));
+
+ return (offset_cnt);
+}
+
+/* Get total size in bytes to represent FREP in the binary format. This
+ includes the starting address, FRE info, and all the offsets. */
+
+static size_t
+sframe_fre_entry_size (sframe_frame_row_entry *frep, size_t addr_size)
+{
+ if (frep == NULL)
+ return 0;
+
+ uint8_t fre_info = frep->fre_info;
+
+ return (addr_size + sizeof (frep->fre_info)
+ + sframe_fre_offset_bytes_size (fre_info));
+}
+
+/* Get SFrame header from the given decoder context DCTX. */
+
+static inline sframe_header *
+sframe_decoder_get_header (sframe_decoder_ctx *dctx)
+{
+ sframe_header *hp = NULL;
+ if (dctx != NULL)
+ hp = &dctx->sfd_header;
+ return hp;
+}
+
+/* Get the offset of the sfde_func_start_address field (from the start of the
+ on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the decoder
+ context DCTX. */
+
+static uint32_t
+sframe_decoder_get_offsetof_fde_start_addr (sframe_decoder_ctx *dctx,
+ uint32_t func_idx,
+ _Unwind_Reason_Code *errp)
+{
+ sframe_header *dhp;
+
+ dhp = sframe_decoder_get_header (dctx);
+ if (dhp == NULL)
+ {
+ if (errp != NULL)
+ *errp = _URC_END_OF_STACK;
+ return 0;
+ }
+
+ if (func_idx >= dhp->sfh_num_fdes)
+ {
+ if (errp != NULL)
+ *errp = _URC_END_OF_STACK;
+ return 0;
+ }
+ else if (errp != NULL)
+ *errp = _URC_NO_REASON;
+
+ return (sframe_get_hdr_size (dhp)
+ + func_idx * sizeof (sframe_func_desc_entry)
+ + offsetof (sframe_func_desc_entry, sfde_func_start_address));
+}
+
+
+/* Get the offset of the start PC of the SFrame FDE at FUNC_IDX from
+ the start of the SFrame section. If the flag
+ SFRAME_F_FDE_FUNC_START_PCREL is set, sfde_func_start_address is
+ the offset of the start PC of the function from the field itself.
+
+ If FUNC_IDX is not a valid index in the given decoder object, returns 0. */
+
+static int32_t
+sframe_decoder_get_secrel_func_start_addr (sframe_decoder_ctx *dctx,
+ uint32_t func_idx)
+{
+ int32_t func_start_addr;
+ _Unwind_Reason_Code err = 0;
+ int32_t offsetof_fde_in_sec = 0;
+
+ /* Check if we have SFRAME_F_FDE_FUNC_START_PCREL. */
+ sframe_header *sh = &dctx->sfd_header;
+ if ((sh->sfh_preamble.sfp_flags & SFRAME_F_FDE_FUNC_START_PCREL))
+ {
+ offsetof_fde_in_sec =
+ sframe_decoder_get_offsetof_fde_start_addr (dctx, func_idx, &err);
+ /* If func_idx is not a valid index, return 0. */
+ if (err == _URC_END_OF_STACK)
+ return 0;
+ }
+
+ func_start_addr = dctx->sfd_funcdesc[func_idx].sfde_func_start_address;
+
+ return func_start_addr + offsetof_fde_in_sec;
+}
+
+/* Check if the SFrame Frame Row Entry identified via the
+ START_IP_OFFSET and the END_IP_OFFSET (for SFrame FDE at
+ FUNC_IDX). */
+
+static bool
+sframe_fre_check_range_p (sframe_decoder_ctx *dctx, uint32_t func_idx,
+ uint32_t start_ip_offset, uint32_t end_ip_offset,
+ int32_t pc)
+{
+ sframe_func_desc_entry *fdep;
+ int32_t func_start_addr;
+ uint8_t rep_block_size;
+ uint32_t fde_type;
+ uint32_t pc_offset;
+ bool mask_p;
+
+ fdep = &dctx->sfd_funcdesc[func_idx];
+ if (fdep == NULL)
+ return false;
+
+ func_start_addr = sframe_decoder_get_secrel_func_start_addr (dctx, func_idx);
+ fde_type = sframe_get_fde_type (fdep);
+ mask_p = (fde_type == SFRAME_FDE_TYPE_PCMASK);
+ rep_block_size = fdep->sfde_func_rep_size;
+
+ if (func_start_addr > pc)
+ return false;
+
+ /* Given func_start_addr <= pc, pc - func_start_addr must be positive. */
+ pc_offset = pc - func_start_addr;
+ /* For SFrame FDEs encoding information for repetitive pattern of insns,
+ masking with the rep_block_size is necessary to find the matching FRE. */
+ if (mask_p)
+ pc_offset = pc_offset % rep_block_size;
+
+ return (start_ip_offset <= pc_offset) && (end_ip_offset >= pc_offset);
+}
+
+/* Get IDX'th offset from FRE. Set ERRP as applicable. */
+
+static int32_t
+sframe_get_fre_offset (sframe_frame_row_entry *fre,
+ int idx,
+ _Unwind_Reason_Code *errp)
+{
+ uint8_t offset_cnt, offset_size;
+
+ if (!sframe_fre_sanity_check_p (fre))
+ {
+ *errp = _URC_END_OF_STACK;
+ return 0;
+ }
+
+ offset_cnt = sframe_fre_get_offset_count (fre->fre_info);
+ offset_size = sframe_fre_get_offset_size (fre->fre_info);
+
+ if (offset_cnt < (idx + 1))
+ {
+ *errp = _URC_END_OF_STACK;
+ return 0;
+ }
+ *errp = _URC_NO_REASON;
+
+ if (offset_size == SFRAME_FRE_OFFSET_1B)
+ {
+ int8_t *sp = (int8_t *)fre->fre_offsets;
+ return sp[idx];
+ }
+ else if (offset_size == SFRAME_FRE_OFFSET_2B)
+ {
+ int16_t *sp = (int16_t *)fre->fre_offsets;
+ return sp[idx];
+ }
+ else
+ {
+ int32_t *ip = (int32_t *)fre->fre_offsets;
+ return ip[idx];
+ }
+}
+
+/* Decode the SFrame FRE start address offset value from FRE_BUF in on-disk
+ binary format, given the FRE_TYPE. Updates the FRE_START_ADDR. */
+
+static void
+sframe_decode_fre_start_address (const char *fre_buf,
+ uint32_t *fre_start_addr,
+ uint32_t fre_type)
+{
+ uint32_t saddr = 0;
+
+ if (fre_type == SFRAME_FRE_TYPE_ADDR1)
+ {
+ uint8_t *uc = (uint8_t *)fre_buf;
+ saddr = (uint32_t)*uc;
+ }
+ else if (fre_type == SFRAME_FRE_TYPE_ADDR2)
+ {
+ uint16_t *ust = (uint16_t *)fre_buf;
+ saddr = (uint32_t)*ust;
+ }
+ else if (fre_type == SFRAME_FRE_TYPE_ADDR4)
+ {
+ uint32_t *uit = (uint32_t *)fre_buf;
+ saddr = (uint32_t)*uit;
+ }
+ else
+ return;
+
+ *fre_start_addr = saddr;
+}
+
+/* Find the function descriptor entry starting which contains the specified
+ address ADDR. */
+
+static sframe_func_desc_entry *
+sframe_get_funcdesc_with_addr_internal (sframe_decoder_ctx *ctx, int32_t addr,
+ int *errp, uint32_t *func_idx)
+{
+ sframe_header *dhp;
+ sframe_func_desc_entry *fdp;
+ int low, high;
+
+ if (ctx == NULL)
+ return NULL;
+
+ dhp = sframe_decoder_get_header (ctx);
+
+ if (dhp == NULL || dhp->sfh_num_fdes == 0 || ctx->sfd_funcdesc == NULL)
+ return NULL;
+ /* If the FDE sub-section is not sorted on PCs, skip the lookup because
+ binary search cannot be used. */
+ if ((dhp->sfh_preamble.sfp_flags & SFRAME_F_FDE_SORTED) == 0)
+ return NULL;
+
+ /* Do the binary search. */
+ fdp = (sframe_func_desc_entry *) ctx->sfd_funcdesc;
+ low = 0;
+ high = dhp->sfh_num_fdes - 1;
+ while (low <= high)
+ {
+ int mid = low + (high - low) / 2;
+
+ /* Given sfde_func_start_address <= addr,
+ addr - sfde_func_start_address must be positive. */
+ if (sframe_decoder_get_secrel_func_start_addr (ctx, mid) <= addr
+ && ((uint32_t)(addr - sframe_decoder_get_secrel_func_start_addr (ctx,
+ mid))
+ < fdp[mid].sfde_func_size))
+ {
+ *func_idx = mid;
+ return fdp + mid;
+ }
+
+ if (sframe_decoder_get_secrel_func_start_addr (ctx, mid) < addr)
+ low = mid + 1;
+ else
+ high = mid - 1;
+ }
+
+ return NULL;
+}
+
+/* Get the end IP offset for the FRE at index i in the FDEP. The buffer FRES
+ is the starting location for the FRE. */
+
+static uint32_t
+sframe_fre_get_end_ip_offset (sframe_func_desc_entry *fdep, unsigned int i,
+ const char *fres)
+{
+ uint32_t end_ip_offset = 0;
+ uint32_t fre_type;
+
+ fre_type = sframe_get_fre_type (fdep);
+
+ /* Get the start address of the next FRE in sequence. */
+ if (i < fdep->sfde_func_num_fres - 1)
+ {
+ sframe_decode_fre_start_address (fres, &end_ip_offset, fre_type);
+ end_ip_offset -= 1;
+ }
+ else
+ /* The end IP offset for the FRE needs to be deduced from the function
+ size. */
+ end_ip_offset = fdep->sfde_func_size - 1;
+
+ return end_ip_offset;
+}
+
+/* Get the SFrame's fixed FP offset given the decoder context CTX. */
+
+static int8_t
+sframe_decoder_get_fixed_fp_offset (sframe_decoder_ctx *ctx)
+{
+ sframe_header *dhp;
+ dhp = sframe_decoder_get_header (ctx);
+ return dhp->sfh_cfa_fixed_fp_offset;
+}
+
+/* Get the SFrame's fixed RA offset given the decoder context CTX. */
+
+static int8_t
+sframe_decoder_get_fixed_ra_offset (sframe_decoder_ctx *ctx)
+{
+ sframe_header *dhp;
+ dhp = sframe_decoder_get_header (ctx);
+ return dhp->sfh_cfa_fixed_ra_offset;
+}
+
+/* Get the base reg id from the FRE info. Set errp if failure. */
+
+uint8_t
+__sframe_fre_get_base_reg_id (sframe_frame_row_entry *fre)
+{
+ uint8_t fre_info = fre->fre_info;
+ return SFRAME_V1_FRE_CFA_BASE_REG_ID (fre_info);
+}
+
+/* Get the CFA offset from the FRE. If the offset is unavailable,
+ sets errp. */
+
+int32_t
+__sframe_fre_get_cfa_offset (sframe_decoder_ctx *dctx __attribute__ ((__unused__)),
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp)
+{
+ return sframe_get_fre_offset (fre, SFRAME_FRE_CFA_OFFSET_IDX, errp);
+}
+
+/* Get the FP offset from the FRE. If the offset is unavailable, sets
+ errp. */
+
+int32_t
+__sframe_fre_get_fp_offset (sframe_decoder_ctx *dctx,
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp)
+{
+ uint32_t fp_offset_idx = 0;
+ int8_t fp_offset = sframe_decoder_get_fixed_fp_offset (dctx);
+
+ *errp = _URC_NO_REASON;
+ /* If the FP offset is not being tracked, return the fixed FP offset
+ from the SFrame header. */
+ if (fp_offset != SFRAME_CFA_FIXED_FP_INVALID)
+ return fp_offset;
+
+ /* In some ABIs, the stack offset to recover RA (using the CFA) from is
+ fixed (like AMD64). In such cases, the stack offset to recover FP will
+ appear at the second index. */
+ fp_offset_idx = ((sframe_decoder_get_fixed_ra_offset (dctx)
+ != SFRAME_CFA_FIXED_RA_INVALID)
+ ? SFRAME_FRE_RA_OFFSET_IDX
+ : SFRAME_FRE_FP_OFFSET_IDX);
+ return sframe_get_fre_offset (fre, fp_offset_idx, errp);
+}
+
+/* Get the RA offset from the FRE. If the offset is unavailable, sets
+ errp. */
+
+int32_t
+__sframe_fre_get_ra_offset (sframe_decoder_ctx *dctx,
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp)
+{
+ int8_t ra_offset = sframe_decoder_get_fixed_ra_offset (dctx);
+ *errp = _URC_NO_REASON;
+
+ /* If the RA offset was not being tracked, return the fixed RA offset
+ from the SFrame header. */
+ if (ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
+ return ra_offset;
+
+ /* Otherwise, get the RA offset from the FRE. */
+ return sframe_get_fre_offset (fre, SFRAME_FRE_RA_OFFSET_IDX, errp);
+}
+
+/* Decode the specified SFrame buffer SF_BUF and return the new SFrame
+ decoder context. */
+
+_Unwind_Reason_Code
+__sframe_decode (sframe_decoder_ctx *dctx, const char *sf_buf)
+{
+ const sframe_preamble *sfp;
+ size_t hdrsz;
+ sframe_header *sfheaderp;
+ char *frame_buf;
+
+ int fidx_size;
+ uint32_t fre_bytes;
+
+ if (sf_buf == NULL)
+ return _URC_END_OF_STACK;
+
+ sfp = (const sframe_preamble *) sf_buf;
+
+ /* Check for foreign endianness. */
+ if (sfp->sfp_magic != SFRAME_MAGIC)
+ return _URC_END_OF_STACK;
+
+ frame_buf = (char *)sf_buf;
+
+ /* Handle the SFrame header. */
+ dctx->sfd_header = *(sframe_header *) frame_buf;
+
+ /* Validate the contents of SFrame header. */
+ sfheaderp = &dctx->sfd_header;
+ if (!sframe_header_sanity_check_p (sfheaderp))
+ return _URC_END_OF_STACK;
+
+ hdrsz = sframe_get_hdr_size (sfheaderp);
+ frame_buf += hdrsz;
+
+ /* Handle the SFrame Function Descriptor Entry section. */
+ fidx_size
+ = sfheaderp->sfh_num_fdes * sizeof (sframe_func_desc_entry);
+ dctx->sfd_funcdesc = (sframe_func_desc_entry *)frame_buf;
+ frame_buf += (fidx_size);
+
+ dctx->sfd_fres = frame_buf;
+ fre_bytes = sfheaderp->sfh_fre_len;
+ dctx->sfd_fre_nbytes = fre_bytes;
+
+ return _URC_NO_REASON;
+}
+
+/* Find the SFrame Row Entry which contains the PC. Returns
+ _URC_END_OF_STACK if failure. */
+
+_Unwind_Reason_Code
+__sframe_find_fre (sframe_decoder_ctx *ctx, int32_t pc,
+ sframe_frame_row_entry *frep)
+{
+ sframe_func_desc_entry *fdep;
+ uint32_t func_idx;
+ uint32_t fre_type, i;
+ uint32_t start_ip_offset;
+ int32_t func_start_addr;
+ uint32_t end_ip_offset;
+ const char *fres;
+ size_t size = 0;
+ int err = 0;
+
+ if ((ctx == NULL) || (frep == NULL))
+ return _URC_END_OF_STACK;
+
+ /* Find the FDE which contains the PC, then scan its fre entries. */
+ fdep = sframe_get_funcdesc_with_addr_internal (ctx, pc, &err, &func_idx);
+ if (fdep == NULL || ctx->sfd_fres == NULL)
+ return _URC_END_OF_STACK;
+
+ fre_type = sframe_get_fre_type (fdep);
+
+ fres = ctx->sfd_fres + fdep->sfde_func_start_fre_off;
+ func_start_addr = sframe_decoder_get_secrel_func_start_addr (ctx, func_idx);
+
+ for (i = 0; i < fdep->sfde_func_num_fres; i++)
+ {
+ size_t addr_size;
+
+ /* Partially decode the FRE. */
+ sframe_decode_fre_start_address (fres, &frep->fre_start_addr, fre_type);
+
+ addr_size = sframe_fre_start_addr_size (fre_type);
+ if (addr_size == 0)
+ return _URC_END_OF_STACK;
+
+ frep->fre_info = *(uint8_t *)(fres + addr_size);
+ size = sframe_fre_entry_size (frep, addr_size);
+
+ start_ip_offset = frep->fre_start_addr;
+ end_ip_offset = sframe_fre_get_end_ip_offset (fdep, i, fres + size);
+
+ /* Stop search if FRE's start_ip is greater than pc. Given
+ func_start_addr <= pc, pc - func_start_addr must be positive. */
+ if (start_ip_offset > (uint32_t) (pc - func_start_addr))
+ return _URC_END_OF_STACK;
+
+ if (sframe_fre_check_range_p (ctx, func_idx, start_ip_offset,
+ end_ip_offset, pc))
+ {
+ /* Decode last FRE bits: offsets size. */
+ frep->fre_offsets = fres + addr_size + sizeof (frep->fre_info);
+ return _URC_NO_REASON;
+ }
+
+ fres += size;
+ }
+ return _URC_END_OF_STACK;
+}
diff --git a/sysdeps/generic/sframe-read.h b/sysdeps/generic/sframe-read.h
new file mode 100644
index 0000000..1461421
--- /dev/null
+++ b/sysdeps/generic/sframe-read.h
@@ -0,0 +1,112 @@
+/* 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 General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _SFRAME_API_H
+#define _SFRAME_API_H
+
+#include <sframe.h>
+#include <stdbool.h>
+#include <unwind.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct sframe_decoder_ctx
+{
+
+ sframe_header sfd_header;
+
+ sframe_func_desc_entry *sfd_funcdesc;
+ /* SFrame FRE table. */
+ char *sfd_fres;
+ /* Number of bytes needed for SFrame FREs. */
+ int sfd_fre_nbytes;
+} sframe_decoder_ctx;
+
+#define MAX_NUM_STACK_OFFSETS 3
+
+/* User interfacing SFrame Row Entry.
+ An abstraction provided by libsframe so the consumer is decoupled from
+ the binary format representation of the same.
+
+ The members are best ordered such that they are aligned at their natural
+ boundaries. This helps avoid usage of undesirable misaligned memory
+ accesses. See PR libsframe/29856. */
+
+typedef struct sframe_frame_row_entry
+{
+ uint32_t fre_start_addr;
+ const char *fre_offsets;
+ unsigned char fre_info;
+} sframe_frame_row_entry;
+
+/* The SFrame Decoder. */
+
+/* Decode the specified SFrame buffer CF_BUF and return the new SFrame
+ decoder context. */
+
+extern _Unwind_Reason_Code
+__sframe_decode (sframe_decoder_ctx *dctx, const char *cf_buf);
+
+/* Find the SFrame Frame Row Entry which contains the PC. Returns
+ _URC_END_OF_STACK if failure. */
+
+extern _Unwind_Reason_Code
+__sframe_find_fre (sframe_decoder_ctx *ctx, int32_t pc,
+ sframe_frame_row_entry *frep);
+
+/* Get the base reg id from the FRE info. */
+
+extern uint8_t
+__sframe_fre_get_base_reg_id (sframe_frame_row_entry *fre);
+
+/* Get the CFA offset from the FRE. Sets ERRP if an error is
+ detected. */
+
+extern int32_t
+__sframe_fre_get_cfa_offset (sframe_decoder_ctx *dtcx,
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp);
+
+/* Get the FP offset from the FRE. If the offset is unavailable, sets
+ ERRP. */
+
+extern int32_t
+__sframe_fre_get_fp_offset (sframe_decoder_ctx *dctx,
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp);
+
+/* Get the RA offset from the FRE. Sets ERRP if ra offset is
+ unavailable. */
+
+extern int32_t
+__sframe_fre_get_ra_offset (sframe_decoder_ctx *dctx,
+ sframe_frame_row_entry *fre,
+ _Unwind_Reason_Code *errp);
+
+/* Get the offset of the sfde_func_start_address field. */
+
+extern uint32_t
+__sframe_decoder_get_offsetof_fde_start_addr (sframe_decoder_ctx *dctx,
+ uint32_t func_idx,
+ _Unwind_Reason_Code *errp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFRAME_API_H */
diff --git a/sysdeps/generic/sframe.c b/sysdeps/generic/sframe.c
new file mode 100644
index 0000000..ba0830d
--- /dev/null
+++ b/sysdeps/generic/sframe.c
@@ -0,0 +1,187 @@
+/* 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 General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <sframe-read.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <unwind.h>
+#include <uw-sigframe.h>
+#include <ldsodefs.h>
+
+/* Some arches like s390x needs an offset to correct the value where
+ SP is located in relation to CFA. */
+#ifndef SFRAME_SP_VAL_OFFSET
+#define SFRAME_SP_VAL_OFFSET 0
+#endif
+
+static inline _Unwind_Ptr
+read_stack_value (_Unwind_Ptr loc)
+{
+ _Unwind_Ptr value = *((_Unwind_Ptr *) loc);
+ return value;
+}
+
+/* Helper to avoid PLT call in libc. Fixes elf/check-localplt
+ errors. */
+
+static int
+_dl_find_object_helper (void *address, struct dl_find_object *result)
+{
+ return GLRO (dl_find_object) (address, result);
+}
+
+/* Backtrace the stack and collect the stacktrace given SFrame info.
+ If successful, store the return addresses in RA_LST. The SIZE
+ argument specifies the maximum number of return addresses that can
+ be stored in RA_LST and contains the number of the addresses
+ collected. */
+
+int
+__stacktrace_sframe (void **ra_lst, int count, frame *frame)
+{
+ _Unwind_Ptr sframe_vma, cfa, return_addr, ra_stack_loc, fp_stack_loc, pc,
+ frame_ptr;
+ int cfa_offset, fp_offset, ra_offset, i;
+ sframe_frame_row_entry fred, *frep = &fred;
+
+ if (!ra_lst || !count)
+ return 0;
+
+ for (i = 0; i < count; i++)
+ {
+ _Unwind_Reason_Code err;
+ struct dl_find_object data;
+ sframe_decoder_ctx decoder_context, *dctx = &decoder_context;
+
+ /* Clean decoder context. */
+ memset (dctx, 0, sizeof (sframe_decoder_ctx));
+
+ /* Load and set up the SFrame stack trace info for pc. */
+ if (_dl_find_object_helper ((void *) frame->pc, &data) < 0)
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+
+ sframe_vma = (_Unwind_Ptr) data.dlfo_sframe;
+ if (!sframe_vma || !(data.dlfo_flags & DLFO_FLAG_SFRAME))
+ {
+#ifdef MD_DECODE_SIGNAL_FRAME
+ /* If there is no valid SFrame section or SFrame section is
+ corrupted then check if it is a signal frame. */
+ if (MD_DECODE_SIGNAL_FRAME (frame) == _URC_NO_REASON)
+ {
+ ra_lst[i] = (void *) frame->pc;
+ continue;
+ }
+#endif
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+ }
+
+ /* Decode the specified SFrame buffer populate sframe's decoder
+ context. */
+ if (__sframe_decode (dctx, (char *) data.dlfo_sframe) != _URC_NO_REASON)
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+
+ pc = frame->pc - sframe_vma;
+ /* Find the SFrame Row Entry which contains the PC. */
+ if (__sframe_find_fre (dctx, pc, frep) == _URC_END_OF_STACK)
+ {
+#ifdef MD_DECODE_SIGNAL_FRAME
+ /* If there are no valid FREs, check if it is a signal
+ frame, and if so decode it. */
+ if (MD_DECODE_SIGNAL_FRAME (frame) == _URC_NO_REASON)
+ {
+ ra_lst[i] = (void *) frame->pc;
+ continue;
+ }
+#endif
+#ifdef MD_DETECT_OUTERMOST_FRAME
+ if (MD_DETECT_OUTERMOST_FRAME (frame) == _URC_END_OF_STACK)
+ return i;
+#endif
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+ }
+
+ /* Get the CFA offset from the FRE. If offset is unavailable,
+ sets err. */
+ cfa_offset = __sframe_fre_get_cfa_offset (dctx, frep, &err);
+ if (err != _URC_NO_REASON)
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+
+ /* Get CFA using base reg id from the FRE info. */
+ cfa = ((__sframe_fre_get_base_reg_id (frep)
+ == SFRAME_BASE_REG_SP) ? frame->sp : frame->fp) + cfa_offset;
+
+ /* Get the RA offset from the FRE. If the offset is
+ unavailable, sets err. */
+ ra_offset = __sframe_fre_get_ra_offset (dctx, frep, &err);
+ if (err != _URC_NO_REASON)
+ /* Force fallback to DWARF stacktracer. */
+ return 0;
+
+ /* RA offset is available, get the value stored in the stack
+ location. */
+ ra_stack_loc = cfa + ra_offset;
+ return_addr = read_stack_value (ra_stack_loc);
+
+ ra_lst[i] = (void *) return_addr;
+
+ /* Get the FP offset from the FRE. If the offset is
+ unavailable, sets err. */
+ fp_offset = __sframe_fre_get_fp_offset (dctx, frep, &err);
+ frame_ptr = frame->fp;
+ if (err == _URC_NO_REASON)
+ {
+ /* FP offset is available, get the value stored in the stack
+ location. */
+ fp_stack_loc = cfa + fp_offset;
+ frame_ptr = read_stack_value (fp_stack_loc);
+ }
+
+ /* Set up for the next frame. */
+ frame->fp = frame_ptr;
+ frame->sp = cfa + SFRAME_SP_VAL_OFFSET;
+ frame->pc = return_addr;
+ }
+ return i;
+}
+
+libc_hidden_def (__stacktrace_sframe);
+
+/* A noinline helper used to obtain the caller's current PC. */
+
+_Unwind_Ptr __attribute__ ((noinline))
+__getPC (void)
+{
+ return (_Unwind_Ptr)
+ __builtin_extract_return_addr (__builtin_return_address (0));
+}
+
+libc_hidden_def (__getPC);
+
+/* A noinline helper used to obtain the caller's current SP. It
+ mimics gcc14's __builtin_stack_address() functionality. */
+
+_Unwind_Ptr __attribute__ ((noinline))
+__getSP (void)
+{
+ return (_Unwind_Ptr) __builtin_dwarf_cfa() + SFRAME_SP_VAL_OFFSET;
+}
+
+libc_hidden_def (__getSP);
diff --git a/sysdeps/generic/sframe.h b/sysdeps/generic/sframe.h
new file mode 100644
index 0000000..e38adcf
--- /dev/null
+++ b/sysdeps/generic/sframe.h
@@ -0,0 +1,378 @@
+/* SFrame format description.
+ Copyright (C) 2022-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 General Public License
+ along with this program; see the file COPYING. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SFRAME_H
+#define _SFRAME_H
+
+#include <sys/types.h>
+#include <limits.h>
+#include <stdint.h>
+#include <unwind.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* SFrame format.
+
+ SFrame format is a simple format to represent the information needed
+ for generating vanilla backtraces. SFrame format keeps track of the
+ minimal necessary information needed for stack tracing:
+ - Canonical Frame Address (CFA)
+ - Frame Pointer (FP)
+ - Return Address (RA)
+
+ The SFrame section itself has the following structure:
+
+ +--------+------------+---------+
+ | file | function | frame |
+ | header | descriptor | row |
+ | | entries | entries |
+ +--------+------------+---------+
+
+ The file header stores a magic number and version information, flags, and
+ the byte offset of each of the sections relative to the end of the header
+ itself. The file header also specifies the total number of Function
+ Descriptor Entries, Frame Row Entries and length of the FRE sub-section.
+
+ Following the header is a list of Function Descriptor Entries (FDEs).
+ This list may be sorted if the flags in the file header indicate it to be
+ so. The sort order, if applicable, is the order of functions in the
+ .text.* sections in the resulting binary artifact. Each Function
+ Descriptor Entry specifies the start PC of a function, the size in bytes
+ of the function and an offset to its first Frame Row Entry (FRE). Each FDE
+ additionally also specifies the type of FRE it uses to encode the stack
+ trace information.
+
+ Next, the SFrame Frame Row Entry sub-section is a list of variable size
+ records. Each entry represents stack trace information for a set of PCs
+ of the function. A singular Frame Row Entry is a self-sufficient record
+ which contains information on how to generate stack trace from the
+ applicable set of PCs.
+
+ */
+
+
+/* SFrame format versions. */
+#define SFRAME_VERSION_1 1
+#define SFRAME_VERSION_2 2
+/* SFrame magic number. */
+#define SFRAME_MAGIC 0xdee2
+/* Current version of SFrame format. */
+#define SFRAME_VERSION SFRAME_VERSION_2
+
+/* Various flags for SFrame. */
+
+/* Function Descriptor Entries are sorted on PC. */
+#define SFRAME_F_FDE_SORTED 0x1
+/* Functions preserve frame pointer. */
+#define SFRAME_F_FRAME_POINTER 0x2
+/* Function start address in SFrame FDE is encoded as the distance from the
+ location of the sfde_func_start_address to the start PC of the function.
+ If absent, the function start address in SFrame FDE is encoded as the
+ distance from the start of the SFrame FDE section to the start PC of the
+ function. */
+#define SFRAME_F_FDE_FUNC_START_PCREL 0x4
+
+/* Set of all defined flags in SFrame V2. */
+#define SFRAME_V2_F_ALL_FLAGS \
+ (SFRAME_F_FDE_SORTED | SFRAME_F_FRAME_POINTER \
+ | SFRAME_F_FDE_FUNC_START_PCREL)
+
+#define SFRAME_CFA_FIXED_FP_INVALID 0
+#define SFRAME_CFA_FIXED_RA_INVALID 0
+
+/* Supported ABIs/Arch. */
+#define SFRAME_ABI_AARCH64_ENDIAN_BIG 1 /* AARCH64 big endian. */
+#define SFRAME_ABI_AARCH64_ENDIAN_LITTLE 2 /* AARCH64 little endian. */
+#define SFRAME_ABI_AMD64_ENDIAN_LITTLE 3 /* AMD64 little endian. */
+
+/* SFrame FRE types. */
+#define SFRAME_FRE_TYPE_ADDR1 0
+#define SFRAME_FRE_TYPE_ADDR2 1
+#define SFRAME_FRE_TYPE_ADDR4 2
+
+/* SFrame Function Descriptor Entry types.
+
+ The SFrame format has two possible representations for functions. The
+ choice of which type to use is made according to the instruction patterns
+ in the relevant program stub.
+
+ An SFrame FDE of type SFRAME_FDE_TYPE_PCINC is an indication
+ that the PCs in the FREs should be treated as increments in bytes. This is
+ used for a bulk of the executable code of a program, which contains
+ instructions with no specific pattern.
+
+ An SFrame FDE of type SFRAME_FDE_TYPE_PCMASK is an indication
+ that the PCs in the FREs should be treated as masks. This type is useful
+ for the cases when a small pattern of instructions in a program stub is
+ repeatedly to cover a specific functionality. Typical usescases are pltN
+ entries, trampolines etc. */
+
+/* Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE. */
+#define SFRAME_FDE_TYPE_PCINC 0
+/* Unwinders perform a (PC % REP_BLOCK_SIZE >= FRE_START_ADDR) to look up a
+ matching FRE. */
+#define SFRAME_FDE_TYPE_PCMASK 1
+
+typedef struct sframe_preamble
+{
+ uint16_t sfp_magic; /* Magic number (SFRAME_MAGIC). */
+ uint8_t sfp_version; /* Data format version number (SFRAME_VERSION). */
+ uint8_t sfp_flags; /* Flags. */
+} __attribute__ ((packed)) sframe_preamble;
+
+typedef struct sframe_header
+{
+ sframe_preamble sfh_preamble;
+ /* Information about the arch (endianness) and ABI. */
+ uint8_t sfh_abi_arch;
+ /* Offset for the Frame Pointer (FP) from CFA may be fixed for some
+ ABIs (e.g, in AMD64 when -fno-omit-frame-pointer is used). When fixed,
+ this field specifies the fixed stack frame offset and the individual
+ FREs do not need to track it. When not fixed, it is set to
+ SFRAME_CFA_FIXED_FP_INVALID, and the individual FREs may provide
+ the applicable stack frame offset, if any. */
+ int8_t sfh_cfa_fixed_fp_offset;
+ /* Offset for the Return Address from CFA is fixed for some ABIs
+ (e.g., AMD64 has it as CFA-8). When fixed, the header specifies the
+ fixed stack frame offset and the individual FREs do not track it. When
+ not fixed, it is set to SFRAME_CFA_FIXED_RA_INVALID, and individual
+ FREs provide the applicable stack frame offset, if any. */
+ int8_t sfh_cfa_fixed_ra_offset;
+ /* Number of bytes making up the auxiliary header, if any.
+ Some ABI/arch, in the future, may use this space for extending the
+ information in SFrame header. Auxiliary header is contained in
+ bytes sequentially following the sframe_header. */
+ uint8_t sfh_auxhdr_len;
+ /* Number of SFrame FDEs in this SFrame section. */
+ uint32_t sfh_num_fdes;
+ /* Number of SFrame Frame Row Entries. */
+ uint32_t sfh_num_fres;
+ /* Number of bytes in the SFrame Frame Row Entry section. */
+ uint32_t sfh_fre_len;
+ /* Offset of SFrame Function Descriptor Entry section. */
+ uint32_t sfh_fdeoff;
+ /* Offset of SFrame Frame Row Entry section. */
+ uint32_t sfh_freoff;
+} __attribute__ ((packed)) sframe_header;
+
+#define SFRAME_V1_HDR_SIZE(sframe_hdr) \
+ ((sizeof (sframe_header) + (sframe_hdr).sfh_auxhdr_len))
+
+/* Two possible keys for executable (instruction) pointers signing. */
+#define SFRAME_AARCH64_PAUTH_KEY_A 0 /* Key A. */
+#define SFRAME_AARCH64_PAUTH_KEY_B 1 /* Key B. */
+
+typedef struct sframe_func_desc_entry
+{
+ /* Function start address. Encoded as a signed offset, relative to the
+ beginning of the current FDE. */
+ int32_t sfde_func_start_address;
+ /* Size of the function in bytes. */
+ uint32_t sfde_func_size;
+ /* Offset of the first SFrame Frame Row Entry of the function, relative to the
+ beginning of the SFrame Frame Row Entry sub-section. */
+ uint32_t sfde_func_start_fre_off;
+ /* Number of frame row entries for the function. */
+ uint32_t sfde_func_num_fres;
+ /* Additional information for stack tracing from the function:
+ - 4-bits: Identify the FRE type used for the function.
+ - 1-bit: Identify the FDE type of the function - mask or inc.
+ - 1-bit: PAC authorization A/B key (aarch64).
+ - 2-bits: Unused.
+ ------------------------------------------------------------------------
+ | Unused | PAC auth A/B key (aarch64) | FDE type | FRE type |
+ | | Unused (amd64) | | |
+ ------------------------------------------------------------------------
+ 8 6 5 4 0 */
+ uint8_t sfde_func_info;
+ /* Size of the block of repeating insns. Used for SFrame FDEs of type
+ SFRAME_FDE_TYPE_PCMASK. */
+ uint8_t sfde_func_rep_size;
+ uint16_t sfde_func_padding2;
+} __attribute__ ((packed)) sframe_func_desc_entry;
+
+/* Macros to compose and decompose function info in FDE. */
+
+/* Note: Set PAC auth key to SFRAME_AARCH64_PAUTH_KEY_A by default. */
+#define SFRAME_V1_FUNC_INFO(fde_type, fre_enc_type) \
+ (((SFRAME_AARCH64_PAUTH_KEY_A & 0x1) << 5) | \
+ (((fde_type) & 0x1) << 4) | ((fre_enc_type) & 0xf))
+
+#define SFRAME_V1_FUNC_FRE_TYPE(data) ((data) & 0xf)
+#define SFRAME_V1_FUNC_FDE_TYPE(data) (((data) >> 4) & 0x1)
+#define SFRAME_V1_FUNC_PAUTH_KEY(data) (((data) >> 5) & 0x1)
+
+/* Set the pauth key as indicated. */
+#define SFRAME_V1_FUNC_INFO_UPDATE_PAUTH_KEY(pauth_key, fde_info) \
+ ((((pauth_key) & 0x1) << 5) | ((fde_info) & 0xdf))
+
+/* Size of stack frame offsets in an SFrame Frame Row Entry. A single
+ SFrame FRE has all offsets of the same size. Offset size may vary
+ across frame row entries. */
+#define SFRAME_FRE_OFFSET_1B 0
+#define SFRAME_FRE_OFFSET_2B 1
+#define SFRAME_FRE_OFFSET_4B 2
+
+/* An SFrame Frame Row Entry can be SP or FP based. */
+#define SFRAME_BASE_REG_FP 0
+#define SFRAME_BASE_REG_SP 1
+
+/* The index at which a specific offset is presented in the variable length
+ bytes of an FRE. */
+#define SFRAME_FRE_CFA_OFFSET_IDX 0
+/* The RA stack offset, if present, will always be at index 1 in the variable
+ length bytes of the FRE. */
+#define SFRAME_FRE_RA_OFFSET_IDX 1
+/* The FP stack offset may appear at offset 1 or 2, depending on the ABI as RA
+ may or may not be tracked. */
+#define SFRAME_FRE_FP_OFFSET_IDX 2
+
+typedef struct sframe_fre_info
+{
+ /* Information about
+ - 1 bit: base reg for CFA
+ - 4 bits: Number of offsets (N). A value of upto 3 is allowed to track
+ all three of CFA, FP and RA (fixed implicit order).
+ - 2 bits: information about size of the offsets (S) in bytes.
+ Valid values are SFRAME_FRE_OFFSET_1B, SFRAME_FRE_OFFSET_2B,
+ SFRAME_FRE_OFFSET_4B
+ - 1 bit: Mangled RA state bit (aarch64 only).
+ ----------------------------------------------------------------------------------
+ | Mangled-RA (aarch64) | Size of offsets | Number of offsets | base_reg |
+ | Unused (amd64) | | | |
+ ----------------------------------------------------------------------------------
+ 8 7 5 1 0
+
+ */
+ uint8_t fre_info;
+} sframe_fre_info;
+
+/* Macros to compose and decompose FRE info. */
+
+/* Note: Set mangled_ra_p to zero by default. */
+#define SFRAME_V1_FRE_INFO(base_reg_id, offset_num, offset_size) \
+ (((0 & 0x1) << 7) | (((offset_size) & 0x3) << 5) | \
+ (((offset_num) & 0xf) << 1) | ((base_reg_id) & 0x1))
+
+/* Set the mangled_ra_p bit as indicated. */
+#define SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P(mangled_ra_p, fre_info) \
+ ((((mangled_ra_p) & 0x1) << 7) | ((fre_info) & 0x7f))
+
+#define SFRAME_V1_FRE_CFA_BASE_REG_ID(data) ((data) & 0x1)
+#define SFRAME_V1_FRE_OFFSET_COUNT(data) (((data) >> 1) & 0xf)
+#define SFRAME_V1_FRE_OFFSET_SIZE(data) (((data) >> 5) & 0x3)
+#define SFRAME_V1_FRE_MANGLED_RA_P(data) (((data) >> 7) & 0x1)
+
+/* SFrame Frame Row Entry definitions.
+
+ Used for both AMD64 and AARCH64.
+
+ An SFrame Frame Row Entry is a self-sufficient record which contains
+ information on how to generate the stack trace for the specified range of
+ PCs. Each SFrame Frame Row Entry is followed by S*N bytes, where:
+ S is the size of the stack frame offset for the FRE, and
+ N is the number of stack frame offsets in the FRE
+
+ The interpretation of FRE stack offsets is ABI-specific:
+
+ AMD64:
+ offset1 (interpreted as CFA = BASE_REG + offset1)
+ if FP is being tracked
+ offset2 (intrepreted as FP = CFA + offset2)
+ fi
+
+ AARCH64:
+ offset1 (interpreted as CFA = BASE_REG + offset1)
+ if FP is being tracked (in other words, if frame record created)
+ offset2 (interpreted as RA = CFA + offset2)
+ offset3 (intrepreted as FP = CFA + offset3)
+ fi
+ Note that in AAPCS64, a frame record, if created, will save both FP and
+ LR on stack.
+*/
+
+/* Used when SFRAME_FRE_TYPE_ADDR1 is specified as FRE type. */
+typedef struct sframe_frame_row_entry_addr1
+{
+ /* Start address of the frame row entry. Encoded as an 1-byte unsigned
+ offset, relative to the start address of the function. */
+ uint8_t sfre_start_address;
+ sframe_fre_info sfre_info;
+} __attribute__ ((packed)) sframe_frame_row_entry_addr1;
+
+/* Upper limit of start address in sframe_frame_row_entry_addr1
+ is 0x100 (not inclusive). */
+#define SFRAME_FRE_TYPE_ADDR1_LIMIT \
+ (1ULL << ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8))
+
+/* Used when SFRAME_FRE_TYPE_ADDR2 is specified as FRE type. */
+typedef struct sframe_frame_row_entry_addr2
+{
+ /* Start address of the frame row entry. Encoded as an 2-byte unsigned
+ offset, relative to the start address of the function. */
+ uint16_t sfre_start_address;
+ sframe_fre_info sfre_info;
+} __attribute__ ((packed)) sframe_frame_row_entry_addr2;
+
+/* Upper limit of start address in sframe_frame_row_entry_addr2
+ is 0x10000 (not inclusive). */
+#define SFRAME_FRE_TYPE_ADDR2_LIMIT \
+ (1ULL << ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8))
+
+/* Used when SFRAME_FRE_TYPE_ADDR4 is specified as FRE type. */
+typedef struct sframe_frame_row_entry_addr4
+{
+ /* Start address of the frame row entry. Encoded as a 4-byte unsigned
+ offset, relative to the start address of the function. */
+ uint32_t sfre_start_address;
+ sframe_fre_info sfre_info;
+} __attribute__ ((packed)) sframe_frame_row_entry_addr4;
+
+/* Upper limit of start address in sframe_frame_row_entry_addr2
+ is 0x100000000 (not inclusive). */
+#define SFRAME_FRE_TYPE_ADDR4_LIMIT \
+ (1ULL << ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8))
+
+/* Used to pass frame information to stack trace routine. */
+typedef struct cframe
+{
+ _Unwind_Ptr pc;
+ _Unwind_Ptr sp;
+ _Unwind_Ptr fp;
+} frame;
+
+/* SFrame stack tracing support. */
+int __stacktrace_sframe (void **, int, frame *);
+libc_hidden_proto (__stacktrace_sframe);
+
+/* Helper used by SFrame tracing algorithm. */
+_Unwind_Ptr __getPC (void);
+libc_hidden_proto (__getPC);
+
+/* Helper used by SFrame tracing algorithm. */
+_Unwind_Ptr __getSP (void);
+libc_hidden_proto (__getSP);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFRAME_H */
diff --git a/sysdeps/generic/uw-sigframe.h b/sysdeps/generic/uw-sigframe.h
new file mode 100644
index 0000000..b357f8a
--- /dev/null
+++ b/sysdeps/generic/uw-sigframe.h
@@ -0,0 +1,31 @@
+/* Internal header file for handling signal frames. Generic version.
+ 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/>. */
+
+/* Each architecture that supports SFrame may need to define several
+ macros to handle exceptional cases during stack backtracing.
+
+ MD_DECODE_SIGNAL_FRAME(frame) should recover frame information when
+ a signal-related exception occurs. The input frame must contain a
+ valid program counter (PC) field. On success, the macro should
+ return _URC_NO_REASON.
+
+ MD_DETECT_OUTERMOST_FRAME(frame) is used to detect the outermost
+ stack frame. It returns _URC_NO_REASON upon successful
+ detection.
+
+ The FRAME structure is defined in sysdeps/generic/sframe.h */
diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index ee6470d..74068ea 100644
--- a/sysdeps/i386/Makefile
+++ b/sysdeps/i386/Makefile
@@ -17,19 +17,22 @@ ifeq ($(subdir),gmon)
sysdep_routines += i386-mcount
endif
-ifeq ($(subdir),elf)
-CFLAGS-rtld.c += -Wno-uninitialized -Wno-unused
-CFLAGS-dl-load.c += -Wno-unused
-CFLAGS-dl-reloc.c += -Wno-unused
-endif
-
ifeq ($(subdir),csu)
gen-as-const-headers += link-defines.sym
+gen-as-const-headers += tlsdesc.sym
else
stack-align-test-flags += -malign-double
endif
+# Make sure no code in ld.so uses mm/xmm/ymm/zmm registers on i386 since
+# the first 3 mm/xmm/ymm/zmm registers are used to pass vector parameters
+# which must be preserved.
+# With SSE disabled, ensure -fpmath is not set to use sse either.
+rtld-CFLAGS += -mno-sse -mno-mmx -mfpmath=387
ifeq ($(subdir),elf)
+CFLAGS-rtld.c += -Wno-uninitialized -Wno-unused
+CFLAGS-dl-load.c += -Wno-unused
+CFLAGS-dl-reloc.c += -Wno-unused
sysdep-dl-routines += \
dl-tls-get-addr \
# sysdep-dl-routines
@@ -40,18 +43,6 @@ modules-names += tst-auditmod3a tst-auditmod3b
$(objpfx)tst-audit3: $(objpfx)tst-auditmod3a.so
$(objpfx)tst-audit3.out: $(objpfx)tst-auditmod3b.so
tst-audit3-ENV = LD_AUDIT=$(objpfx)tst-auditmod3b.so
-endif
-
-ifeq ($(subdir),csu)
-gen-as-const-headers += tlsdesc.sym
-endif
-
-# Make sure no code in ld.so uses mm/xmm/ymm/zmm registers on i386 since
-# the first 3 mm/xmm/ymm/zmm registers are used to pass vector parameters
-# which must be preserved.
-# With SSE disabled, ensure -fpmath is not set to use sse either.
-rtld-CFLAGS += -mno-sse -mno-mmx -mfpmath=387
-ifeq ($(subdir),elf)
CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\
$(rtld-CFLAGS))
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index de146dd..7572f62 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -62,7 +62,6 @@ tests += \
tst-abstime \
tst-atfork1 \
tst-attr1 \
- tst-backtrace1 \
tst-bad-schedattr \
tst-barrier1 \
tst-barrier2 \
diff --git a/sysdeps/pthread/tst-backtrace1.c b/sysdeps/pthread/tst-backtrace1.c
deleted file mode 100644
index 01b8a0c..0000000
--- a/sysdeps/pthread/tst-backtrace1.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* Copyright (C) 2004-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/>. */
-
-#include <execinfo.h>
-#include <pthread.h>
-#include <stdio.h>
-
-#define BT_SIZE 64
-void *bt_array[BT_SIZE];
-int bt_cnt;
-
-int
-do_bt (void)
-{
- bt_cnt = backtrace (bt_array, BT_SIZE);
- return 56;
-}
-
-int
-call_do_bt (void)
-{
- return do_bt () + 1;
-}
-
-void *
-tf (void *arg)
-{
- if (call_do_bt () != 57)
- return (void *) 1L;
- return NULL;
-}
-
-int
-do_test (void)
-{
- pthread_t th;
- if (pthread_create (&th, NULL, tf, NULL))
- {
- puts ("create failed");
- return 1;
- }
-
- void *res;
- if (pthread_join (th, &res))
- {
- puts ("join failed");
- return 1;
- }
-
- if (res != NULL)
- {
- puts ("thread failed");
- return 1;
- }
-
- char **text = backtrace_symbols (bt_array, bt_cnt);
- if (text == NULL)
- {
- puts ("backtrace_symbols failed");
- return 1;
- }
-
- for (int i = 0; i < bt_cnt; ++i)
- puts (text[i]);
-
- return 0;
-}
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
diff --git a/sysdeps/pthread/tst-cond23.c b/sysdeps/pthread/tst-cond23.c
index 0a68472..a338397 100644
--- a/sysdeps/pthread/tst-cond23.c
+++ b/sysdeps/pthread/tst-cond23.c
@@ -151,7 +151,7 @@ do_test (void)
#if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
- return 0;
+ return EXIT_UNSUPPORTED;
#else
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 0aec783..c47cbdf 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -425,8 +425,6 @@ sysdep_headers += \
bits/termios-tcflow.h \
# sysdep_headers
-gen-as-const-headers += termios-kernel-consts.sym
-
tests += \
tst-termios-linux \
# tests
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 0000000..9d5d345
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h
@@ -0,0 +1,78 @@
+/* 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>
+
+#ifdef __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;
+ mcontext_t *mt;
+ struct kernel_rt_sigframe *rt_;
+
+ if ((frame->pc & 3) != 0)
+ return _URC_END_OF_STACK;
+
+ /* A signal frame will have a return address pointing to
+ __kernel_rt_sigreturn. 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 kernel_rt_sigframe *) frame->sp;
+ mt = &rt_->uc.uc_mcontext;
+
+ /* Frame pointer register number. */
+#define FP_REGNUM 30
+
+ frame->pc = (_Unwind_Ptr) mt->pc;
+ frame->sp = (_Unwind_Ptr) mt->sp;
+ frame->fp = (_Unwind_Ptr) mt->regs[FP_REGNUM];
+ return _URC_NO_REASON;
+}
+
+#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;
+}
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h b/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
new file mode 100644
index 0000000..77dc0c1
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996-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 _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Oh well, this is necessary since the kernel data structure is
+ different from the user-level version. */
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('t', 19, char[44])
+#define TCSETS _IOW ('t', 20, char[44])
+#define TCSETSW _IOW ('t', 21, char[44])
+#define TCSETSF _IOW ('t', 22, char[44])
+
+#include <linux/sockios.h>
diff --git a/sysdeps/unix/sysv/linux/alpha/termios_arch.h b/sysdeps/unix/sysv/linux/alpha/termios_arch.h
new file mode 100644
index 0000000..20025f2
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/termios_arch.h
@@ -0,0 +1,26 @@
+/* Architectural parameters for Linux termios - Alpha/PowerPC version
+
+ Copyright (C) 1997-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 TERMIOS_INTERNALS_H
+# error "<termios_arch.h> should only be included from <termios_internals.h>"
+#endif
+
+#define _TERMIOS2_NCCS 19
+#define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 1
+#define _HAVE_STRUCT_OLD_TERMIOS 0
diff --git a/sysdeps/unix/sysv/linux/bits/ioctls.h b/sysdeps/unix/sysv/linux/bits/ioctls.h
index f340a4f..1ddcd4f 100644
--- a/sysdeps/unix/sysv/linux/bits/ioctls.h
+++ b/sysdeps/unix/sysv/linux/bits/ioctls.h
@@ -22,18 +22,4 @@
/* Use the definitions from the kernel header files. */
#include <asm/ioctls.h>
-/* The GNU C library has a different definition of struct termios,
- incompatible with what the ioctl interface expects. The existence
- of the termios2 ioctls is considered an implementation detail.
- Undefine all related ioctl constants. */
-#undef TCGETS
-#undef TCSETS
-#undef TCSETSF
-#undef TCSETSW
-#undef TCGETS2
-#undef TCSETS2
-#undef TCSETSF2
-#undef TCSETSW2
-
-
#include <linux/sockios.h>
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h b/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h
new file mode 100644
index 0000000..6563be8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996-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 _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Oh well, this is necessary since the kernel data structure is
+ different from the user-level version. */
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('T', 16, char[36])
+#define TCSETS _IOW ('T', 17, char[36])
+#define TCSETSW _IOW ('T', 18, char[36])
+#define TCSETSF _IOW ('T', 19, char[36])
+
+#include <linux/sockios.h>
diff --git a/sysdeps/unix/sysv/linux/isatty.c b/sysdeps/unix/sysv/linux/isatty.c
index e7e98f8..3faaec5 100644
--- a/sysdeps/unix/sysv/linux/isatty.c
+++ b/sysdeps/unix/sysv/linux/isatty.c
@@ -24,6 +24,6 @@ int
__isatty (int fd)
{
struct termios2 k_termios;
- return INLINE_SYSCALL_CALL (ioctl, fd, ARCH_TCGETS, &k_termios) == 0;
+ return INLINE_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios) == 0;
}
weak_alias (__isatty, isatty)
diff --git a/sysdeps/unix/sysv/linux/isatty_nostatus.c b/sysdeps/unix/sysv/linux/isatty_nostatus.c
index 9970442..406decb 100644
--- a/sysdeps/unix/sysv/linux/isatty_nostatus.c
+++ b/sysdeps/unix/sysv/linux/isatty_nostatus.c
@@ -22,5 +22,5 @@ int
__isatty_nostatus (int fd)
{
struct termios2 k_termios;
- return INTERNAL_SYSCALL_CALL (ioctl, fd, ARCH_TCGETS, &k_termios) == 0;
+ return INTERNAL_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios) == 0;
}
diff --git a/sysdeps/unix/sysv/linux/mips/old_termios.h b/sysdeps/unix/sysv/linux/mips/termios_arch.h
index 8164742..392d9aa 100644
--- a/sysdeps/unix/sysv/linux/mips/old_termios.h
+++ b/sysdeps/unix/sysv/linux/mips/termios_arch.h
@@ -1,6 +1,6 @@
-/* old_termios.h for MIPS.
+/* Architectural parameters for Linux termios - MIPS version
- Copyright (C) 2025 Free Software Foundation, Inc.
+ Copyright (C) 1991-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
@@ -17,15 +17,18 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#define _TERMIOS2_NCCS 23
+#define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
+
#define _HAVE_STRUCT_OLD_TERMIOS 1
#define OLD_NCCS 32
-typedef struct old_termios
+struct old_termios
{
- tcflag_t c_iflag; /* input mode flags */
- tcflag_t c_oflag; /* output mode flags */
- tcflag_t c_cflag; /* control mode flags */
- tcflag_t c_lflag; /* local mode flags */
- cc_t c_line; /* line discipline */
- cc_t c_cc[OLD_NCCS]; /* control characters */
-} old_termios_t;
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[OLD_NCCS]; /* control characters */
+};
diff --git a/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h b/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
index 94cfd71..6c21357 100644
--- a/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
+++ b/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
@@ -1,4 +1,4 @@
-/* Linux internal definitions for ioctl. powerpc version.
+/* Linux internal definitions for ioctl.
Copyright (C) 2021-2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -17,40 +17,27 @@
<https://www.gnu.org/licenses/>. */
#include <termios.h>
-#include <termios_internals.h>
-#include <assert.h>
-
-/* PowerPC quirk: on PowerPC only, ioctl() emulates the TCGETS/TCSETS*
- ioctls with tcgetattr/tcsetattr using the glibc struct termios.
- As struct termios2 is the same as the kernel struct termios on PowerPC,
- simply consider the kernel ones as the termios2 interface, even
- though the kernel doesn't call it that. */
-
-#define GLIBC_TCGETS _IOR ('t', 19, struct termios)
-#define GLIBC_TCSETS _IOW ('t', 20, struct termios)
-#define GLIBC_TCSETSW _IOW ('t', 21, struct termios)
-#define GLIBC_TCSETSF _IOW ('t', 22, struct termios)
+/* The user-visible size of struct termios has changed. Catch ioctl calls
+ using the new-style struct termios, and translate them to old-style. */
static inline bool
__ioctl_arch (int *r, int fd, unsigned long request, void *arg)
{
- static_assert (GLIBC_TCGETS != KERNEL_TCGETS2,
- "emulation not possible due to matching ioctl constants");
switch (request)
{
- case GLIBC_TCGETS:
+ case TCGETS:
*r = __tcgetattr (fd, (struct termios *) arg);
break;
- case GLIBC_TCSETS:
+ case TCSETS:
*r = __tcsetattr (fd, TCSANOW, (struct termios *) arg);
break;
- case GLIBC_TCSETSW:
+ case TCSETSW:
*r = __tcsetattr (fd, TCSADRAIN, (struct termios *) arg);
break;
- case GLIBC_TCSETSF:
+ case TCSETSF:
*r = __tcsetattr (fd, TCSAFLUSH, (struct termios *) arg);
break;
diff --git a/sysdeps/unix/sysv/linux/powerpc/termios_arch.h b/sysdeps/unix/sysv/linux/powerpc/termios_arch.h
new file mode 100644
index 0000000..919b437
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/termios_arch.h
@@ -0,0 +1,33 @@
+/* Architectural parameters for Linux termios - PowerPC version
+
+ Copyright (C) 1997-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/>. */
+
+#define _TERMIOS2_NCCS 19
+#define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 1
+#define _HAVE_STRUCT_OLD_TERMIOS 0
+
+/* PowerPC quirk: on PowerPC only, ioctl() emulates the TCGETS/TCSETS*
+ ioctls with tcgetattr/tcsetattr using the glibc struct termios.
+ As struct termios2 is the same as the kernel struct termios on PowerPC,
+ simply consider the kernel ones as the termios2 interface, even
+ though the kernel doesn't call it that. */
+
+#define TCGETS2 _IOR ('t', 19, struct termios2)
+#define TCSETS2 _IOW ('t', 20, struct termios2)
+#define TCSETSW2 _IOW ('t', 21, struct termios2)
+#define TCSETSF2 _IOW ('t', 22, struct termios2)
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h b/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
new file mode 100644
index 0000000..1a95466
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996-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 _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Oh well, this is necessary since the kernel data structure is
+ different from the user-level version. */
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('T', 8, char[36])
+#define TCSETS _IOW ('T', 9, char[36])
+#define TCSETSW _IOW ('T', 10, char[36])
+#define TCSETSF _IOW ('T', 11, char[36])
+
+#include <linux/sockios.h>
diff --git a/sysdeps/unix/sysv/linux/sparc/old_termios.h b/sysdeps/unix/sysv/linux/sparc/termios_arch.h
index d7af589..f3b3f65 100644
--- a/sysdeps/unix/sysv/linux/sparc/old_termios.h
+++ b/sysdeps/unix/sysv/linux/sparc/termios_arch.h
@@ -1,6 +1,6 @@
-/* old_termios.h for SPARC.
+/* Architectural parameters for Linux termios - SPARC version
- Copyright (C) 2025 Free Software Foundation, Inc.
+ Copyright (C) 1991-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
@@ -17,15 +17,18 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#define _TERMIOS2_NCCS 19
+#define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
+
#define _HAVE_STRUCT_OLD_TERMIOS 1
#define OLD_NCCS 17
-typedef struct old_termios
+struct old_termios
{
- tcflag_t c_iflag; /* input mode flags */
- tcflag_t c_oflag; /* output mode flags */
- tcflag_t c_cflag; /* control mode flags */
- tcflag_t c_lflag; /* local mode flags */
- cc_t c_line; /* line discipline */
- cc_t c_cc[OLD_NCCS]; /* control characters */
-} old_termios_t;
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[OLD_NCCS]; /* control characters */
+};
diff --git a/sysdeps/unix/sysv/linux/tcgetattr.c b/sysdeps/unix/sysv/linux/tcgetattr.c
index 36f68a7..ca17569 100644
--- a/sysdeps/unix/sysv/linux/tcgetattr.c
+++ b/sysdeps/unix/sysv/linux/tcgetattr.c
@@ -22,7 +22,7 @@ int
__tcgetattr (int fd, struct termios *termios_p)
{
struct termios2 k_termios;
- long int retval = INLINE_SYSCALL_CALL (ioctl, fd, ARCH_TCGETS, &k_termios);
+ long int retval = INLINE_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios);
if (__glibc_likely (retval != -1))
{
diff --git a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c
index ad8f2df..4f07a03 100644
--- a/sysdeps/unix/sysv/linux/tcsetattr.c
+++ b/sysdeps/unix/sysv/linux/tcsetattr.c
@@ -19,12 +19,6 @@
#define static_assert_equal(x,y) _Static_assert ((x) == (y), #x " != " #y)
-static_assert_equal (sizeof (struct termios2), KERNEL_TERMIOS2_SIZE);
-static_assert_equal (offsetof (struct termios2, c_cc),
- KERNEL_TERMIOS2_CC_OFFSET);
-static_assert_equal (offsetof (struct termios2, c_line),
- KERNEL_TERMIOS2_LINE_OFFSET);
-
/* Set the state of FD to *TERMIOS_P. */
int
__tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
@@ -59,10 +53,10 @@ __tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
*/
static_assert_equal(TCSADRAIN, TCSANOW + 1);
static_assert_equal(TCSAFLUSH, TCSANOW + 2);
- static_assert_equal(KERNEL_TCSETSW2, KERNEL_TCSETS2 + 1);
- static_assert_equal(KERNEL_TCSETSF2, KERNEL_TCSETS2 + 2);
- static_assert_equal(KERNEL_TCSETSW, KERNEL_TCSETS + 1);
- static_assert_equal(KERNEL_TCSETSF, KERNEL_TCSETS + 2);
+ static_assert_equal(TCSETSW2, TCSETS2 + 1);
+ static_assert_equal(TCSETSF2, TCSETS2 + 2);
+ static_assert_equal(TCSETSW, TCSETS + 1);
+ static_assert_equal(TCSETSF, TCSETS + 2);
cmd = (long)optional_actions - TCSANOW;
if (cmd > 2)
@@ -72,11 +66,11 @@ __tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
k_termios.c_ospeed != k_termios.c_ispeed ||
cbaud (k_termios.c_cflag) == __BOTHER)
{
- cmd += KERNEL_TCSETS2;
+ cmd += TCSETS2;
}
else
{
- cmd += KERNEL_TCSETS;
+ cmd += TCSETS;
k_termios.c_cflag &= ~CIBAUD;
}
diff --git a/sysdeps/unix/sysv/linux/termios-kernel-consts.sym b/sysdeps/unix/sysv/linux/termios-kernel-consts.sym
deleted file mode 100644
index 3856a8c..0000000
--- a/sysdeps/unix/sysv/linux/termios-kernel-consts.sym
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <linux/termios.h>
-#include <stddef.h>
-
-#ifdef TCGETS2
-# define STRUCT_TERMIOS struct termios2
-#else
-# define TCGETS2 TCGETS
-# define TCSETS2 TCSETS
-# define TCSETSW2 TCSETSW
-# define TCSETSF2 TCSETSF
-# define STRUCT_TERMIOS struct termios
-#endif
-
---
-KERNEL_TCGETS TCGETS
-KERNEL_TCSETS TCSETS
-KERNEL_TCSETSF TCSETSF
-KERNEL_TCSETSW TCSETSW
-KERNEL_TCGETS2 TCGETS2
-KERNEL_TCSETS2 TCSETS2
-KERNEL_TCSETSF2 TCSETSF2
-KERNEL_TCSETSW2 TCSETSW2
-KERNEL_TERMIOS2_SIZE sizeof (STRUCT_TERMIOS)
-KERNEL_TERMIOS2_CC_OFFSET offsetof (STRUCT_TERMIOS, c_cc)
-KERNEL_TERMIOS2_LINE_OFFSET offsetof (STRUCT_TERMIOS, c_line)
-_TERMIOS2_NCCS sizeof ((STRUCT_TERMIOS) { 0 }.c_cc) / sizeof (cc_t)
diff --git a/sysdeps/unix/sysv/linux/termios_arch.h b/sysdeps/unix/sysv/linux/termios_arch.h
new file mode 100644
index 0000000..8dbf420
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/termios_arch.h
@@ -0,0 +1,23 @@
+/* Architectural parameters for Linux termios - generic version
+
+ Copyright (C) 1997-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/>. */
+
+#define _TERMIOS2_NCCS 19
+#define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
+
+#define _HAVE_STRUCT_OLD_TERMIOS 0
diff --git a/sysdeps/unix/sysv/linux/termios_internals.h b/sysdeps/unix/sysv/linux/termios_internals.h
index b2f3f1b..e8dbfe7 100644
--- a/sysdeps/unix/sysv/linux/termios_internals.h
+++ b/sysdeps/unix/sysv/linux/termios_internals.h
@@ -30,18 +30,7 @@
#include <sysdep.h>
#include <shlib-compat.h>
-#include <termios-kernel-consts.h>
-
-/* Alpha got termios2 late, but TCGETS has exactly the same structure
- format and function as TCGETS2. On all other platforms, the termios2
- interface exists as far back as this version of glibc supports.
-
- For TCSETS* it is more complicated; this is handled in tcsetattr.c. */
-#ifdef __ASSUME_TERMIOS2
-# define ARCH_TCGETS KERNEL_TCGETS2
-#else
-# define ARCH_TCGETS KERNEL_TCGETS
-#endif
+#include <termios_arch.h>
/* ---- Kernel interface definitions ---- */
@@ -55,7 +44,7 @@ struct termios2
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
-#if KERNEL_TERMIOS2_CC_OFFSET < KERNEL_TERMIOS2_LINE_OFFSET
+#if _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE
cc_t c_cc[_TERMIOS2_NCCS]; /* control characters */
cc_t c_line; /* line discipline */
#else
@@ -66,6 +55,26 @@ struct termios2
speed_t c_ospeed; /* output speed */
};
+/* Alpha got termios2 late, but TCGETS has exactly the same structure
+ format and function as TCGETS2. On all other platforms, the termios2
+ interface exists as far back as this version of glibc supports.
+
+ For TCSETS* it is more complicated; this is handled in tcsetattr.c.
+
+ Some other architectures only have the equivalent of the termios2
+ interface, in which case the old ioctl names are the only ones
+ presented, but are equivalent to the new ones. */
+#ifndef TCGETS2
+# define TCGETS2 TCGETS
+# define TCSETS2 TCSETS
+# define TCSETSW2 TCSETSW
+# define TCSETSF2 TCSETSF
+#elif !__ASSUME_TERMIOS2
+/* Hack for Alpha */
+# undef TCGETS2
+# define TCGETS2 TCGETS
+#endif
+
/* ---- Application interface definitions ---- */
/*
@@ -82,7 +91,12 @@ struct termios2
* This only applies to SPARC and MIPS; for other architectures the
* new and old speed_t interfaces both use the same struct termios.
*/
-#include <old_termios.h>
+#if _HAVE_STRUCT_OLD_TERMIOS
+typedef struct old_termios old_termios_t;
+#else
+# define OLD_NCCS NCCS
+typedef struct termios old_termios_t;
+#endif
/* ---- Internal function definitions ---- */
diff --git a/sysdeps/unix/sysv/linux/x86_64/uw-sigframe.h b/sysdeps/unix/sysv/linux/x86_64/uw-sigframe.h
new file mode 100644
index 0000000..585ca01
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/uw-sigframe.h
@@ -0,0 +1,76 @@
+/* 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/linux-unwind.h */
+
+#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
+
+#ifdef __LP64__
+#define RT_SIGRETURN_SYSCALL 0x050f0000000fc0c7ULL
+#else
+#define RT_SIGRETURN_SYSCALL 0x050f40000201c0c7ULL
+#endif
+
+static _Unwind_Reason_Code
+x86_64_decode_signal_frame (frame *frame)
+{
+ unsigned char *pc = (unsigned char *) frame->pc;
+ mcontext_t *st;
+
+ unsigned char pc0 = *(unsigned char *)(pc + 0);
+ unsigned long long pc1;
+ memcpy (&pc1, pc + 1, sizeof (unsigned long long));
+
+ /* movq $__NR_rt_sigreturn, %rax ; syscall. */
+ if ( pc0 == 0x48
+ && pc1 == RT_SIGRETURN_SYSCALL)
+ {
+ ucontext_t *uc_ = (ucontext_t *)frame->sp;
+ st = &uc_->uc_mcontext;
+ }
+ else
+ return _URC_END_OF_STACK;
+
+ frame->pc = (_Unwind_Ptr) st->gregs[REG_RIP];
+ frame->sp = (_Unwind_Ptr) st->gregs[REG_RSP];
+ frame->fp = (_Unwind_Ptr) st->gregs[REG_RBP];
+ return _URC_NO_REASON;
+}
+
+#define MD_DETECT_OUTERMOST_FRAME x86_64_detect_outermost_frame
+
+static _Unwind_Reason_Code
+x86_64_detect_outermost_frame (frame *frame)
+{
+ /* Outermost frame has the frame pointer cleared. */
+ if (frame->fp == 0)
+ return _URC_END_OF_STACK;
+
+ return _URC_NO_REASON;
+}
+
+#endif /* ifdef __x86_64__ */
diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure
index c7ea9ac..dff26e9 100644
--- a/sysdeps/x86/configure
+++ b/sysdeps/x86/configure
@@ -171,8 +171,12 @@ fi
config_vars="$config_vars
have-x86-isa-level = $libc_cv_have_x86_isa_level"
config_vars="$config_vars
+x86-isa-level-2-or-above = 2 3 4"
+config_vars="$config_vars
x86-isa-level-3-or-above = 3 4"
config_vars="$config_vars
+x86-isa-level-4-or-above = 4"
+config_vars="$config_vars
enable-x86-isa-level = $libc_cv_include_x86_isa_level"
diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac
index 031f917..54960a7 100644
--- a/sysdeps/x86/configure.ac
+++ b/sysdeps/x86/configure.ac
@@ -117,7 +117,9 @@ else
AC_DEFINE_UNQUOTED(MINIMUM_X86_ISA_LEVEL, $libc_cv_have_x86_isa_level)
fi
LIBC_CONFIG_VAR([have-x86-isa-level], [$libc_cv_have_x86_isa_level])
+LIBC_CONFIG_VAR([x86-isa-level-2-or-above], [2 3 4])
LIBC_CONFIG_VAR([x86-isa-level-3-or-above], [3 4])
+LIBC_CONFIG_VAR([x86-isa-level-4-or-above], [4])
LIBC_CONFIG_VAR([enable-x86-isa-level], [$libc_cv_include_x86_isa_level])
dnl Check if TEST_CC supports -mfpmath=387
diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index c3e1065..8cace35 100644
--- a/sysdeps/x86_64/Makefile
+++ b/sysdeps/x86_64/Makefile
@@ -11,6 +11,7 @@ endif
ifeq ($(subdir),csu)
gen-as-const-headers += link-defines.sym
+gen-as-const-headers += tlsdesc.sym rtld-offsets.sym
endif
ifeq ($(subdir),gmon)
@@ -235,10 +236,6 @@ $(objpfx)check-rtld.out: $(objpfx)rtld.reloc
generated += check-rtld.out
endif # $(subdir) == elf
-ifeq ($(subdir),csu)
-gen-as-const-headers += tlsdesc.sym rtld-offsets.sym
-endif
-
ifeq ($(subdir),wcsmbs)
sysdep_routines += \
@@ -269,6 +266,15 @@ endif
ifneq ($(enable-cet),no)
+# Add -fcf-protection to CFLAGS when CET is enabled.
+CFLAGS-.o += -fcf-protection
+CFLAGS-.os += -fcf-protection
+CFLAGS-.op += -fcf-protection
+CFLAGS-.oS += -fcf-protection
+
+# Compile assembly codes with <cet.h> when CET is enabled.
+asm-CPPFLAGS += -fcf-protection -include cet.h
+
ifeq ($(subdir),elf)
sysdep-dl-routines += dl-cet
@@ -461,18 +467,7 @@ $(objpfx)tst-shstk-legacy-1g.out: \
$(..)/sysdeps/x86_64/tst-shstk-legacy-1g.sh $(objpfx)tst-shstk-legacy-1g
$(SHELL) $< $(common-objpfx) '$(test-program-prefix)' 2> $@; \
$(evaluate-test)
-endif
-
-# Add -fcf-protection to CFLAGS when CET is enabled.
-CFLAGS-.o += -fcf-protection
-CFLAGS-.os += -fcf-protection
-CFLAGS-.op += -fcf-protection
-CFLAGS-.oS += -fcf-protection
-
-# Compile assembly codes with <cet.h> when CET is enabled.
-asm-CPPFLAGS += -fcf-protection -include cet.h
-ifeq ($(subdir),elf)
ifeq (yes,$(build-shared))
tests-special += $(objpfx)check-cet.out
endif
diff --git a/sysdeps/x86_64/configure b/sysdeps/x86_64/configure
index bbf520b..32324f6 100644
--- a/sysdeps/x86_64/configure
+++ b/sysdeps/x86_64/configure
@@ -289,6 +289,8 @@ fi
config_vars="$config_vars
have-x86-apx = $libc_cv_x86_have_apx"
+libc_cv_support_sframe=yes
+
test -n "$critic_missing" && as_fn_error $? "
*** $critic_missing" "$LINENO" 5
diff --git a/sysdeps/x86_64/configure.ac b/sysdeps/x86_64/configure.ac
index 4a3f7f4..a00958e 100644
--- a/sysdeps/x86_64/configure.ac
+++ b/sysdeps/x86_64/configure.ac
@@ -104,5 +104,7 @@ if test $libc_cv_x86_have_apx = yes; then
fi
LIBC_CONFIG_VAR([have-x86-apx], [$libc_cv_x86_have_apx])
+libc_cv_support_sframe=yes
+
test -n "$critic_missing" && AC_MSG_ERROR([
*** $critic_missing])
diff --git a/sysdeps/x86_64/fpu/math-use-builtins-trunc.h b/sysdeps/x86_64/fpu/math-use-builtins-trunc.h
new file mode 100644
index 0000000..c2387eb
--- /dev/null
+++ b/sysdeps/x86_64/fpu/math-use-builtins-trunc.h
@@ -0,0 +1,9 @@
+#ifdef __SSE4_1__
+# define USE_TRUNC_BUILTIN 1
+# define USE_TRUNCF_BUILTIN 1
+#else
+# define USE_TRUNC_BUILTIN 0
+# define USE_TRUNCF_BUILTIN 0
+#endif
+#define USE_TRUNCL_BUILTIN 0
+#define USE_TRUNCF128_BUILTIN 0
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 3403422..708b142 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -26,6 +26,14 @@ CFLAGS-s_sinf-fma.c = -mfma -mavx2
CFLAGS-s_cosf-fma.c = -mfma -mavx2
CFLAGS-s_sincosf-fma.c = -mfma -mavx2
+# Check if ISA level is 2 or above.
+ifeq (,$(filter $(have-x86-isa-level),$(x86-isa-level-2-or-above)))
+sysdep_calls += \
+ s_modf-sse4_1 \
+ s_modff-sse4_1 \
+# sysdep_calls
+endif
+
# Check if ISA level is 3 or above.
ifneq (,$(filter $(have-x86-isa-level),$(x86-isa-level-3-or-above)))
libm-sysdep_routines += \
@@ -43,6 +51,10 @@ libm-sysdep_routines += \
s_truncf-avx \
# libm-sysdep_routines
else
+sysdep_calls += \
+ s_modf-avx \
+ s_modff-avx \
+# sysdep_calls
ifeq (no,$(have-x86-apx))
libm-sysdep_routines += \
e_asin-fma4 \
@@ -121,6 +133,11 @@ libm-sysdep_routines += \
s_truncf-c \
# libm-sysdep_routines
endif
+
+# $(sysdep_calls) functions are built both for libc and libm. While the
+# libc objects have the prefix s_, the libm ones are prefixed with m_.
+sysdep_routines += $(sysdep_calls)
+libm-sysdep_routines += $(sysdep_calls:s_%=m_%)
endif
CFLAGS-e_asin-fma4.c = -mfma4
@@ -140,6 +157,12 @@ CFLAGS-s_atan-avx.c = -msse2avx -DSSE2AVX
CFLAGS-s_sin-avx.c = -msse2avx -DSSE2AVX
CFLAGS-s_tan-avx.c = -msse2avx -DSSE2AVX
CFLAGS-s_sincos-avx.c = -msse2avx -DSSE2AVX
+
+CFLAGS-s_modf-sse4_1.c = -msse4.1 -fno-builtin-modff32x -fno-builtin-modff64
+CFLAGS-s_modff-sse4_1.c = -msse4.1 -fno-builtin-modff32
+
+CFLAGS-s_modf-avx.c = -mavx -fno-builtin-modff32x -fno-builtin-modff64
+CFLAGS-s_modff-avx.c = -mavx -fno-builtin-modff32
endif
ifeq ($(subdir),mathvec)
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1-avx.h b/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1-avx.h
new file mode 100644
index 0000000..071595f
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1-avx.h
@@ -0,0 +1,41 @@
+/* Common definition for ifunc selections optimized with SSE4.1 and AVX.
+ 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/>. */
+
+#include <init-arch.h>
+
+extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (sse41) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (avx) attribute_hidden;
+
+static inline void *
+IFUNC_SELECTOR (void)
+{
+ const struct cpu_features* cpu_features = __get_cpu_features ();
+
+ if (CPU_FEATURE_USABLE_P (cpu_features, AVX))
+ return OPTIMIZE (avx);
+
+#if MINIMUM_X86_ISA_LEVEL == SSE4_1_X86_ISA_LEVEL
+ return OPTIMIZE (sse41);
+#else
+ if (CPU_FEATURE_USABLE_P (cpu_features, SSE4_1))
+ return OPTIMIZE (sse41);
+
+ return OPTIMIZE (sse2);
+#endif
+}
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c b/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c
new file mode 100644
index 0000000..ab4f03d
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c
@@ -0,0 +1,3 @@
+#define __modf __modf_avx
+
+#include <sysdeps/ieee754/dbl-64/s_modf.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c b/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c
new file mode 100644
index 0000000..00aa8cd
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c
@@ -0,0 +1,3 @@
+#define __modf __modf_sse41
+
+#include <sysdeps/ieee754/dbl-64/s_modf.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modf.c b/sysdeps/x86_64/fpu/multiarch/s_modf.c
new file mode 100644
index 0000000..e365bfc
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modf.c
@@ -0,0 +1,41 @@
+/* Multiple versions of modf
+ 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/>. */
+
+#include <sysdeps/x86/isa-level.h>
+#if MINIMUM_X86_ISA_LEVEL < AVX_X86_ISA_LEVEL
+# define NO_MATH_REDIRECT
+# include <libm-alias-double.h>
+
+# define modf __redirect_modf
+# define __modf __redirect___modf
+# include <math.h>
+# undef modf
+# undef __modf
+
+# define SYMBOL_NAME modf
+# include "ifunc-sse4_1-avx.h"
+
+libc_ifunc_redirected (__redirect_modf, __modf, IFUNC_SELECTOR ());
+libm_alias_double (__modf, modf)
+# if MINIMUM_X86_ISA_LEVEL == SSE4_1_X86_ISA_LEVEL
+# define __modf __modf_sse41
+# else
+# define __modf __modf_sse2
+# endif
+#endif
+#include <sysdeps/ieee754/dbl-64/s_modf.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c b/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c
new file mode 100644
index 0000000..07cb9c1
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c
@@ -0,0 +1,3 @@
+#define __modff __modff_avx
+
+#include <sysdeps/ieee754/flt-32/s_modff.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c b/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c
new file mode 100644
index 0000000..060c5e3
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c
@@ -0,0 +1,3 @@
+#define __modff __modff_sse41
+
+#include <sysdeps/ieee754/flt-32/s_modff.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modff.c b/sysdeps/x86_64/fpu/multiarch/s_modff.c
new file mode 100644
index 0000000..a4b5429
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_modff.c
@@ -0,0 +1,41 @@
+/* Multiple versions of modff
+ 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/>. */
+
+#include <sysdeps/x86/isa-level.h>
+#if MINIMUM_X86_ISA_LEVEL < AVX_X86_ISA_LEVEL
+# define NO_MATH_REDIRECT
+# include <libm-alias-float.h>
+
+# define modff __redirect_modff
+# define __modff __redirect___modff
+# include <math.h>
+# undef modff
+# undef __modff
+
+# define SYMBOL_NAME modff
+# include "ifunc-sse4_1-avx.h"
+
+libc_ifunc_redirected (__redirect_modff, __modff, IFUNC_SELECTOR ());
+libm_alias_float (__modf, modf)
+# if MINIMUM_X86_ISA_LEVEL == SSE4_1_X86_ISA_LEVEL
+# define __modff __modff_sse41
+# else
+# define __modff __modff_sse2
+# endif
+#endif
+#include <sysdeps/ieee754/flt-32/s_modff.c>