public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] PTR_MANGLE/PTR_DEMANGLE refactoring
@ 2022-10-13 12:20 Florian Weimer
  2022-10-13 12:20 ` [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Florian Weimer @ 2022-10-13 12:20 UTC (permalink / raw)
  To: libc-alpha

These patches define PTR_MANGLE and PTR_DEMANGLE unconditionally for C
sources.

I looked into providing generic pointer guard support (particularly for
ld.so), but that needs a bit more work because we need to special-case
the setjmp/longjmp mangling first: the C and assembler side need to be
consistent, and if we add generic pointer mangling on the C side, things
break.

Tested on aarch64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu,
powerpc64le-linux-gnu, s390x-linux-gnu, x86_64-linux-gnu.  Built with
build-many-glibcs.py.

Thanks,
Florian

Florian Weimer (3):
  x86-64: Move LP_SIZE definition to its own header
  Introduce <pointer_guard.h>, extracted from <sysdep.h>
  Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources

 hurd/sigunwind.c                              |  4 +-
 iconv/gconv.c                                 |  4 +-
 iconv/gconv_cache.c                           |  6 +-
 iconv/gconv_db.c                              | 17 +---
 iconv/gconv_dl.c                              |  4 +-
 iconv/gconv_trans.c                           |  3 +-
 iconv/skeleton.c                              |  4 +-
 inet/idna.c                                   |  7 +-
 libio/iofopncook.c                            | 13 +--
 libio/iofwide.c                               |  8 +-
 libio/libioP.h                                |  3 +-
 libio/vtables.c                               |  3 +-
 misc/unwind-link.c                            | 11 ++-
 nss/nss_module.c                              | 14 +---
 stdlib/cxa_atexit.c                           |  4 +-
 stdlib/cxa_finalize.c                         |  5 +-
 stdlib/cxa_thread_atexit_impl.c               |  5 +-
 stdlib/exit.c                                 | 11 +--
 stdlib/on_exit.c                              |  4 +-
 sysdeps/aarch64/__longjmp.S                   |  1 +
 sysdeps/aarch64/jmpbuf-offsets.h              |  3 +-
 sysdeps/aarch64/setjmp.S                      |  1 +
 sysdeps/alpha/__longjmp.S                     |  1 +
 sysdeps/alpha/jmpbuf-unwind.h                 |  3 +-
 sysdeps/alpha/setjmp.S                        |  1 +
 sysdeps/arc/jmpbuf-unwind.h                   |  3 +-
 sysdeps/arm/__longjmp.S                       |  1 +
 sysdeps/arm/jmpbuf-unwind.h                   |  3 +-
 sysdeps/arm/pointer_guard.h                   | 67 +++++++++++++++
 sysdeps/arm/setjmp.S                          |  1 +
 sysdeps/arm/sysdep.h                          | 44 ----------
 sysdeps/csky/abiv2/__longjmp.S                |  1 +
 sysdeps/csky/abiv2/setjmp.S                   |  1 +
 sysdeps/csky/jmpbuf-unwind.h                  |  3 +-
 sysdeps/generic/pointer_guard.h               | 29 +++++++
 sysdeps/generic/unwind-link.h                 |  8 +-
 sysdeps/i386/__longjmp.S                      |  1 +
 sysdeps/i386/bsd-_setjmp.S                    |  1 +
 sysdeps/i386/bsd-setjmp.S                     |  1 +
 sysdeps/i386/jmpbuf-unwind.h                  |  3 +-
 sysdeps/i386/setjmp.S                         |  1 +
 sysdeps/i386/unwind-arch.h                    |  6 +-
 sysdeps/loongarch/__longjmp.S                 |  1 +
 sysdeps/loongarch/jmpbuf-unwind.h             |  3 +-
 sysdeps/loongarch/setjmp.S                    |  1 +
 sysdeps/m68k/jmpbuf-unwind.h                  |  3 +-
 sysdeps/mach/hurd/i386/____longjmp_chk.S      |  1 +
 sysdeps/mach/hurd/i386/__longjmp.S            |  1 +
 sysdeps/mach/hurd/jmp-unwind.c                |  4 +-
 sysdeps/microblaze/jmpbuf-unwind.h            |  3 +-
 sysdeps/mips/jmpbuf-unwind.h                  |  3 +-
 sysdeps/nios2/__longjmp.S                     |  1 +
 sysdeps/nios2/jmpbuf-offsets.h                |  3 +-
 sysdeps/nios2/setjmp.S                        |  1 +
 sysdeps/powerpc/jmpbuf-unwind.h               |  3 +-
 sysdeps/powerpc/powerpc32/__longjmp-common.S  |  1 +
 .../powerpc/powerpc32/fpu/__longjmp-common.S  |  1 +
 sysdeps/powerpc/powerpc32/fpu/setjmp-common.S |  1 +
 sysdeps/powerpc/powerpc32/setjmp-common.S     |  1 +
 sysdeps/powerpc/powerpc64/__longjmp-common.S  |  1 +
 sysdeps/powerpc/powerpc64/setjmp-common.S     |  1 +
 sysdeps/riscv/jmpbuf-unwind.h                 |  3 +-
 sysdeps/s390/jmpbuf-unwind.h                  |  3 +-
 sysdeps/s390/s390-32/__longjmp.c              |  6 ++
 sysdeps/s390/s390-32/setjmp.S                 |  1 +
 sysdeps/s390/s390-64/__longjmp.c              |  6 ++
 sysdeps/s390/s390-64/setjmp.S                 |  1 +
 sysdeps/sh/jmpbuf-unwind.h                    |  3 +-
 sysdeps/sh/sh3/__longjmp.S                    |  1 +
 sysdeps/sh/sh3/setjmp.S                       |  1 +
 sysdeps/sh/sh4/__longjmp.S                    |  1 +
 sysdeps/sh/sh4/setjmp.S                       |  1 +
 sysdeps/sparc/sparc32/__longjmp.S             |  1 +
 sysdeps/sparc/sparc32/jmpbuf-unwind.h         |  3 +-
 sysdeps/sparc/sparc32/setjmp.S                |  1 +
 .../unix/sysv/linux/aarch64/pointer_guard.h   | 68 +++++++++++++++
 sysdeps/unix/sysv/linux/aarch64/sysdep.h      | 45 ----------
 .../unix/sysv/linux/alpha/____longjmp_chk.S   |  1 +
 sysdeps/unix/sysv/linux/alpha/pointer_guard.h | 62 ++++++++++++++
 sysdeps/unix/sysv/linux/alpha/sysdep.h        | 40 ---------
 sysdeps/unix/sysv/linux/arc/sysdep.h          |  4 -
 sysdeps/unix/sysv/linux/csky/pointer_guard.h  | 68 +++++++++++++++
 sysdeps/unix/sysv/linux/csky/sysdep.h         | 46 -----------
 sysdeps/unix/sysv/linux/hppa/sysdep.h         |  4 -
 .../unix/sysv/linux/i386/____longjmp_chk.S    |  1 +
 sysdeps/unix/sysv/linux/i386/pointer_guard.h  | 49 +++++++++++
 sysdeps/unix/sysv/linux/i386/sysdep.h         | 28 -------
 sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S |  1 +
 sysdeps/unix/sysv/linux/ia64/__longjmp.S      |  1 +
 sysdeps/unix/sysv/linux/ia64/pointer_guard.h  | 44 ++++++++++
 sysdeps/unix/sysv/linux/ia64/setjmp.S         |  1 +
 sysdeps/unix/sysv/linux/ia64/sysdep.h         | 20 -----
 .../unix/sysv/linux/loongarch/pointer_guard.h | 82 +++++++++++++++++++
 sysdeps/unix/sysv/linux/loongarch/sysdep.h    | 60 --------------
 sysdeps/unix/sysv/linux/m68k/sysdep.h         |  4 -
 sysdeps/unix/sysv/linux/microblaze/sysdep.h   |  4 -
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |  4 -
 sysdeps/unix/sysv/linux/mips/mips64/sysdep.h  |  4 -
 sysdeps/unix/sysv/linux/nios2/pointer_guard.h | 40 +++++++++
 sysdeps/unix/sysv/linux/nios2/sysdep.h        | 17 ----
 sysdeps/unix/sysv/linux/or1k/sysdep.h         |  4 -
 .../unix/sysv/linux/powerpc/pointer_guard.h   | 55 +++++++++++++
 sysdeps/unix/sysv/linux/powerpc/sysdep.h      | 32 --------
 sysdeps/unix/sysv/linux/riscv/sysdep.h        |  4 -
 .../sysv/linux/s390/s390-32/pointer_guard.h   | 45 ++++++++++
 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h | 21 -----
 .../sysv/linux/s390/s390-64/pointer_guard.h   | 47 +++++++++++
 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h | 23 ------
 sysdeps/unix/sysv/linux/sh/____longjmp_chk.S  |  1 +
 sysdeps/unix/sysv/linux/sh/pointer_guard.h    | 43 ++++++++++
 sysdeps/unix/sysv/linux/sh/sysdep.h           | 19 -----
 .../linux/sparc/sparc32/____longjmp_chk.S     |  1 +
 .../sysv/linux/sparc/sparc32/pointer_guard.h  | 44 ++++++++++
 .../unix/sysv/linux/sparc/sparc32/sysdep.h    | 20 -----
 .../sysv/linux/sparc/sparc64/pointer_guard.h  | 44 ++++++++++
 .../unix/sysv/linux/sparc/sparc64/sysdep.h    | 20 -----
 .../unix/sysv/linux/x86_64/____longjmp_chk.S  |  1 +
 .../unix/sysv/linux/x86_64/pointer_guard.h    | 61 ++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/sysdep.h       | 40 ---------
 sysdeps/x86_64/__longjmp.S                    |  1 +
 sysdeps/x86_64/jmpbuf-unwind.h                |  3 +-
 sysdeps/x86_64/setjmp.S                       |  1 +
 sysdeps/x86_64/sysdep.h                       |  7 +-
 sysdeps/x86_64/x32/sysdep.h                   |  6 +-
 sysdeps/x86_64/x32/x86-lp_size.h              | 23 ++++++
 sysdeps/x86_64/x86-lp_size.h                  | 23 ++++++
 wcsmbs/btowc.c                                |  6 +-
 wcsmbs/mbrtoc16.c                             |  4 +-
 wcsmbs/mbrtoc8.c                              |  2 -
 wcsmbs/mbrtowc.c                              |  4 +-
 wcsmbs/mbsnrtowcs.c                           |  4 +-
 wcsmbs/mbsrtowcs_l.c                          |  4 +-
 wcsmbs/wcrtomb.c                              |  4 +-
 wcsmbs/wcsnrtombs.c                           |  4 +-
 wcsmbs/wcsrtombs.c                            |  4 +-
 wcsmbs/wctob.c                                |  4 +-
 136 files changed, 1007 insertions(+), 700 deletions(-)
 create mode 100644 sysdeps/arm/pointer_guard.h
 create mode 100644 sysdeps/generic/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/alpha/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/i386/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/ia64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/nios2/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sh/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
 create mode 100644 sysdeps/x86_64/x32/x86-lp_size.h
 create mode 100644 sysdeps/x86_64/x86-lp_size.h


base-commit: 15a94e6668a6d7c5697e805d8d67f1d102d0d52e
-- 
2.37.3


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header
  2022-10-13 12:20 [PATCH 0/3] PTR_MANGLE/PTR_DEMANGLE refactoring Florian Weimer
@ 2022-10-13 12:20 ` Florian Weimer
  2022-10-17 16:03   ` Adhemerval Zanella Netto
  2022-10-13 12:20 ` [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h> Florian Weimer
  2022-10-13 12:20 ` [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources Florian Weimer
  2 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2022-10-13 12:20 UTC (permalink / raw)
  To: libc-alpha

This way, we can define the pointer guard macros without including
<sysdep.h> on x86-64.  Other architectures will not have such an
inclusion dependency, and the implied header file inclusion would
create a porting hazard.
---
 sysdeps/x86_64/sysdep.h          |  7 +------
 sysdeps/x86_64/x32/sysdep.h      |  6 +-----
 sysdeps/x86_64/x32/x86-lp_size.h | 23 +++++++++++++++++++++++
 sysdeps/x86_64/x86-lp_size.h     | 23 +++++++++++++++++++++++
 4 files changed, 48 insertions(+), 11 deletions(-)
 create mode 100644 sysdeps/x86_64/x32/x86-lp_size.h
 create mode 100644 sysdeps/x86_64/x86-lp_size.h

diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
index 7f5defa4ec..d1a43dc14c 100644
--- a/sysdeps/x86_64/sysdep.h
+++ b/sysdeps/x86_64/sysdep.h
@@ -20,6 +20,7 @@
 #define _X86_64_SYSDEP_H 1
 
 #include <sysdeps/x86/sysdep.h>
+#include <x86-lp_size.h>
 
 #ifdef	__ASSEMBLER__
 
@@ -68,9 +69,6 @@ lose:									      \
 # define JUMPTARGET(name)	name
 #endif
 
-/* Long and pointer size in bytes.  */
-#define LP_SIZE	8
-
 /* Instruction to operate on long and pointer.  */
 #define LP_OP(insn) insn##q
 
@@ -137,9 +135,6 @@ lose:									      \
 
 #else	/* __ASSEMBLER__ */
 
-/* Long and pointer size in bytes.  */
-#define LP_SIZE "8"
-
 /* Instruction to operate on long and pointer.  */
 #define LP_OP(insn) #insn "q"
 
diff --git a/sysdeps/x86_64/x32/sysdep.h b/sysdeps/x86_64/x32/sysdep.h
index 645ea4ae69..92d987780d 100644
--- a/sysdeps/x86_64/x32/sysdep.h
+++ b/sysdeps/x86_64/x32/sysdep.h
@@ -17,8 +17,8 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdeps/x86_64/sysdep.h>
+#include <x86-lp_size.h>
 
-#undef LP_SIZE
 #undef LP_OP
 #undef ASM_ADDR
 
@@ -41,8 +41,6 @@
 
 #ifdef	__ASSEMBLER__
 
-# define LP_SIZE 4
-
 # define LP_OP(insn) insn##l
 
 # define ASM_ADDR .long
@@ -66,8 +64,6 @@
 
 #else	/* __ASSEMBLER__ */
 
-# define LP_SIZE "4"
-
 # define LP_OP(insn) #insn "l"
 
 # define ASM_ADDR ".long"
diff --git a/sysdeps/x86_64/x32/x86-lp_size.h b/sysdeps/x86_64/x32/x86-lp_size.h
new file mode 100644
index 0000000000..ad03eb66b2
--- /dev/null
+++ b/sysdeps/x86_64/x32/x86-lp_size.h
@@ -0,0 +1,23 @@
+/* Pointer size definition for x86-64 x42.
+   Copyright (C) 2022 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/>.  */
+
+#ifdef __ASSEMBLER__
+# define LP_SIZE 4
+#else
+# define LP_SIZE "4"
+#endif
diff --git a/sysdeps/x86_64/x86-lp_size.h b/sysdeps/x86_64/x86-lp_size.h
new file mode 100644
index 0000000000..76877240e8
--- /dev/null
+++ b/sysdeps/x86_64/x86-lp_size.h
@@ -0,0 +1,23 @@
+/* Pointer size definition for x86-64.
+   Copyright (C) 2022 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/>.  */
+
+#ifdef __ASSEMBLER__
+# define LP_SIZE 8
+#else
+# define LP_SIZE "8"
+#endif
-- 
2.37.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h>
  2022-10-13 12:20 [PATCH 0/3] PTR_MANGLE/PTR_DEMANGLE refactoring Florian Weimer
  2022-10-13 12:20 ` [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header Florian Weimer
@ 2022-10-13 12:20 ` Florian Weimer
  2022-10-14  3:30   ` DJ Delorie
  2022-10-17 16:13   ` Adhemerval Zanella Netto
  2022-10-13 12:20 ` [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources Florian Weimer
  2 siblings, 2 replies; 10+ messages in thread
From: Florian Weimer @ 2022-10-13 12:20 UTC (permalink / raw)
  To: libc-alpha

This allows us to define a generic no-op version of PTR_MANGLE and
PTR_DEMANGLE.  In the future, we can use PTR_MANGLE and PTR_DEMANGLE
unconditionally in C sources, avoiding an unintended loss of hardening
due to missing include files or unlucky header inclusion ordering.

In i386 and x86_64, we can avoid a <tls.h> dependency in the C
code by using the computed constant from <tcb-offsets.h>.  <sysdep.h>
no longer includes these definitions, so there is no cyclic dependency
anymore when computing the <tcb-offsets.h> constants.
---
 hurd/sigunwind.c                              |  2 +-
 iconv/gconv.c                                 |  2 +-
 iconv/gconv_cache.c                           |  1 +
 iconv/gconv_db.c                              |  2 +-
 iconv/gconv_dl.c                              |  2 +-
 iconv/gconv_trans.c                           |  1 +
 iconv/skeleton.c                              |  2 +-
 inet/idna.c                                   |  1 +
 libio/iofopncook.c                            |  1 +
 libio/iofwide.c                               |  2 +-
 libio/libioP.h                                |  1 +
 libio/vtables.c                               |  1 +
 misc/unwind-link.c                            |  1 +
 nss/nss_module.c                              |  2 +-
 stdlib/cxa_atexit.c                           |  2 +-
 stdlib/cxa_finalize.c                         |  2 +-
 stdlib/cxa_thread_atexit_impl.c               |  1 +
 stdlib/exit.c                                 |  2 +-
 stdlib/on_exit.c                              |  2 +-
 sysdeps/aarch64/__longjmp.S                   |  1 +
 sysdeps/aarch64/jmpbuf-offsets.h              |  1 +
 sysdeps/aarch64/setjmp.S                      |  1 +
 sysdeps/alpha/__longjmp.S                     |  1 +
 sysdeps/alpha/jmpbuf-unwind.h                 |  1 +
 sysdeps/alpha/setjmp.S                        |  1 +
 sysdeps/arc/jmpbuf-unwind.h                   |  1 +
 sysdeps/arm/__longjmp.S                       |  1 +
 sysdeps/arm/jmpbuf-unwind.h                   |  1 +
 sysdeps/arm/pointer_guard.h                   | 67 +++++++++++++++
 sysdeps/arm/setjmp.S                          |  1 +
 sysdeps/arm/sysdep.h                          | 44 ----------
 sysdeps/csky/abiv2/__longjmp.S                |  1 +
 sysdeps/csky/abiv2/setjmp.S                   |  1 +
 sysdeps/csky/jmpbuf-unwind.h                  |  1 +
 sysdeps/generic/pointer_guard.h               | 29 +++++++
 sysdeps/generic/unwind-link.h                 |  2 +-
 sysdeps/i386/__longjmp.S                      |  1 +
 sysdeps/i386/bsd-_setjmp.S                    |  1 +
 sysdeps/i386/bsd-setjmp.S                     |  1 +
 sysdeps/i386/jmpbuf-unwind.h                  |  1 +
 sysdeps/i386/setjmp.S                         |  1 +
 sysdeps/loongarch/__longjmp.S                 |  1 +
 sysdeps/loongarch/jmpbuf-unwind.h             |  1 +
 sysdeps/loongarch/setjmp.S                    |  1 +
 sysdeps/m68k/jmpbuf-unwind.h                  |  1 +
 sysdeps/mach/hurd/i386/____longjmp_chk.S      |  1 +
 sysdeps/mach/hurd/i386/__longjmp.S            |  1 +
 sysdeps/mach/hurd/jmp-unwind.c                |  2 +-
 sysdeps/microblaze/jmpbuf-unwind.h            |  1 +
 sysdeps/mips/jmpbuf-unwind.h                  |  1 +
 sysdeps/nios2/__longjmp.S                     |  1 +
 sysdeps/nios2/jmpbuf-offsets.h                |  1 +
 sysdeps/nios2/setjmp.S                        |  1 +
 sysdeps/powerpc/jmpbuf-unwind.h               |  1 +
 sysdeps/powerpc/powerpc32/__longjmp-common.S  |  1 +
 .../powerpc/powerpc32/fpu/__longjmp-common.S  |  1 +
 sysdeps/powerpc/powerpc32/fpu/setjmp-common.S |  1 +
 sysdeps/powerpc/powerpc32/setjmp-common.S     |  1 +
 sysdeps/powerpc/powerpc64/__longjmp-common.S  |  1 +
 sysdeps/powerpc/powerpc64/setjmp-common.S     |  1 +
 sysdeps/riscv/jmpbuf-unwind.h                 |  1 +
 sysdeps/s390/jmpbuf-unwind.h                  |  1 +
 sysdeps/s390/s390-32/__longjmp.c              |  1 +
 sysdeps/s390/s390-32/setjmp.S                 |  1 +
 sysdeps/s390/s390-64/__longjmp.c              |  1 +
 sysdeps/s390/s390-64/setjmp.S                 |  1 +
 sysdeps/sh/jmpbuf-unwind.h                    |  1 +
 sysdeps/sh/sh3/__longjmp.S                    |  1 +
 sysdeps/sh/sh3/setjmp.S                       |  1 +
 sysdeps/sh/sh4/__longjmp.S                    |  1 +
 sysdeps/sh/sh4/setjmp.S                       |  1 +
 sysdeps/sparc/sparc32/__longjmp.S             |  1 +
 sysdeps/sparc/sparc32/jmpbuf-unwind.h         |  1 +
 sysdeps/sparc/sparc32/setjmp.S                |  1 +
 .../unix/sysv/linux/aarch64/pointer_guard.h   | 68 +++++++++++++++
 sysdeps/unix/sysv/linux/aarch64/sysdep.h      | 45 ----------
 .../unix/sysv/linux/alpha/____longjmp_chk.S   |  1 +
 sysdeps/unix/sysv/linux/alpha/pointer_guard.h | 62 ++++++++++++++
 sysdeps/unix/sysv/linux/alpha/sysdep.h        | 40 ---------
 sysdeps/unix/sysv/linux/arc/sysdep.h          |  4 -
 sysdeps/unix/sysv/linux/csky/pointer_guard.h  | 68 +++++++++++++++
 sysdeps/unix/sysv/linux/csky/sysdep.h         | 46 -----------
 sysdeps/unix/sysv/linux/hppa/sysdep.h         |  4 -
 .../unix/sysv/linux/i386/____longjmp_chk.S    |  1 +
 sysdeps/unix/sysv/linux/i386/pointer_guard.h  | 49 +++++++++++
 sysdeps/unix/sysv/linux/i386/sysdep.h         | 28 -------
 sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S |  1 +
 sysdeps/unix/sysv/linux/ia64/__longjmp.S      |  1 +
 sysdeps/unix/sysv/linux/ia64/pointer_guard.h  | 44 ++++++++++
 sysdeps/unix/sysv/linux/ia64/setjmp.S         |  1 +
 sysdeps/unix/sysv/linux/ia64/sysdep.h         | 20 -----
 .../unix/sysv/linux/loongarch/pointer_guard.h | 82 +++++++++++++++++++
 sysdeps/unix/sysv/linux/loongarch/sysdep.h    | 60 --------------
 sysdeps/unix/sysv/linux/m68k/sysdep.h         |  4 -
 sysdeps/unix/sysv/linux/microblaze/sysdep.h   |  4 -
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |  4 -
 sysdeps/unix/sysv/linux/mips/mips64/sysdep.h  |  4 -
 sysdeps/unix/sysv/linux/nios2/pointer_guard.h | 40 +++++++++
 sysdeps/unix/sysv/linux/nios2/sysdep.h        | 17 ----
 sysdeps/unix/sysv/linux/or1k/sysdep.h         |  4 -
 .../unix/sysv/linux/powerpc/pointer_guard.h   | 55 +++++++++++++
 sysdeps/unix/sysv/linux/powerpc/sysdep.h      | 32 --------
 sysdeps/unix/sysv/linux/riscv/sysdep.h        |  4 -
 .../sysv/linux/s390/s390-32/pointer_guard.h   | 45 ++++++++++
 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h | 21 -----
 .../sysv/linux/s390/s390-64/pointer_guard.h   | 47 +++++++++++
 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h | 23 ------
 sysdeps/unix/sysv/linux/sh/____longjmp_chk.S  |  1 +
 sysdeps/unix/sysv/linux/sh/pointer_guard.h    | 43 ++++++++++
 sysdeps/unix/sysv/linux/sh/sysdep.h           | 19 -----
 .../linux/sparc/sparc32/____longjmp_chk.S     |  1 +
 .../sysv/linux/sparc/sparc32/pointer_guard.h  | 44 ++++++++++
 .../unix/sysv/linux/sparc/sparc32/sysdep.h    | 20 -----
 .../sysv/linux/sparc/sparc64/pointer_guard.h  | 44 ++++++++++
 .../unix/sysv/linux/sparc/sparc64/sysdep.h    | 20 -----
 .../unix/sysv/linux/x86_64/____longjmp_chk.S  |  1 +
 .../unix/sysv/linux/x86_64/pointer_guard.h    | 61 ++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/sysdep.h       | 40 ---------
 sysdeps/x86_64/__longjmp.S                    |  1 +
 sysdeps/x86_64/jmpbuf-unwind.h                |  1 +
 sysdeps/x86_64/setjmp.S                       |  1 +
 sysdeps/x86_64/x32/x86-lp_size.h              |  2 +-
 wcsmbs/btowc.c                                |  2 +-
 wcsmbs/mbrtoc16.c                             |  2 +-
 wcsmbs/mbrtoc8.c                              |  2 -
 wcsmbs/mbrtowc.c                              |  2 +-
 wcsmbs/mbsnrtowcs.c                           |  2 +-
 wcsmbs/mbsrtowcs_l.c                          |  2 +-
 wcsmbs/wcrtomb.c                              |  2 +-
 wcsmbs/wcsnrtombs.c                           |  2 +-
 wcsmbs/wcsrtombs.c                            |  2 +-
 wcsmbs/wctob.c                                |  2 +-
 132 files changed, 940 insertions(+), 532 deletions(-)
 create mode 100644 sysdeps/arm/pointer_guard.h
 create mode 100644 sysdeps/generic/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/alpha/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/i386/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/ia64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/nios2/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sh/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/pointer_guard.h

diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
index de76cf2436..28213091e3 100644
--- a/hurd/sigunwind.c
+++ b/hurd/sigunwind.c
@@ -22,7 +22,7 @@
 #include <jmpbuf-unwind.h>
 #include <assert.h>
 #include <stdint.h>
-
+#include <pointer_guard.h>
 
 /* _hurd_setup_sighandler puts a link on the `active resources' chain so that
    _longjmp_unwind will call this function with the `struct sigcontext *'
diff --git a/iconv/gconv.c b/iconv/gconv.c
index 62d2b37bcd..dea9c80fee 100644
--- a/iconv/gconv.c
+++ b/iconv/gconv.c
@@ -23,7 +23,7 @@
 #include <sys/param.h>
 
 #include <gconv_int.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 int
diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
index c772856d1f..5dbf596b8d 100644
--- a/iconv/gconv_cache.c
+++ b/iconv/gconv_cache.c
@@ -28,6 +28,7 @@
 #include <gconv_int.h>
 #include <iconvconfig.h>
 #include <not-cancel.h>
+#include <pointer_guard.h>
 
 #include "../intl/hash-string.h"
 
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index bf385ac7b1..90037fdf58 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -27,7 +27,7 @@
 
 #include <dlfcn.h>
 #include <gconv_int.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 /* Simple data structure for alias mapping.  We have two names, `from'
diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
index 24c0bd1d39..c93c5dd380 100644
--- a/iconv/gconv_dl.c
+++ b/iconv/gconv_dl.c
@@ -26,7 +26,7 @@
 #include <sys/param.h>
 
 #include <gconv_int.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 #ifdef DEBUG
diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c
index 1ebbbfd51b..0f4ce10996 100644
--- a/iconv/gconv_trans.c
+++ b/iconv/gconv_trans.c
@@ -26,6 +26,7 @@
 #include <libc-lock.h>
 #include "gconv_int.h"
 #include "../locale/localeinfo.h"
+#include <pointer_guard.h>
 
 
 int
diff --git a/iconv/skeleton.c b/iconv/skeleton.c
index 0356dbf92b..42ee0b6508 100644
--- a/iconv/skeleton.c
+++ b/iconv/skeleton.c
@@ -147,7 +147,7 @@
 # include <dlfcn.h>
 #endif
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 #include <stdint.h>
 
 #ifndef DL_CALL_FCT
diff --git a/inet/idna.c b/inet/idna.c
index 9c76681c6a..df5811fd6a 100644
--- a/inet/idna.c
+++ b/inet/idna.c
@@ -21,6 +21,7 @@
 #include <inet/net-internal.h>
 #include <netdb.h>
 #include <stdbool.h>
+#include <pointer_guard.h>
 
 /* Use the soname and version to locate libidn2, to ensure a
    compatible ABI.  */
diff --git a/libio/iofopncook.c b/libio/iofopncook.c
index e108ad2199..a7db4ef1c9 100644
--- a/libio/iofopncook.c
+++ b/libio/iofopncook.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <shlib-compat.h>
+#include <pointer_guard.h>
 
 static ssize_t
 _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
diff --git a/libio/iofwide.c b/libio/iofwide.c
index 01616e06c7..1ce685f48a 100644
--- a/libio/iofwide.c
+++ b/libio/iofwide.c
@@ -36,7 +36,7 @@
 #include <wcsmbs/wcsmbsload.h>
 #include <iconv/gconv_int.h>
 #include <shlib-compat.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 /* Return orientation of stream.  If mode is nonzero try to change
diff --git a/libio/libioP.h b/libio/libioP.h
index ba4fdbd200..dac3de73a1 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -47,6 +47,7 @@
 #include "iolibio.h"
 
 #include <shlib-compat.h>
+#include <pointer_guard.h>
 
 /* For historical reasons this is the name of the sysdeps header that
    adjusts the libio configuration.  */
diff --git a/libio/vtables.c b/libio/vtables.c
index 50acab7f21..32459e4fac 100644
--- a/libio/vtables.c
+++ b/libio/vtables.c
@@ -20,6 +20,7 @@
 #include <libioP.h>
 #include <stdio.h>
 #include <ldsodefs.h>
+#include <pointer_guard.h>
 
 #ifdef SHARED
 
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 9ae9561206..45b7886b46 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -23,6 +23,7 @@
 #include <gnu/lib-names.h>
 #include <unwind-link.h>
 #include <libc-lock.h>
+#include <pointer_guard.h>
 
 /* Statically allocate the object, so that we do not have to deal with
    malloc failure.  __libc_unwind_link_get must not fail if libgcc_s
diff --git a/nss/nss_module.c b/nss/nss_module.c
index f00bbd9e1a..9a8f3ddf94 100644
--- a/nss/nss_module.c
+++ b/nss/nss_module.c
@@ -32,7 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Suffix after .so of NSS service modules.  This is a bit of magic,
    but we assume LIBNSS_FILES_SO looks like "libnss_files.so.2" and we
diff --git a/stdlib/cxa_atexit.c b/stdlib/cxa_atexit.c
index 1412dacb07..adf89e93f5 100644
--- a/stdlib/cxa_atexit.c
+++ b/stdlib/cxa_atexit.c
@@ -21,7 +21,7 @@
 
 #include <libc-lock.h>
 #include "exit.h"
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #undef __cxa_atexit
 
diff --git a/stdlib/cxa_finalize.c b/stdlib/cxa_finalize.c
index d4db2e1fe0..f2479569a5 100644
--- a/stdlib/cxa_finalize.c
+++ b/stdlib/cxa_finalize.c
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include "exit.h"
 #include <register-atfork.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 #include <stdint.h>
 
 /* If D is non-NULL, call all functions registered with `__cxa_atexit'
diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c
index 5cc8eb55dd..faacab3990 100644
--- a/stdlib/cxa_thread_atexit_impl.c
+++ b/stdlib/cxa_thread_atexit_impl.c
@@ -75,6 +75,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ldsodefs.h>
+#include <pointer_guard.h>
 
 typedef void (*dtor_func) (void *);
 
diff --git a/stdlib/exit.c b/stdlib/exit.c
index bc46109f3e..e59156bbf6 100644
--- a/stdlib/exit.c
+++ b/stdlib/exit.c
@@ -18,7 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 #include <libc-lock.h>
 #include "exit.h"
 
diff --git a/stdlib/on_exit.c b/stdlib/on_exit.c
index 3e2d640d65..fb59db20ca 100644
--- a/stdlib/on_exit.c
+++ b/stdlib/on_exit.c
@@ -18,7 +18,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include "exit.h"
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Register a function to be called by exit.  */
 int
diff --git a/sysdeps/aarch64/__longjmp.S b/sysdeps/aarch64/__longjmp.S
index 5f83f9f264..d934e00ec3 100644
--- a/sysdeps/aarch64/__longjmp.S
+++ b/sysdeps/aarch64/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <stap-probe.h>
 
diff --git a/sysdeps/aarch64/jmpbuf-offsets.h b/sysdeps/aarch64/jmpbuf-offsets.h
index 6256bda7a9..78bdd4a539 100644
--- a/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/sysdeps/aarch64/jmpbuf-offsets.h
@@ -43,6 +43,7 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf jmpbuf)
diff --git a/sysdeps/aarch64/setjmp.S b/sysdeps/aarch64/setjmp.S
index 3860f4e0ec..2ed2feb488 100644
--- a/sysdeps/aarch64/setjmp.S
+++ b/sysdeps/aarch64/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <stap-probe.h>
 
diff --git a/sysdeps/alpha/__longjmp.S b/sysdeps/alpha/__longjmp.S
index ec7510bb55..aed7a17ed8 100644
--- a/sysdeps/alpha/__longjmp.S
+++ b/sysdeps/alpha/__longjmp.S
@@ -18,6 +18,7 @@
 #define __ASSEMBLY__
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 
diff --git a/sysdeps/alpha/jmpbuf-unwind.h b/sysdeps/alpha/jmpbuf-unwind.h
index 13b27990b3..318b73b100 100644
--- a/sysdeps/alpha/jmpbuf-unwind.h
+++ b/sysdeps/alpha/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame containing a local
    variable at ADDRESS.  */
diff --git a/sysdeps/alpha/setjmp.S b/sysdeps/alpha/setjmp.S
index f86367ae08..deb888c072 100644
--- a/sysdeps/alpha/setjmp.S
+++ b/sysdeps/alpha/setjmp.S
@@ -18,6 +18,7 @@
 #define __ASSEMBLY__
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 	.ent __sigsetjmp
diff --git a/sysdeps/arc/jmpbuf-unwind.h b/sysdeps/arc/jmpbuf-unwind.h
index 5488707919..e5434a95dd 100644
--- a/sysdeps/arc/jmpbuf-unwind.h
+++ b/sysdeps/arc/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <jmpbuf-offsets.h>
 #include <stdint.h>
 #include <unwind.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/arm/__longjmp.S b/sysdeps/arm/__longjmp.S
index 5f1cf3643f..411055b9b3 100644
--- a/sysdeps/arm/__longjmp.S
+++ b/sysdeps/arm/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #include <bits/setjmp.h>
 #include <rtld-global-offsets.h>
diff --git a/sysdeps/arm/jmpbuf-unwind.h b/sysdeps/arm/jmpbuf-unwind.h
index e6b118f4d0..641444eaf3 100644
--- a/sysdeps/arm/jmpbuf-unwind.h
+++ b/sysdeps/arm/jmpbuf-unwind.h
@@ -18,6 +18,7 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <unwind.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
diff --git a/sysdeps/arm/pointer_guard.h b/sysdeps/arm/pointer_guard.h
new file mode 100644
index 0000000000..6b90cec2f3
--- /dev/null
+++ b/sysdeps/arm/pointer_guard.h
@@ -0,0 +1,67 @@
+/* Pointer guard implementation.  Arm version.
+   Copyright (C) 2013-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+/* Pointer mangling support.  */
+#if (IS_IN (rtld) \
+     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE_LOAD(guard, tmp)                                   \
+  LDR_HIDDEN (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local), 0)
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  PTR_MANGLE_LOAD(guard, tmp);                                          \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)          \
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)    \
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)        \
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE_LOAD(guard, tmp)                                   \
+  LDR_GLOBAL (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard), 0);
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  PTR_MANGLE_LOAD(guard, tmp);                                          \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)          \
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)    \
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)        \
+  PTR_MANGLE2 (dst, src, guard)
+# else
+#  include <stdint.h>
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/arm/setjmp.S b/sysdeps/arm/setjmp.S
index 1c26227437..271454d769 100644
--- a/sysdeps/arm/setjmp.S
+++ b/sysdeps/arm/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #include <bits/setjmp.h>
 #include <rtld-global-offsets.h>
diff --git a/sysdeps/arm/sysdep.h b/sysdeps/arm/sysdep.h
index f19146b85f..ffd848de88 100644
--- a/sysdeps/arm/sysdep.h
+++ b/sysdeps/arm/sysdep.h
@@ -293,47 +293,3 @@
 #else
 # define PC_OFS  8
 #endif
-
-/* Pointer mangling support.  */
-#if (IS_IN (rtld) \
-     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE_LOAD(guard, tmp)					\
-  LDR_HIDDEN (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local), 0)
-#  define PTR_MANGLE(dst, src, guard, tmp)				\
-  PTR_MANGLE_LOAD(guard, tmp);						\
-  PTR_MANGLE2(dst, src, guard)
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#  define PTR_MANGLE2(dst, src, guard)		\
-  eor dst, src, guard
-#  define PTR_DEMANGLE(dst, src, guard, tmp)	\
-  PTR_MANGLE (dst, src, guard, tmp)
-#  define PTR_DEMANGLE2(dst, src, guard)	\
-  PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
-#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
-# endif
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE_LOAD(guard, tmp)					\
-  LDR_GLOBAL (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard), 0);
-#  define PTR_MANGLE(dst, src, guard, tmp)				\
-  PTR_MANGLE_LOAD(guard, tmp);						\
-  PTR_MANGLE2(dst, src, guard)
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#  define PTR_MANGLE2(dst, src, guard)		\
-  eor dst, src, guard
-#  define PTR_DEMANGLE(dst, src, guard, tmp)	\
-  PTR_MANGLE (dst, src, guard, tmp)
-#  define PTR_DEMANGLE2(dst, src, guard)	\
-  PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard attribute_relro;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
-#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
-# endif
-#endif
diff --git a/sysdeps/csky/abiv2/__longjmp.S b/sysdeps/csky/abiv2/__longjmp.S
index 762b2cb47f..bb7da548c2 100644
--- a/sysdeps/csky/abiv2/__longjmp.S
+++ b/sysdeps/csky/abiv2/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 ENTRY (__longjmp)
 	mov	a2, a0
diff --git a/sysdeps/csky/abiv2/setjmp.S b/sysdeps/csky/abiv2/setjmp.S
index 0acf197d02..afef3ce390 100644
--- a/sysdeps/csky/abiv2/setjmp.S
+++ b/sysdeps/csky/abiv2/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 ENTRY (setjmp)
 	movi	a1, 1
diff --git a/sysdeps/csky/jmpbuf-unwind.h b/sysdeps/csky/jmpbuf-unwind.h
index 358e912856..76fca431c6 100644
--- a/sysdeps/csky/jmpbuf-unwind.h
+++ b/sysdeps/csky/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/generic/pointer_guard.h b/sysdeps/generic/pointer_guard.h
new file mode 100644
index 0000000000..58a624e1d5
--- /dev/null
+++ b/sysdeps/generic/pointer_guard.h
@@ -0,0 +1,29 @@
+/* Pointer obfuscation implenentation.  Generic (no-op) version.
+   Copyright (C) 2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+/* Assembler code depends on PTR_MANGLE not being defined for
+   optimization purposes.  */
+#ifndef __ASSEMBLER__
+# define PTR_MANGLE(x) (void) (x)
+# define PTR_DEMANGLE(x) (void) (x)
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/generic/unwind-link.h b/sysdeps/generic/unwind-link.h
index 93ee80f3f8..a2076a23bf 100644
--- a/sysdeps/generic/unwind-link.h
+++ b/sysdeps/generic/unwind-link.h
@@ -31,7 +31,7 @@ unwind_arch_adjustment (void *prev, void *addr)
 #endif
 
 #ifdef SHARED
-# include <sysdep.h>
+# include <pointer_guard.h>
 # include <unwind-resume.h>
 
 # if UNWIND_LINK_FRAME_STATE_FOR
diff --git a/sysdeps/i386/__longjmp.S b/sysdeps/i386/__longjmp.S
index 508d370d5c..b67781ceb7 100644
--- a/sysdeps/i386/__longjmp.S
+++ b/sysdeps/i386/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/i386/bsd-_setjmp.S b/sysdeps/i386/bsd-_setjmp.S
index 190e35b0c7..80399dba6e 100644
--- a/sysdeps/i386/bsd-_setjmp.S
+++ b/sysdeps/i386/bsd-_setjmp.S
@@ -21,6 +21,7 @@
    in setjmp doesn't clobber the state restored by longjmp.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <stap-probe.h>
diff --git a/sysdeps/i386/bsd-setjmp.S b/sysdeps/i386/bsd-setjmp.S
index 575ac96208..b367bad85f 100644
--- a/sysdeps/i386/bsd-setjmp.S
+++ b/sysdeps/i386/bsd-setjmp.S
@@ -21,6 +21,7 @@
    in setjmp doesn't clobber the state restored by longjmp.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <stap-probe.h>
diff --git a/sysdeps/i386/jmpbuf-unwind.h b/sysdeps/i386/jmpbuf-unwind.h
index 416c816b45..73d214fd31 100644
--- a/sysdeps/i386/jmpbuf-unwind.h
+++ b/sysdeps/i386/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/i386/setjmp.S b/sysdeps/i386/setjmp.S
index 217efbdf8a..b528245806 100644
--- a/sysdeps/i386/setjmp.S
+++ b/sysdeps/i386/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/loongarch/__longjmp.S b/sysdeps/loongarch/__longjmp.S
index d6a99fcbc8..4c40ffa158 100644
--- a/sysdeps/loongarch/__longjmp.S
+++ b/sysdeps/loongarch/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <sys/asm.h>
 
 ENTRY (__longjmp)
diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
index 6fa509151d..458edec135 100644
--- a/sysdeps/loongarch/jmpbuf-unwind.h
+++ b/sysdeps/loongarch/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/loongarch/setjmp.S b/sysdeps/loongarch/setjmp.S
index 9b1cdea48c..e5f480d453 100644
--- a/sysdeps/loongarch/setjmp.S
+++ b/sysdeps/loongarch/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <sys/asm.h>
 
 ENTRY (_setjmp)
diff --git a/sysdeps/m68k/jmpbuf-unwind.h b/sysdeps/m68k/jmpbuf-unwind.h
index 17e4b859ab..3ee46c050c 100644
--- a/sysdeps/m68k/jmpbuf-unwind.h
+++ b/sysdeps/m68k/jmpbuf-unwind.h
@@ -19,6 +19,7 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <unwind.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/mach/hurd/i386/____longjmp_chk.S b/sysdeps/mach/hurd/i386/____longjmp_chk.S
index 1a019e2e2b..81d297de0c 100644
--- a/sysdeps/mach/hurd/i386/____longjmp_chk.S
+++ b/sysdeps/mach/hurd/i386/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <tcb-offsets.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/mach/hurd/i386/__longjmp.S b/sysdeps/mach/hurd/i386/__longjmp.S
index 72fcc79f4b..22915fb21e 100644
--- a/sysdeps/mach/hurd/i386/__longjmp.S
+++ b/sysdeps/mach/hurd/i386/__longjmp.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <tcb-offsets.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/mach/hurd/jmp-unwind.c b/sysdeps/mach/hurd/jmp-unwind.c
index f8938bc6f4..2577fbf3ee 100644
--- a/sysdeps/mach/hurd/jmp-unwind.c
+++ b/sysdeps/mach/hurd/jmp-unwind.c
@@ -22,7 +22,7 @@
 #include <hurd/sigpreempt.h>
 #include <assert.h>
 #include <stdint.h>
-
+#include <pointer_guard.h>
 
 #ifndef _JMPBUF_UNWINDS
 #error "<jmpbuf-unwind.h> fails to define _JMPBUF_UNWINDS"
diff --git a/sysdeps/microblaze/jmpbuf-unwind.h b/sysdeps/microblaze/jmpbuf-unwind.h
index f23c7581a7..302e950ced 100644
--- a/sysdeps/microblaze/jmpbuf-unwind.h
+++ b/sysdeps/microblaze/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/mips/jmpbuf-unwind.h b/sysdeps/mips/jmpbuf-unwind.h
index 813c24f3b1..28ecffedb0 100644
--- a/sysdeps/mips/jmpbuf-unwind.h
+++ b/sysdeps/mips/jmpbuf-unwind.h
@@ -19,6 +19,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/nios2/__longjmp.S b/sysdeps/nios2/__longjmp.S
index 214901d67d..13695e25a6 100644
--- a/sysdeps/nios2/__longjmp.S
+++ b/sysdeps/nios2/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 /* __longjmp(jmpbuf, val) */
diff --git a/sysdeps/nios2/jmpbuf-offsets.h b/sysdeps/nios2/jmpbuf-offsets.h
index a13aa76c16..76fea64ffe 100644
--- a/sysdeps/nios2/jmpbuf-offsets.h
+++ b/sysdeps/nios2/jmpbuf-offsets.h
@@ -32,6 +32,7 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf jmpbuf)
diff --git a/sysdeps/nios2/setjmp.S b/sysdeps/nios2/setjmp.S
index 0aa5b23d4f..ec75108b87 100644
--- a/sysdeps/nios2/setjmp.S
+++ b/sysdeps/nios2/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 	.text
diff --git a/sysdeps/powerpc/jmpbuf-unwind.h b/sysdeps/powerpc/jmpbuf-unwind.h
index 706ceda5d4..93573ce238 100644
--- a/sysdeps/powerpc/jmpbuf-unwind.h
+++ b/sysdeps/powerpc/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/powerpc/powerpc32/__longjmp-common.S b/sysdeps/powerpc/powerpc32/__longjmp-common.S
index 13ded200e2..0e0361e4fd 100644
--- a/sysdeps/powerpc/powerpc32/__longjmp-common.S
+++ b/sysdeps/powerpc/powerpc32/__longjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #ifdef __NO_VMX__
diff --git a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
index e3937222a7..de04a62be2 100644
--- a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
+++ b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #ifdef __NO_VMX__
diff --git a/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S b/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
index f82196e6c2..1943ffd229 100644
--- a/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
+++ b/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #ifdef __NO_VMX__
diff --git a/sysdeps/powerpc/powerpc32/setjmp-common.S b/sysdeps/powerpc/powerpc32/setjmp-common.S
index c632a3f8f2..281dd65f6a 100644
--- a/sysdeps/powerpc/powerpc32/setjmp-common.S
+++ b/sysdeps/powerpc/powerpc32/setjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #ifdef __NO_VMX__
diff --git a/sysdeps/powerpc/powerpc64/__longjmp-common.S b/sysdeps/powerpc/powerpc64/__longjmp-common.S
index 5f629e1e0f..ff3e0beb23 100644
--- a/sysdeps/powerpc/powerpc64/__longjmp-common.S
+++ b/sysdeps/powerpc/powerpc64/__longjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #define _SETJMP_H
diff --git a/sysdeps/powerpc/powerpc64/setjmp-common.S b/sysdeps/powerpc/powerpc64/setjmp-common.S
index 19e76d59ee..75389e4d26 100644
--- a/sysdeps/powerpc/powerpc64/setjmp-common.S
+++ b/sysdeps/powerpc/powerpc64/setjmp-common.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <stap-probe.h>
 #define _ASM
 #ifdef __NO_VMX__
diff --git a/sysdeps/riscv/jmpbuf-unwind.h b/sysdeps/riscv/jmpbuf-unwind.h
index 28e73dda55..b411a246d1 100644
--- a/sysdeps/riscv/jmpbuf-unwind.h
+++ b/sysdeps/riscv/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/s390/jmpbuf-unwind.h b/sysdeps/s390/jmpbuf-unwind.h
index b4ff8da6e2..10b37f09c3 100644
--- a/sysdeps/s390/jmpbuf-unwind.h
+++ b/sysdeps/s390/jmpbuf-unwind.h
@@ -21,6 +21,7 @@
 #include <unwind.h>
 #include <bits/wordsize.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 
 /* Test if longjmp to JMPBUF would unwind the frame
diff --git a/sysdeps/s390/s390-32/__longjmp.c b/sysdeps/s390/s390-32/__longjmp.c
index 09a3a2b8f8..83d42329a3 100644
--- a/sysdeps/s390/s390-32/__longjmp.c
+++ b/sysdeps/s390/s390-32/__longjmp.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <setjmp.h>
 #include <bits/setjmp.h>
 #include <stdlib.h>
diff --git a/sysdeps/s390/s390-32/setjmp.S b/sysdeps/s390/s390-32/setjmp.S
index c15c7bb99a..08704238f8 100644
--- a/sysdeps/s390/s390-32/setjmp.S
+++ b/sysdeps/s390/s390-32/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #define _ASM
 #define _SETJMP_H
 #include <bits/setjmp.h>
diff --git a/sysdeps/s390/s390-64/__longjmp.c b/sysdeps/s390/s390-64/__longjmp.c
index 2ca96e1b1b..9fe4939e5e 100644
--- a/sysdeps/s390/s390-64/__longjmp.c
+++ b/sysdeps/s390/s390-64/__longjmp.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <setjmp.h>
 #include <bits/setjmp.h>
 #include <stdlib.h>
diff --git a/sysdeps/s390/s390-64/setjmp.S b/sysdeps/s390/s390-64/setjmp.S
index 6dcd77df15..5c59f571a2 100644
--- a/sysdeps/s390/s390-64/setjmp.S
+++ b/sysdeps/s390/s390-64/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #define _ASM
 #define _SETJMP_H
 #include <bits/setjmp.h>
diff --git a/sysdeps/sh/jmpbuf-unwind.h b/sysdeps/sh/jmpbuf-unwind.h
index c6672955ae..1957e5275d 100644
--- a/sysdeps/sh/jmpbuf-unwind.h
+++ b/sysdeps/sh/jmpbuf-unwind.h
@@ -19,6 +19,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/sh/sh3/__longjmp.S b/sysdeps/sh/sh3/__longjmp.S
index 4228b5fef7..f10bed2afe 100644
--- a/sysdeps/sh/sh3/__longjmp.S
+++ b/sysdeps/sh/sh3/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #define _SETJMP_H
 #define _ASM
 #include <bits/setjmp.h>
diff --git a/sysdeps/sh/sh3/setjmp.S b/sysdeps/sh/sh3/setjmp.S
index 0dd0003efe..363e16fb15 100644
--- a/sysdeps/sh/sh3/setjmp.S
+++ b/sysdeps/sh/sh3/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 ENTRY (__sigsetjmp)
diff --git a/sysdeps/sh/sh4/__longjmp.S b/sysdeps/sh/sh4/__longjmp.S
index 2013b71794..bc179e4584 100644
--- a/sysdeps/sh/sh4/__longjmp.S
+++ b/sysdeps/sh/sh4/__longjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #define _SETJMP_H
 #define _ASM
 #include <bits/setjmp.h>
diff --git a/sysdeps/sh/sh4/setjmp.S b/sysdeps/sh/sh4/setjmp.S
index b73aa3c18c..f28ec42091 100644
--- a/sysdeps/sh/sh4/setjmp.S
+++ b/sysdeps/sh/sh4/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 ENTRY (__sigsetjmp)
diff --git a/sysdeps/sparc/sparc32/__longjmp.S b/sysdeps/sparc/sparc32/__longjmp.S
index 5bed2440ac..68b3b15cb1 100644
--- a/sysdeps/sparc/sparc32/__longjmp.S
+++ b/sysdeps/sparc/sparc32/__longjmp.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 #include <jmpbuf-offsets.h>
 #define ENV(base,reg) [%base + (reg * 4)]
diff --git a/sysdeps/sparc/sparc32/jmpbuf-unwind.h b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
index 3ab5088555..8b697ed95b 100644
--- a/sysdeps/sparc/sparc32/jmpbuf-unwind.h
+++ b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/sparc/sparc32/setjmp.S b/sysdeps/sparc/sparc32/setjmp.S
index 9c7531bc95..c4e29c47b9 100644
--- a/sysdeps/sparc/sparc32/setjmp.S
+++ b/sysdeps/sparc/sparc32/setjmp.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <sys/trap.h>
 
 #include <jmpbuf-offsets.h>
diff --git a/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
new file mode 100644
index 0000000000..b81c9075f3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
@@ -0,0 +1,68 @@
+/* Pointer guard implementation.  AArch64 version.
+   Copyright (C) 2014-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+/* Pointer mangling is supported for AArch64.  */
+#if (IS_IN (rtld) \
+     || (!defined SHARED && (IS_IN (libc) \
+                             || IS_IN (libpthread))))
+# ifdef __ASSEMBLER__
+/* Note, dst, src, guard, and tmp are all register numbers rather than
+   register names so they will work with both ILP32 and LP64. */
+#  define PTR_MANGLE(dst, src, guard, tmp)                                \
+  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2 (dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor x##dst, x##src, x##guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#else
+# ifdef __ASSEMBLER__
+/* Note, dst, src, guard, and tmp are all register numbers rather than
+   register names so they will work with both ILP32 and LP64. */
+#  define PTR_MANGLE(dst, src, guard, tmp)                             \
+  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
+  PTR_MANGLE2 (dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor x##dst, x##src, x##guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+#  include <stdint.h>
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index f1853e012f..8ba50dab8f 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -233,49 +233,4 @@
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is supported for AArch64.  */
-#if (IS_IN (rtld) \
-     || (!defined SHARED && (IS_IN (libc) \
-			     || IS_IN (libpthread))))
-# ifdef __ASSEMBLER__
-/* Note, dst, src, guard, and tmp are all register numbers rather than
-   register names so they will work with both ILP32 and LP64. */
-#  define PTR_MANGLE(dst, src, guard, tmp)                                \
-  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
-  PTR_MANGLE2 (dst, src, guard)
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#  define PTR_MANGLE2(dst, src, guard)\
-  eor x##dst, x##src, x##guard
-#  define PTR_DEMANGLE(dst, src, guard, tmp)\
-  PTR_MANGLE (dst, src, guard, tmp)
-#  define PTR_DEMANGLE2(dst, src, guard)\
-  PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
-#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
-# endif
-#else
-# ifdef __ASSEMBLER__
-/* Note, dst, src, guard, and tmp are all register numbers rather than
-   register names so they will work with both ILP32 and LP64. */
-#  define PTR_MANGLE(dst, src, guard, tmp)                             \
-  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
-  PTR_MANGLE2 (dst, src, guard)
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#  define PTR_MANGLE2(dst, src, guard)\
-  eor x##dst, x##src, x##guard
-#  define PTR_DEMANGLE(dst, src, guard, tmp)\
-  PTR_MANGLE (dst, src, guard, tmp)
-#  define PTR_DEMANGLE2(dst, src, guard)\
-  PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard attribute_relro;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
-#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/aarch64/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S b/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
index 610f401d45..566a3b0211 100644
--- a/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 
diff --git a/sysdeps/unix/sysv/linux/alpha/pointer_guard.h b/sysdeps/unix/sysv/linux/alpha/pointer_guard.h
new file mode 100644
index 0000000000..d4d513d816
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/pointer_guard.h
@@ -0,0 +1,62 @@
+/* Pointer guard implementation.  Alpha version.
+   Copyright (C) 2006-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+/* Pointer mangling support.  Note that tls access is slow enough that
+   we don't deoptimize things by placing the pointer check value there.  */
+
+#ifdef __ASSEMBLER__
+# if IS_IN (rtld)
+#  define PTR_MANGLE(dst, src, tmp)                             \
+        ldah    tmp, __pointer_chk_guard_local($29) !gprelhigh; \
+        ldq     tmp, __pointer_chk_guard_local(tmp) !gprellow;  \
+        xor     src, tmp, dst
+#  define PTR_MANGLE2(dst, src, tmp)                            \
+        xor     src, tmp, dst
+# elif defined SHARED
+#  define PTR_MANGLE(dst, src, tmp)             \
+        ldq     tmp, __pointer_chk_guard;       \
+        xor     src, tmp, dst
+# else
+#  define PTR_MANGLE(dst, src, tmp)             \
+        ldq     tmp, __pointer_chk_guard_local; \
+        xor     src, tmp, dst
+# endif
+# define PTR_MANGLE2(dst, src, tmp)             \
+        xor     src, tmp, dst
+# define PTR_DEMANGLE(dst, tmp)   PTR_MANGLE(dst, dst, tmp)
+# define PTR_DEMANGLE2(dst, tmp)  PTR_MANGLE2(dst, dst, tmp)
+#else
+# include <stdint.h>
+# if (IS_IN (rtld) \
+      || (!defined SHARED && (IS_IN (libc) \
+                              || IS_IN (libpthread))))
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+        (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+        (var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+# endif
+# define PTR_DEMANGLE(var)  PTR_MANGLE(var)
+#endif /* ASSEMBLER */
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep.h b/sysdeps/unix/sysv/linux/alpha/sysdep.h
index 77ec2b5400..0ddcb58b30 100644
--- a/sysdeps/unix/sysv/linux/alpha/sysdep.h
+++ b/sysdeps/unix/sysv/linux/alpha/sysdep.h
@@ -313,44 +313,4 @@ __LABEL(name)						\
 })
 #endif /* ASSEMBLER */
 
-/* Pointer mangling support.  Note that tls access is slow enough that
-   we don't deoptimize things by placing the pointer check value there.  */
-
-#ifdef __ASSEMBLER__
-# if IS_IN (rtld)
-#  define PTR_MANGLE(dst, src, tmp)				\
-	ldah	tmp, __pointer_chk_guard_local($29) !gprelhigh;	\
-	ldq	tmp, __pointer_chk_guard_local(tmp) !gprellow;	\
-	xor	src, tmp, dst
-#  define PTR_MANGLE2(dst, src, tmp)				\
-	xor	src, tmp, dst
-# elif defined SHARED
-#  define PTR_MANGLE(dst, src, tmp)		\
-	ldq	tmp, __pointer_chk_guard;	\
-	xor	src, tmp, dst
-# else
-#  define PTR_MANGLE(dst, src, tmp)		\
-	ldq	tmp, __pointer_chk_guard_local;	\
-	xor	src, tmp, dst
-# endif
-# define PTR_MANGLE2(dst, src, tmp)		\
-	xor	src, tmp, dst
-# define PTR_DEMANGLE(dst, tmp)   PTR_MANGLE(dst, dst, tmp)
-# define PTR_DEMANGLE2(dst, tmp)  PTR_MANGLE2(dst, dst, tmp)
-#else
-# include <stdint.h>
-# if (IS_IN (rtld) \
-      || (!defined SHARED && (IS_IN (libc) \
-			      || IS_IN (libpthread))))
-extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
-#  define PTR_MANGLE(var) \
-	(var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
-# else
-extern uintptr_t __pointer_chk_guard attribute_relro;
-#  define PTR_MANGLE(var) \
-	(var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
-# endif
-# define PTR_DEMANGLE(var)  PTR_MANGLE(var)
-#endif /* ASSEMBLER */
-
 #endif /* _LINUX_ALPHA_SYSDEP_H  */
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
index d0c1a78381..512284a705 100644
--- a/sysdeps/unix/sysv/linux/arc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
@@ -215,10 +215,6 @@ hidden_proto (__syscall_error)
   LOAD_ARGS_6 (nm, arg1, arg2, arg3, arg4, arg5, arg6)	\
   register long int _arg7 __asm__ ("r6") = _tmp7;
 
-/* Pointer mangling not yet supported.  */
-# define PTR_MANGLE(var) (void) (var)
-# define PTR_DEMANGLE(var) (void) (var)
-
 # undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
 # define HAVE_INTERNAL_BRK_ADDR_SYMBOL  1
 
diff --git a/sysdeps/unix/sysv/linux/csky/pointer_guard.h b/sysdeps/unix/sysv/linux/csky/pointer_guard.h
new file mode 100644
index 0000000000..ed683220c9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/pointer_guard.h
@@ -0,0 +1,68 @@
+/* Pointer obfuscation implenentation.  C-SKY version.
+   Copyright (C) 2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if (IS_IN (rtld) \
+     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard)                   \
+        grs     t0, 1f;                                 \
+1:                                                      \
+        lrw     guard, 1b@GOTPC;                        \
+        addu    t0, guard;                              \
+        lrw     guard, __pointer_chk_guard_local@GOT;   \
+        ldr.w   guard, (t0, guard << 0);                \
+        ldw     guard, (guard, 0);                      \
+        xor     dst, src, guard;
+#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
+#  define PTR_MANGLE2(dst, src, guard) \
+        xor     dst, src, guard
+#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard)           \
+        grs     t0, 1f;                         \
+1:                                              \
+        lrw     guard, 1b@GOTPC;                \
+        addu    t0, guard;                      \
+        lrw     guard, __pointer_chk_guard@GOT; \
+        ldr.w   guard, (t0, guard << 0);        \
+        ldw     guard, (guard, 0);              \
+        xor     dst, src, guard;
+#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
+#  define PTR_MANGLE2(dst, src, guard) \
+        xor     dst, src, guard
+#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
+# else
+# include <stdint.h>
+extern uintptr_t __pointer_chk_guard;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/csky/sysdep.h b/sysdeps/unix/sysv/linux/csky/sysdep.h
index 56c527fa8b..76b09f0cc6 100644
--- a/sysdeps/unix/sysv/linux/csky/sysdep.h
+++ b/sysdeps/unix/sysv/linux/csky/sysdep.h
@@ -466,50 +466,4 @@ __local_syscall_error:				\
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if (IS_IN (rtld) \
-     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(dst, src, guard)			\
-	grs	t0, 1f;					\
-1:							\
-	lrw	guard, 1b@GOTPC;			\
-	addu	t0, guard;				\
-	lrw	guard, __pointer_chk_guard_local@GOT;	\
-	ldr.w	guard, (t0, guard << 0);		\
-	ldw	guard, (guard, 0);			\
-	xor	dst, src, guard;
-#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
-#  define PTR_MANGLE2(dst, src, guard) \
-	xor	dst, src, guard
-#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard_local;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
-#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
-# endif
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(dst, src, guard)		\
-	grs	t0, 1f;				\
-1:						\
-	lrw	guard, 1b@GOTPC;		\
-	addu	t0, guard;			\
-	lrw	guard, __pointer_chk_guard@GOT;	\
-	ldr.w	guard, (t0, guard << 0);	\
-	ldw	guard, (guard, 0);		\
-	xor	dst, src, guard;
-#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
-#  define PTR_MANGLE2(dst, src, guard) \
-	xor	dst, src, guard
-#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
-# else
-extern uintptr_t __pointer_chk_guard;
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
-#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/csky/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.h b/sysdeps/unix/sysv/linux/hppa/sysdep.h
index 2f339a4bd6..3aef8f536a 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep.h
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep.h
@@ -470,8 +470,4 @@ L(pre_end):					ASM_LINE_SEP	\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for HPPA.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 #endif /* _LINUX_HPPA_SYSDEP_H */
diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
index a1cf9a4b21..f409542a62 100644
--- a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/unix/sysv/linux/i386/pointer_guard.h b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
new file mode 100644
index 0000000000..a2d2a0c38b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
@@ -0,0 +1,49 @@
+/* Pointer obfuscation implenentation.  i386 version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#include <tcb-offsets.h>
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  Using a global variable
+   is too complicated here since we have no PC-relative addressing mode.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg)       xorl %gs:POINTER_GUARD, reg;                  \
+                                roll $9, reg
+#  define PTR_DEMANGLE(reg)     rorl $9, reg;                                 \
+                                xorl %gs:POINTER_GUARD, reg
+# else
+#  define PTR_MANGLE(var)       asm ("xorl %%gs:%c2, %0\n"                    \
+                                     "roll $9, %0"                            \
+                                     : "=r" (var)                             \
+                                     : "0" (var),                             \
+                                       "i" (POINTER_GUARD))
+#  define PTR_DEMANGLE(var)     asm ("rorl $9, %0\n"                          \
+                                     "xorl %%gs:%c2, %0"                      \
+                                     : "=r" (var)                             \
+                                     : "0" (var),                             \
+                                       "i" (POINTER_GUARD))
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 7085f7e19a..b8be668a42 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -446,34 +446,6 @@ struct libc_do_syscall_args
 
 #endif	/* __ASSEMBLER__ */
 
-
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  Using a global variable
-   is too complicated here since we have no PC-relative addressing mode.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg)	xorl %gs:POINTER_GUARD, reg;		      \
-				roll $9, reg
-#  define PTR_DEMANGLE(reg)	rorl $9, reg;				      \
-				xorl %gs:POINTER_GUARD, reg
-# else
-#  define PTR_MANGLE(var)	asm ("xorl %%gs:%c2, %0\n"		      \
-				     "roll $9, %0"			      \
-				     : "=r" (var)			      \
-				     : "0" (var),			      \
-				       "i" (offsetof (tcbhead_t,	      \
-						      pointer_guard)))
-#  define PTR_DEMANGLE(var)	asm ("rorl $9, %0\n"			      \
-				     "xorl %%gs:%c2, %0"		      \
-				     : "=r" (var)			      \
-				     : "0" (var),			      \
-				       "i" (offsetof (tcbhead_t,	      \
-						      pointer_guard)))
-# endif
-#endif
-
 /* Each shadow stack slot takes 4 bytes.  Assuming that each stack
    frame takes 128 bytes, this is used to compute shadow stack size
    from stack size.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S b/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
index 9511c15945..4ef5129623 100644
--- a/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
+++ b/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
@@ -15,6 +15,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <features.h>
 
 LEAF(__ia64_flush_rbs)
diff --git a/sysdeps/unix/sysv/linux/ia64/__longjmp.S b/sysdeps/unix/sysv/linux/ia64/__longjmp.S
index 793dc98cc1..da9653d8a7 100644
--- a/sysdeps/unix/sysv/linux/ia64/__longjmp.S
+++ b/sysdeps/unix/sysv/linux/ia64/__longjmp.S
@@ -31,6 +31,7 @@
 		bits into ar.rnat after setting ar.bspstore. */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <features.h>
 
 #	define	pPos	p6	/* is rotate count positive? */
diff --git a/sysdeps/unix/sysv/linux/ia64/pointer_guard.h b/sysdeps/unix/sysv/linux/ia64/pointer_guard.h
new file mode 100644
index 0000000000..8631f39374
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ia64/pointer_guard.h
@@ -0,0 +1,44 @@
+/* Pointer obfuscation implenentation.  ia64 version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg, tmpreg) \
+        add     tmpreg=-16,r13          \
+        ;;                              \
+        ld8     tmpreg=[tmpreg]         \
+        ;;                              \
+        xor     reg=reg, tmpreg
+#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/ia64/setjmp.S b/sysdeps/unix/sysv/linux/ia64/setjmp.S
index c29a31f7a6..a978dd4360 100644
--- a/sysdeps/unix/sysv/linux/ia64/setjmp.S
+++ b/sysdeps/unix/sysv/linux/ia64/setjmp.S
@@ -63,6 +63,7 @@
 	0x1c0	f31 */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <features.h>
 
 	/* The following two entry points are the traditional entry points: */
diff --git a/sysdeps/unix/sysv/linux/ia64/sysdep.h b/sysdeps/unix/sysv/linux/ia64/sysdep.h
index 14adbdf4ff..b450c6c224 100644
--- a/sysdeps/unix/sysv/linux/ia64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/ia64/sysdep.h
@@ -324,24 +324,4 @@
 
 #endif /* not __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg, tmpreg) \
-        add	tmpreg=-16,r13		\
-        ;;				\
-        ld8	tmpreg=[tmpreg]		\
-        ;;				\
-        xor	reg=reg, tmpreg
-#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/ia64/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h b/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
new file mode 100644
index 0000000000..4b2ed46167
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
@@ -0,0 +1,82 @@
+/* Pointer obfuscation implenentation.  LoongArch version.
+   Copyright (C) 2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+/* Load a got-relative EXPR into G, using T.
+   Note G and T are register names.  */
+#define LD_GLOBAL(G, EXPR) \
+  la.global G,  EXPR; \
+  REG_L     G,  G,  0;
+
+/* Load a pc-relative EXPR into G, using T.
+   Note G and T are register names.  */
+#define LD_PCREL(G, EXPR) \
+  la.pcrel  G,  EXPR; \
+  REG_L     G,  G,  0;
+
+#if (IS_IN (rtld) \
+     || (!defined SHARED && (IS_IN (libc) \
+     || IS_IN (libpthread))))
+
+#ifdef __ASSEMBLER__
+#define PTR_MANGLE(dst, src, guard) \
+  LD_PCREL (guard, __pointer_chk_guard_local); \
+  PTR_MANGLE2 (dst, src, guard);
+#define PTR_DEMANGLE(dst, src, guard) \
+  LD_PCREL (guard, __pointer_chk_guard_local); \
+  PTR_DEMANGLE2 (dst, src, guard);
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#define PTR_MANGLE2(dst, src, guard) \
+  xor  dst, src, guard;
+#define PTR_DEMANGLE2(dst, src, guard) \
+  PTR_MANGLE2 (dst, src, guard);
+#else
+# include <stdint.h>
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#define PTR_DEMANGLE(var) PTR_MANGLE (var)
+#endif
+
+#else
+
+#ifdef __ASSEMBLER__
+#define PTR_MANGLE(dst, src, guard) \
+  LD_GLOBAL (guard, __pointer_chk_guard); \
+  PTR_MANGLE2 (dst, src, guard);
+#define PTR_DEMANGLE(dst, src, guard) \
+  LD_GLOBAL (guard, __pointer_chk_guard); \
+  PTR_DEMANGLE2 (dst, src, guard);
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#define PTR_MANGLE2(dst, src, guard) \
+  xor dst, src, guard;
+#define PTR_DEMANGLE2(dst, src, guard) \
+  PTR_MANGLE2 (dst, src, guard);
+#else
+# include <stdint.h>
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#define PTR_DEMANGLE(var) PTR_MANGLE (var)
+#endif
+
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
index f4a1d23a97..09f8243f25 100644
--- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h
+++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
@@ -314,64 +314,4 @@ extern long int __syscall_error (long int neg_errno);
 
 #endif /* ! __ASSEMBLER__ */
 
-/* Pointer mangling is supported for LoongArch.  */
-
-/* Load a got-relative EXPR into G, using T.
-   Note G and T are register names.  */
-#define LD_GLOBAL(G, EXPR) \
-  la.global G,	EXPR; \
-  REG_L	    G,	G,  0;
-
-/* Load a pc-relative EXPR into G, using T.
-   Note G and T are register names.  */
-#define LD_PCREL(G, EXPR) \
-  la.pcrel  G,	EXPR; \
-  REG_L	    G,	G,  0;
-
-#if (IS_IN (rtld) \
-     || (!defined SHARED && (IS_IN (libc) \
-     || IS_IN (libpthread))))
-
-#ifdef __ASSEMBLER__
-#define PTR_MANGLE(dst, src, guard) \
-  LD_PCREL (guard, __pointer_chk_guard_local); \
-  PTR_MANGLE2 (dst, src, guard);
-#define PTR_DEMANGLE(dst, src, guard) \
-  LD_PCREL (guard, __pointer_chk_guard_local); \
-  PTR_DEMANGLE2 (dst, src, guard);
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#define PTR_MANGLE2(dst, src, guard) \
-  xor  dst, src, guard;
-#define PTR_DEMANGLE2(dst, src, guard) \
-  PTR_MANGLE2 (dst, src, guard);
-#else
-extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
-#define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
-#define PTR_DEMANGLE(var) PTR_MANGLE (var)
-#endif
-
-#else
-
-#ifdef __ASSEMBLER__
-#define PTR_MANGLE(dst, src, guard) \
-  LD_GLOBAL (guard, __pointer_chk_guard); \
-  PTR_MANGLE2 (dst, src, guard);
-#define PTR_DEMANGLE(dst, src, guard) \
-  LD_GLOBAL (guard, __pointer_chk_guard); \
-  PTR_DEMANGLE2 (dst, src, guard);
-/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
-#define PTR_MANGLE2(dst, src, guard) \
-  xor dst, src, guard;
-#define PTR_DEMANGLE2(dst, src, guard) \
-  PTR_MANGLE2 (dst, src, guard);
-#else
-extern uintptr_t __pointer_chk_guard attribute_relro;
-#define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
-#define PTR_DEMANGLE(var) PTR_MANGLE (var)
-#endif
-
-#endif
-
 #endif /* linux/loongarch/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep.h b/sysdeps/unix/sysv/linux/m68k/sysdep.h
index d87892a377..064240330a 100644
--- a/sysdeps/unix/sysv/linux/m68k/sysdep.h
+++ b/sysdeps/unix/sysv/linux/m68k/sysdep.h
@@ -295,10 +295,6 @@ SYSCALL_ERROR_LABEL:							      \
 
 #endif /* not __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for M68K.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 /* M68K needs system-supplied DSO to access TLS helpers
    even when statically linked.  */
 #define NEED_STATIC_SYSINFO_DSO 1
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
index fda78f6467..19805f6b5d 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
@@ -304,10 +304,6 @@ SYSCALL_ERROR_LABEL_DCL:                            \
   })
 
 
-/* Pointer mangling is not yet supported for Microblaze.  */
-# define PTR_MANGLE(var) (void) (var)
-# define PTR_DEMANGLE(var) (void) (var)
-
 #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
 #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
 
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
index a2a93bc840..0ef410c3c9 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
@@ -337,8 +337,4 @@ libc_hidden_proto (__mips_syscall7, nomips16)
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for MIPS.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 #endif /* linux/mips/mips32/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
index 2c16a6758d..e362f15300 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
@@ -300,8 +300,4 @@ typedef long int __syscall_arg_t;
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for MIPS.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 #endif /* linux/mips/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/nios2/pointer_guard.h b/sysdeps/unix/sysv/linux/nios2/pointer_guard.h
new file mode 100644
index 0000000000..da17809592
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nios2/pointer_guard.h
@@ -0,0 +1,40 @@
+/* Pointer obfuscation implenentation.  Nios II version.
+   Copyright (C) 2015-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23)
+#  define PTR_MANGLE(dst, src, guard) xor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.h b/sysdeps/unix/sysv/linux/nios2/sysdep.h
index 5fe960c2a5..46667b9c19 100644
--- a/sysdeps/unix/sysv/linux/nios2/sysdep.h
+++ b/sysdeps/unix/sysv/linux/nios2/sysdep.h
@@ -220,21 +220,4 @@
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23)
-#  define PTR_MANGLE(dst, src, guard) xor dst, src, guard
-#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
-
 #endif /* linux/nios2/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/or1k/sysdep.h b/sysdeps/unix/sysv/linux/or1k/sysdep.h
index 941c934554..b1fdf2a806 100644
--- a/sysdeps/unix/sysv/linux/or1k/sysdep.h
+++ b/sysdeps/unix/sysv/linux/or1k/sysdep.h
@@ -119,10 +119,6 @@ L(pseudo_end): \
 
 extern long int __syscall_error (long int neg_errno);
 
-/* Pointer mangling is not yet supported for or1k.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 #undef INTERNAL_SYSCALL
 #define INTERNAL_SYSCALL(name, nr, args...) \
 	INTERNAL_SYSCALL_NCS (SYS_ify (name), nr, args)
diff --git a/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h b/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
new file mode 100644
index 0000000000..5961793c0d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
@@ -0,0 +1,55 @@
+/* Pointer obfuscation implenentation.  PowerpC version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  if defined(__PPC64__) || defined(__powerpc64__)
+#   define LOAD  ld
+#   define TPREG r13
+#  else
+#   define LOAD  lwz
+#   define TPREG r2
+#  endif
+#  define PTR_MANGLE(reg, tmpreg) \
+        LOAD    tmpreg,POINTER_GUARD(TPREG); \
+        xor     reg,tmpreg,reg
+#  define PTR_MANGLE2(reg, tmpreg) \
+        xor     reg,tmpreg,reg
+#  define PTR_MANGLE3(destreg, reg, tmpreg) \
+        LOAD    tmpreg,POINTER_GUARD(TPREG); \
+        xor     destreg,tmpreg,reg
+#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+#  define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
+#  define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
index 4fb135aa8d..9e44818978 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
@@ -207,38 +207,6 @@
 #define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
 #define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
 
-
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-# ifdef __ASSEMBLER__
-#  if defined(__PPC64__) || defined(__powerpc64__)
-#   define LOAD  ld
-#   define TPREG r13
-#  else
-#   define LOAD  lwz
-#   define TPREG r2
-#  endif
-#  define PTR_MANGLE(reg, tmpreg) \
-	LOAD	tmpreg,POINTER_GUARD(TPREG); \
-	xor	reg,tmpreg,reg
-#  define PTR_MANGLE2(reg, tmpreg) \
-	xor	reg,tmpreg,reg
-#  define PTR_MANGLE3(destreg, reg, tmpreg) \
-	LOAD	tmpreg,POINTER_GUARD(TPREG); \
-	xor	destreg,tmpreg,reg
-#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
-#  define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
-#  define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
 /* List of system calls which are supported as vsyscalls.  */
 #define VDSO_NAME  "LINUX_2.6.15"
 #define VDSO_HASH  123718565
diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
index 9b03b10567..c9af888132 100644
--- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
+++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
@@ -357,8 +357,4 @@ extern long int __syscall_error (long int neg_errno);
 
 #endif /* ! __ASSEMBLER__ */
 
-/* Pointer mangling is not supported.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
-
 #endif /* linux/riscv/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h b/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
new file mode 100644
index 0000000000..0e85d4ccbb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
@@ -0,0 +1,45 @@
+/* Pointer obfuscation implenentation.  s390 version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+/* For the time being just use stack_guard rather than a separate
+   pointer_guard.  */
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg, tmpreg) \
+  ear     tmpreg,%a0;                   \
+  x       reg,STACK_GUARD(tmpreg)
+#  define PTR_MANGLE2(reg, tmpreg) \
+  x       reg,STACK_GUARD(tmpreg)
+#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
index e41106b377..a24fde7c6d 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
@@ -177,25 +177,4 @@
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-/* For the time being just use stack_guard rather than a separate
-   pointer_guard.  */
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg, tmpreg) \
-  ear     tmpreg,%a0;			\
-  x       reg,STACK_GUARD(tmpreg)
-#  define PTR_MANGLE2(reg, tmpreg) \
-  x       reg,STACK_GUARD(tmpreg)
-#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* _LINUX_S390_SYSDEP_H */
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h b/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
new file mode 100644
index 0000000000..5285456806
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
@@ -0,0 +1,47 @@
+/* Pointer obfuscation implenentation.  s390x version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+/* For the time being just use stack_guard rather than a separate
+   pointer_guard.  */
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg, tmpreg) \
+  ear     tmpreg,%a0;			\
+  sllg    tmpreg,tmpreg,32;		\
+  ear     tmpreg,%a1;			\
+  xg      reg,STACK_GUARD(tmpreg)
+#  define PTR_MANGLE2(reg, tmpreg) \
+  xg      reg,STACK_GUARD(tmpreg)
+#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
index 150e33981a..79bc0fa4a6 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
@@ -175,27 +175,4 @@
 
 #endif /* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-/* For the time being just use stack_guard rather than a separate
-   pointer_guard.  */
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg, tmpreg) \
-  ear     tmpreg,%a0;			\
-  sllg    tmpreg,tmpreg,32;		\
-  ear     tmpreg,%a1;			\
-  xg      reg,STACK_GUARD(tmpreg)
-#  define PTR_MANGLE2(reg, tmpreg) \
-  xg      reg,STACK_GUARD(tmpreg)
-#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* _LINUX_S390_SYSDEP_H */
diff --git a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
index e821e158c4..cf69926316 100644
--- a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 #include <sigaltstack-offsets.h>
 
diff --git a/sysdeps/unix/sysv/linux/sh/pointer_guard.h b/sysdeps/unix/sysv/linux/sh/pointer_guard.h
new file mode 100644
index 0000000000..32a571d496
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sh/pointer_guard.h
@@ -0,0 +1,43 @@
+/* Pointer obfuscation implenentation.  Generic (no-op) version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  Using a global variable
+   is too complicated here since we have no PC-relative addressing mode.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg, tmp) \
+     stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
+#  define PTR_MANGLE2(reg, tmp) xor tmp,reg
+#  define PTR_DEMANGLE(reg, tmp)        PTR_MANGLE (reg, tmp)
+#  define PTR_DEMANGLE2(reg, tmp)       PTR_MANGLE2 (reg, tmp)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+     (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep.h b/sysdeps/unix/sysv/linux/sh/sysdep.h
index e9e13cd184..a2f43f68c3 100644
--- a/sysdeps/unix/sysv/linux/sh/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sh/sysdep.h
@@ -315,23 +315,4 @@
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  Using a global variable
-   is too complicated here since we have no PC-relative addressing mode.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg, tmp) \
-     stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
-#  define PTR_MANGLE2(reg, tmp)	xor tmp,reg
-#  define PTR_DEMANGLE(reg, tmp)	PTR_MANGLE (reg, tmp)
-#  define PTR_DEMANGLE2(reg, tmp)	PTR_MANGLE2 (reg, tmp)
-# else
-#  define PTR_MANGLE(var) \
-     (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/sh/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
index 8e8cb4d751..ad23840bcd 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 #define ENV(base,reg) [%base + (reg * 4)]
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h b/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
new file mode 100644
index 0000000000..4063513cd8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
@@ -0,0 +1,44 @@
+/* Pointer obfuscation implenentation.  32-bit SPARC version.
+   Copyright (C) 2006-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dreg, reg, tmpreg) \
+  ld    [%g7 + POINTER_GUARD], tmpreg; \
+  xor   reg, tmpreg, dreg
+#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
+#  define PTR_MANGLE2(dreg, reg, tmpreg) \
+  xor   reg, tmpreg, dreg
+#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
index 032608a4e0..1783af8178 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
@@ -125,24 +125,4 @@ ENTRY(name);					\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(dreg, reg, tmpreg) \
-  ld	[%g7 + POINTER_GUARD], tmpreg; \
-  xor	reg, tmpreg, dreg
-#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
-#  define PTR_MANGLE2(dreg, reg, tmpreg) \
-  xor	reg, tmpreg, dreg
-#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/sparc/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h b/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
new file mode 100644
index 0000000000..7865e87c73
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
@@ -0,0 +1,44 @@
+/* Pointer obfuscation implenentation.  64-bit SPARC version.
+   Copyright (C) 2006-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# include <sysdeps/generic/pointer_guard.h>
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dreg, reg, tmpreg) \
+  ldx   [%g7 + POINTER_GUARD], tmpreg; \
+  xor   reg, tmpreg, dreg
+#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
+#  define PTR_MANGLE2(dreg, reg, tmpreg) \
+  xor   reg, tmpreg, dreg
+#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
+# else
+#  include <stdint.h>
+#  include <tls.h>
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
index 4aaa2912ce..4ae22ae25b 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
@@ -127,24 +127,4 @@ ENTRY(name);					\
    register windows.  So if you poke stack memory directly you add this.  */
 #define STACK_BIAS	2047
 
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(dreg, reg, tmpreg) \
-  ldx	[%g7 + POINTER_GUARD], tmpreg; \
-  xor	reg, tmpreg, dreg
-#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
-#  define PTR_MANGLE2(dreg, reg, tmpreg) \
-  xor	reg, tmpreg, dreg
-#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
-# else
-#  define PTR_MANGLE(var) \
-  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
-#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
-# endif
-#endif
-
 #endif /* linux/sparc64/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index ffdf4624bf..5ff275c436 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <asm-syntax.h>
 #include <stap-probe.h>
diff --git a/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h b/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
new file mode 100644
index 0000000000..2df3912897
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
@@ -0,0 +1,61 @@
+/* Pointer obfuscation implenentation.  x86-64 version.
+   Copyright (C) 2005-2022 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 POINTER_GUARD_H
+#define POINTER_GUARD_H
+
+#include <x86-lp_size.h>
+#include <tcb-offsets.h>
+
+#if IS_IN (rtld)
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+   earlier than the descriptor is initialized.  */
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg)       xor __pointer_chk_guard_local(%rip), reg;    \
+                                rol $2*LP_SIZE+1, reg
+#  define PTR_DEMANGLE(reg)     ror $2*LP_SIZE+1, reg;                       \
+                                xor __pointer_chk_guard_local(%rip), reg
+# else
+#  define PTR_MANGLE(reg)       asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
+                                     "rol $2*" LP_SIZE "+1, %0"                   \
+                                     : "=r" (reg) : "0" (reg))
+#  define PTR_DEMANGLE(reg)     asm ("ror $2*" LP_SIZE "+1, %0\n"                 \
+                                     "xor __pointer_chk_guard_local(%%rip), %0"   \
+                                     : "=r" (reg) : "0" (reg))
+# endif
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(reg)       xor %fs:POINTER_GUARD, reg;                   \
+                                rol $2*LP_SIZE+1, reg
+#  define PTR_DEMANGLE(reg)     ror $2*LP_SIZE+1, reg;                        \
+                                xor %fs:POINTER_GUARD, reg
+# else
+#  define PTR_MANGLE(var)       asm ("xor %%fs:%c2, %0\n"                     \
+                                     "rol $2*" LP_SIZE "+1, %0"               \
+                                     : "=r" (var)                             \
+                                     : "0" (var),                             \
+                                       "i" (POINTER_GUARD))
+#  define PTR_DEMANGLE(var)     asm ("ror $2*" LP_SIZE "+1, %0\n"             \
+                                     "xor %%fs:%c2, %0"                       \
+                                     : "=r" (var)                             \
+                                     : "0" (var),                             \
+                                       "i" (POINTER_GUARD))
+# endif
+#endif
+
+#endif /* POINTER_GUARD_H */
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 740abefcfd..5e4d7827d7 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -381,46 +381,6 @@
 
 #endif	/* __ASSEMBLER__ */
 
-
-/* Pointer mangling support.  */
-#if IS_IN (rtld)
-/* We cannot use the thread descriptor because in ld.so we use setjmp
-   earlier than the descriptor is initialized.  */
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg)	xor __pointer_chk_guard_local(%rip), reg;    \
-				rol $2*LP_SIZE+1, reg
-#  define PTR_DEMANGLE(reg)	ror $2*LP_SIZE+1, reg;			     \
-				xor __pointer_chk_guard_local(%rip), reg
-# else
-#  define PTR_MANGLE(reg)	asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
-				     "rol $2*" LP_SIZE "+1, %0"			  \
-				     : "=r" (reg) : "0" (reg))
-#  define PTR_DEMANGLE(reg)	asm ("ror $2*" LP_SIZE "+1, %0\n"		  \
-				     "xor __pointer_chk_guard_local(%%rip), %0"   \
-				     : "=r" (reg) : "0" (reg))
-# endif
-#else
-# ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg)	xor %fs:POINTER_GUARD, reg;		      \
-				rol $2*LP_SIZE+1, reg
-#  define PTR_DEMANGLE(reg)	ror $2*LP_SIZE+1, reg;			      \
-				xor %fs:POINTER_GUARD, reg
-# else
-#  define PTR_MANGLE(var)	asm ("xor %%fs:%c2, %0\n"		      \
-				     "rol $2*" LP_SIZE "+1, %0"		      \
-				     : "=r" (var)			      \
-				     : "0" (var),			      \
-				       "i" (offsetof (tcbhead_t,	      \
-						      pointer_guard)))
-#  define PTR_DEMANGLE(var)	asm ("ror $2*" LP_SIZE "+1, %0\n"	      \
-				     "xor %%fs:%c2, %0"			      \
-				     : "=r" (var)			      \
-				     : "0" (var),			      \
-				       "i" (offsetof (tcbhead_t,	      \
-						      pointer_guard)))
-# endif
-#endif
-
 /* How to pass the off{64}_t argument on p{readv,writev}{64}.  */
 #undef LO_HI_LONG
 #define LO_HI_LONG(val) (val), 0
diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S
index b51d79168c..6fdb4ccfbf 100644
--- a/sysdeps/x86_64/__longjmp.S
+++ b/sysdeps/x86_64/__longjmp.S
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/x86_64/jmpbuf-unwind.h b/sysdeps/x86_64/jmpbuf-unwind.h
index 42ea37508e..c92b2633bc 100644
--- a/sysdeps/x86_64/jmpbuf-unwind.h
+++ b/sysdeps/x86_64/jmpbuf-unwind.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <unwind.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 /* Test if longjmp to JMPBUF would unwind the frame
    containing a local variable at ADDRESS.  */
diff --git a/sysdeps/x86_64/setjmp.S b/sysdeps/x86_64/setjmp.S
index 1b77dcd4f9..3897e66dc4 100644
--- a/sysdeps/x86_64/setjmp.S
+++ b/sysdeps/x86_64/setjmp.S
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <jmp_buf-ssp.h>
 #include <asm-syntax.h>
diff --git a/sysdeps/x86_64/x32/x86-lp_size.h b/sysdeps/x86_64/x32/x86-lp_size.h
index ad03eb66b2..0b71e58be5 100644
--- a/sysdeps/x86_64/x32/x86-lp_size.h
+++ b/sysdeps/x86_64/x32/x86-lp_size.h
@@ -1,4 +1,4 @@
-/* Pointer size definition for x86-64 x42.
+/* Pointer size definition for x86-64 x32.
    Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
diff --git a/wcsmbs/btowc.c b/wcsmbs/btowc.c
index 21e52a67f4..7023ec99f1 100644
--- a/wcsmbs/btowc.c
+++ b/wcsmbs/btowc.c
@@ -24,7 +24,7 @@
 #include <wcsmbsload.h>
 #include <limits.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 wint_t
diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
index b23d9b0160..f8b029b58a 100644
--- a/wcsmbs/mbrtoc16.c
+++ b/wcsmbs/mbrtoc16.c
@@ -22,7 +22,7 @@
 #include <uchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/mbrtoc8.c b/wcsmbs/mbrtoc8.c
index dd80b5282d..e745a49e09 100644
--- a/wcsmbs/mbrtoc8.c
+++ b/wcsmbs/mbrtoc8.c
@@ -23,8 +23,6 @@
 #include <uchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
-
 #ifndef EILSEQ
 # define EILSEQ EINVAL
 #endif
diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
index 78d9994f67..46a1cc38df 100644
--- a/wcsmbs/mbrtowc.c
+++ b/wcsmbs/mbrtowc.c
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/mbsnrtowcs.c b/wcsmbs/mbsnrtowcs.c
index 5860822400..06a1f2d36f 100644
--- a/wcsmbs/mbsnrtowcs.c
+++ b/wcsmbs/mbsnrtowcs.c
@@ -23,7 +23,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/mbsrtowcs_l.c b/wcsmbs/mbsrtowcs_l.c
index 0ebc389fdb..526b88e1dd 100644
--- a/wcsmbs/mbsrtowcs_l.c
+++ b/wcsmbs/mbsrtowcs_l.c
@@ -27,7 +27,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c
index c0cce3792f..42690f2efd 100644
--- a/wcsmbs/wcrtomb.c
+++ b/wcsmbs/wcrtomb.c
@@ -25,7 +25,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/wcsnrtombs.c b/wcsmbs/wcsnrtombs.c
index 9707f6f4bc..6ba180cdc2 100644
--- a/wcsmbs/wcsnrtombs.c
+++ b/wcsmbs/wcsnrtombs.c
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c
index b1ac704b28..7db2b181b3 100644
--- a/wcsmbs/wcsrtombs.c
+++ b/wcsmbs/wcsrtombs.c
@@ -23,7 +23,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
diff --git a/wcsmbs/wctob.c b/wcsmbs/wctob.c
index 573c2c9448..5dfbd7ab7e 100644
--- a/wcsmbs/wctob.c
+++ b/wcsmbs/wctob.c
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 int
-- 
2.37.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources
  2022-10-13 12:20 [PATCH 0/3] PTR_MANGLE/PTR_DEMANGLE refactoring Florian Weimer
  2022-10-13 12:20 ` [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header Florian Weimer
  2022-10-13 12:20 ` [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h> Florian Weimer
@ 2022-10-13 12:20 ` Florian Weimer
  2022-10-17 16:15   ` Adhemerval Zanella Netto
  2 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2022-10-13 12:20 UTC (permalink / raw)
  To: libc-alpha

In the future, this will result in a compilation failure if the
macros are unexpectedly undefined (due to header inclusion ordering
or header inclusion missing altogether).

Assembler sources are more difficult to convert.  In many cases,
they are hand-optimized for the mangling and no-mangling variants,
which is why they are not converted.

sysdeps/s390/s390-32/__longjmp.c and sysdeps/s390/s390-64/__longjmp.c
are special: These are C sources, but most of the implementation is
in assembler, so the PTR_DEMANGLE macro has to be undefined in some
cases, to match the assembler style.
---
 hurd/sigunwind.c                      |  2 --
 iconv/gconv.c                         |  2 --
 iconv/gconv_cache.c                   |  5 -----
 iconv/gconv_db.c                      | 15 ---------------
 iconv/gconv_dl.c                      |  2 --
 iconv/gconv_trans.c                   |  2 --
 iconv/skeleton.c                      |  2 --
 inet/idna.c                           |  6 ------
 libio/iofopncook.c                    | 12 ------------
 libio/iofwide.c                       |  6 ------
 libio/libioP.h                        |  2 --
 libio/vtables.c                       |  2 --
 misc/unwind-link.c                    | 10 ++++------
 nss/nss_module.c                      | 12 ------------
 stdlib/cxa_atexit.c                   |  2 --
 stdlib/cxa_finalize.c                 |  3 +--
 stdlib/cxa_thread_atexit_impl.c       |  4 ----
 stdlib/exit.c                         |  9 +++------
 stdlib/on_exit.c                      |  2 --
 sysdeps/aarch64/jmpbuf-offsets.h      |  2 --
 sysdeps/alpha/jmpbuf-unwind.h         |  2 --
 sysdeps/arc/jmpbuf-unwind.h           |  2 --
 sysdeps/arm/jmpbuf-unwind.h           |  2 --
 sysdeps/csky/jmpbuf-unwind.h          |  2 --
 sysdeps/generic/unwind-link.h         |  6 +-----
 sysdeps/i386/jmpbuf-unwind.h          |  2 --
 sysdeps/i386/unwind-arch.h            |  6 +-----
 sysdeps/loongarch/jmpbuf-unwind.h     |  2 --
 sysdeps/m68k/jmpbuf-unwind.h          |  2 --
 sysdeps/mach/hurd/jmp-unwind.c        |  2 --
 sysdeps/microblaze/jmpbuf-unwind.h    |  2 --
 sysdeps/mips/jmpbuf-unwind.h          |  2 --
 sysdeps/nios2/jmpbuf-offsets.h        |  2 --
 sysdeps/powerpc/jmpbuf-unwind.h       |  2 --
 sysdeps/riscv/jmpbuf-unwind.h         |  2 --
 sysdeps/s390/jmpbuf-unwind.h          |  2 --
 sysdeps/s390/s390-32/__longjmp.c      |  5 +++++
 sysdeps/s390/s390-64/__longjmp.c      |  5 +++++
 sysdeps/sh/jmpbuf-unwind.h            |  2 --
 sysdeps/sparc/sparc32/jmpbuf-unwind.h |  2 --
 sysdeps/x86_64/jmpbuf-unwind.h        |  2 --
 wcsmbs/btowc.c                        |  4 ----
 wcsmbs/mbrtoc16.c                     |  2 --
 wcsmbs/mbrtowc.c                      |  2 --
 wcsmbs/mbsnrtowcs.c                   |  2 --
 wcsmbs/mbsrtowcs_l.c                  |  2 --
 wcsmbs/wcrtomb.c                      |  2 --
 wcsmbs/wcsnrtombs.c                   |  2 --
 wcsmbs/wcsrtombs.c                    |  2 --
 wcsmbs/wctob.c                        |  2 --
 50 files changed, 20 insertions(+), 158 deletions(-)

diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
index 28213091e3..f114990b6f 100644
--- a/hurd/sigunwind.c
+++ b/hurd/sigunwind.c
@@ -73,9 +73,7 @@ _hurdsig_longjmp_from_handler (void *data, jmp_buf env, int val)
 
       inline uintptr_t demangle_ptr (uintptr_t x)
 	{
-# ifdef PTR_DEMANGLE
 	  PTR_DEMANGLE (x);
-# endif
 	  return x;
 	}
 
diff --git a/iconv/gconv.c b/iconv/gconv.c
index dea9c80fee..592a75956c 100644
--- a/iconv/gconv.c
+++ b/iconv/gconv.c
@@ -46,10 +46,8 @@ __gconv (__gconv_t cd, const unsigned char **inbuf,
   cd->__data[last_step].__outbufend = outbufend;
 
   __gconv_fct fct = cd->__steps->__fct;
-#ifdef PTR_DEMANGLE
   if (cd->__steps->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   if (inbuf == NULL || *inbuf == NULL)
     {
diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
index 5dbf596b8d..8d47545c41 100644
--- a/iconv/gconv_cache.c
+++ b/iconv/gconv_cache.c
@@ -205,16 +205,11 @@ find_module (const char *directory, const char *filename,
 
       /* Call the init function.  */
       __gconv_init_fct init_fct = result->__init_fct;
-#ifdef PTR_DEMANGLE
       PTR_DEMANGLE (init_fct);
-#endif
       if (init_fct != NULL)
 	{
 	  status = DL_CALL_FCT (init_fct, (result));
-
-#ifdef PTR_MANGLE
 	  PTR_MANGLE (result->__btowc_fct);
-#endif
 	}
     }
 
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index 90037fdf58..4943c954a3 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -180,9 +180,7 @@ free_derivation (void *p)
 	&& deriv->steps[cnt].__shlib_handle != NULL)
       {
 	__gconv_end_fct end_fct = deriv->steps[cnt].__end_fct;
-#ifdef PTR_DEMANGLE
 	PTR_DEMANGLE (end_fct);
-#endif
 	if (end_fct != NULL)
 	  DL_CALL_FCT (end_fct, (&deriv->steps[cnt]));
       }
@@ -208,9 +206,7 @@ __gconv_release_step (struct __gconv_step *step)
     {
       /* Call the destructor.  */
 	__gconv_end_fct end_fct = step->__end_fct;
-#ifdef PTR_DEMANGLE
 	PTR_DEMANGLE (end_fct);
-#endif
       if (end_fct != NULL)
 	DL_CALL_FCT (end_fct, (step));
 
@@ -303,9 +299,7 @@ gen_steps (struct derivation_step *best, const char *toset,
 
 	      /* Call the init function.  */
 	      __gconv_init_fct init_fct = result[step_cnt].__init_fct;
-# ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (init_fct);
-# endif
 	      if (init_fct != NULL)
 		{
 		  status = DL_CALL_FCT (init_fct, (&result[step_cnt]));
@@ -316,17 +310,13 @@ gen_steps (struct derivation_step *best, const char *toset,
 		      /* Do not call the end function because the init
 			 function has failed.  */
 		      result[step_cnt].__end_fct = NULL;
-# ifdef PTR_MANGLE
 		      PTR_MANGLE (result[step_cnt].__end_fct);
-# endif
 		      /* Make sure we unload this module.  */
 		      --step_cnt;
 		      break;
 		    }
 		}
-# ifdef PTR_MANGLE
 	      PTR_MANGLE (result[step_cnt].__btowc_fct);
-# endif
 	    }
 	  else
 #endif
@@ -404,15 +394,10 @@ increment_counter (struct __gconv_step *steps, size_t nsteps)
 
 	      /* Call the init function.  */
 	      __gconv_init_fct init_fct = step->__init_fct;
-#ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (init_fct);
-#endif
 	      if (init_fct != NULL)
 		DL_CALL_FCT (init_fct, (step));
-
-#ifdef PTR_MANGLE
 	      PTR_MANGLE (step->__btowc_fct);
-#endif
 	    }
 	}
     }
diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
index c93c5dd380..5ed982636a 100644
--- a/iconv/gconv_dl.c
+++ b/iconv/gconv_dl.c
@@ -127,11 +127,9 @@ __gconv_find_shlib (const char *name)
 		  found->init_fct = __libc_dlsym (found->handle, "gconv_init");
 		  found->end_fct = __libc_dlsym (found->handle, "gconv_end");
 
-#ifdef PTR_MANGLE
 		  PTR_MANGLE (found->fct);
 		  PTR_MANGLE (found->init_fct);
 		  PTR_MANGLE (found->end_fct);
-#endif
 
 		  /* We have succeeded in loading the shared object.  */
 		  found->counter = 1;
diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c
index 0f4ce10996..2255531452 100644
--- a/iconv/gconv_trans.c
+++ b/iconv/gconv_trans.c
@@ -53,10 +53,8 @@ __gconv_transliterate (struct __gconv_step *step,
   winbufend = (const uint32_t *) inbufend;
 
   __gconv_fct fct = step->__fct;
-#ifdef PTR_DEMANGLE
   if (step->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* If there is no transliteration information in the locale don't do
      anything and return the error.  */
diff --git a/iconv/skeleton.c b/iconv/skeleton.c
index 42ee0b6508..9eaf9a4948 100644
--- a/iconv/skeleton.c
+++ b/iconv/skeleton.c
@@ -404,10 +404,8 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
   if ((data->__flags & __GCONV_IS_LAST) == 0)
     {
       fct = next_step->__fct;
-#ifdef PTR_DEMANGLE
       if (next_step->__shlib_handle != NULL)
 	PTR_DEMANGLE (fct);
-#endif
     }
 
   /* If the function is called with no input this means we have to reset
diff --git a/inet/idna.c b/inet/idna.c
index df5811fd6a..2243d3e7d9 100644
--- a/inet/idna.c
+++ b/inet/idna.c
@@ -73,10 +73,8 @@ functions_allocate (void *closure)
   result->handle = handle;
   result->lookup_ul = ptr_lookup_ul;
   result->to_unicode_lzlz = ptr_to_unicode_lzlz;
-#ifdef PTR_MANGLE
   PTR_MANGLE (result->lookup_ul);
   PTR_MANGLE (result->to_unicode_lzlz);
-#endif
 
   return result;
 }
@@ -138,9 +136,7 @@ __idna_to_dns_encoding (const char *name, char **result)
     return EAI_IDN_ENCODE;
   char *ptr = NULL;
   __typeof__ (functions->lookup_ul) fptr = functions->lookup_ul;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (fptr);
-#endif
   int ret = fptr (name, &ptr, 0);
   if (ret == 0)
     {
@@ -165,9 +161,7 @@ __idna_from_dns_encoding (const char *name, char **result)
     return gai_strdup (name, result);
   char *ptr = NULL;
   __typeof__ (functions->to_unicode_lzlz) fptr = functions->to_unicode_lzlz;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (fptr);
-#endif
   int ret = fptr (name, &ptr, 0);
   if (ret == 0)
     {
diff --git a/libio/iofopncook.c b/libio/iofopncook.c
index a7db4ef1c9..6c27610319 100644
--- a/libio/iofopncook.c
+++ b/libio/iofopncook.c
@@ -35,9 +35,7 @@ _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
 {
   struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
   cookie_read_function_t *read_cb = cfile->__io_functions.read;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (read_cb);
-#endif
 
   if (read_cb == NULL)
     return -1;
@@ -50,9 +48,7 @@ _IO_cookie_write (FILE *fp, const void *buf, ssize_t size)
 {
   struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
   cookie_write_function_t *write_cb = cfile->__io_functions.write;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (write_cb);
-#endif
 
   if (write_cb == NULL)
     {
@@ -72,9 +68,7 @@ _IO_cookie_seek (FILE *fp, off64_t offset, int dir)
 {
   struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
   cookie_seek_function_t *seek_cb = cfile->__io_functions.seek;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (seek_cb);
-#endif
 
   return ((seek_cb == NULL
 	   || (seek_cb (cfile->__cookie, &offset, dir)
@@ -88,9 +82,7 @@ _IO_cookie_close (FILE *fp)
 {
   struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
   cookie_close_function_t *close_cb = cfile->__io_functions.close;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (close_cb);
-#endif
 
   if (close_cb == NULL)
     return 0;
@@ -139,12 +131,10 @@ static void
 set_callbacks (cookie_io_functions_t *target,
 	       cookie_io_functions_t source)
 {
-#ifdef PTR_MANGLE
   PTR_MANGLE (source.read);
   PTR_MANGLE (source.write);
   PTR_MANGLE (source.seek);
   PTR_MANGLE (source.close);
-#endif
   *target = source;
 }
 
@@ -226,9 +216,7 @@ _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir)
   struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
   int (*seek_cb) (FILE *, off_t, int)
     = (int (*) (FILE *, off_t, int)) cfile->__io_functions.seek;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (seek_cb);
-#endif
 
   if (seek_cb == NULL)
     return _IO_pos_BAD;
diff --git a/libio/iofwide.c b/libio/iofwide.c
index 1ce685f48a..37c353e3aa 100644
--- a/libio/iofwide.c
+++ b/libio/iofwide.c
@@ -124,10 +124,8 @@ __libio_codecvt_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
   codecvt->__cd_out.step_data.__statep = statep;
 
   __gconv_fct fct = gs->__fct;
-#ifdef PTR_DEMANGLE
   if (gs->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   status = DL_CALL_FCT (fct,
 			(gs, &codecvt->__cd_out.step_data, &from_start_copy,
@@ -176,10 +174,8 @@ __libio_codecvt_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
   codecvt->__cd_in.step_data.__statep = statep;
 
   __gconv_fct fct = gs->__fct;
-#ifdef PTR_DEMANGLE
   if (gs->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   status = DL_CALL_FCT (fct,
 			(gs, &codecvt->__cd_in.step_data, &from_start_copy,
@@ -243,10 +239,8 @@ __libio_codecvt_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
   codecvt->__cd_in.step_data.__statep = statep;
 
   __gconv_fct fct = gs->__fct;
-#ifdef PTR_DEMANGLE
   if (gs->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   DL_CALL_FCT (fct,
 	       (gs, &codecvt->__cd_in.step_data, &cp,
diff --git a/libio/libioP.h b/libio/libioP.h
index dac3de73a1..3a5498bd65 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -911,9 +911,7 @@ extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
 static inline void
 IO_set_accept_foreign_vtables (void (*flag) (void))
 {
-#ifdef PTR_MANGLE
   PTR_MANGLE (flag);
-#endif
   atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
 }
 
diff --git a/libio/vtables.c b/libio/vtables.c
index 32459e4fac..e3809c28ce 100644
--- a/libio/vtables.c
+++ b/libio/vtables.c
@@ -39,9 +39,7 @@ _IO_vtable_check (void)
 #ifdef SHARED
   /* Honor the compatibility flag.  */
   void (*flag) (void) = atomic_load_relaxed (&IO_accept_foreign_vtables);
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (flag);
-#endif
   if (flag == &_IO_vtable_check)
     return;
 
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 45b7886b46..e8653bbaf1 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -86,19 +86,17 @@ __libc_unwind_link_get (void)
   assert (local.ptr__Unwind_Resume != NULL);
   assert (local.ptr_personality != NULL);
 
-#ifdef PTR_MANGLE
   PTR_MANGLE (local.ptr__Unwind_Backtrace);
   PTR_MANGLE (local.ptr__Unwind_ForcedUnwind);
   PTR_MANGLE (local.ptr__Unwind_GetCFA);
-# if UNWIND_LINK_GETIP
+#if UNWIND_LINK_GETIP
   PTR_MANGLE (local.ptr__Unwind_GetIP);
-# endif
+#endif
   PTR_MANGLE (local.ptr__Unwind_Resume);
-# if UNWIND_LINK_FRAME_STATE_FOR
+#if UNWIND_LINK_FRAME_STATE_FOR
   PTR_MANGLE (local.ptr___frame_state_for);
-# endif
-  PTR_MANGLE (local.ptr_personality);
 #endif
+  PTR_MANGLE (local.ptr_personality);
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
diff --git a/nss/nss_module.c b/nss/nss_module.c
index 9a8f3ddf94..444facb9b8 100644
--- a/nss/nss_module.c
+++ b/nss/nss_module.c
@@ -128,10 +128,8 @@ module_load_builtin (struct nss_module *module,
     case nss_module_failed:
       bind (module->functions.untyped);
 
-#ifdef PTR_MANGLE
       for (int i = 0; i < nss_module_functions_count; ++i)
 	PTR_MANGLE (module->functions.untyped[i]);
-#endif
 
       module->handle = NULL;
       /* Synchronizes with unlocked __nss_module_load atomic_load_acquire.  */
@@ -153,9 +151,7 @@ module_load_nss_files (struct nss_module *module)
   if (is_nscd)
     {
       void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
-# ifdef PTR_DEMANGLE
       PTR_DEMANGLE (cb);
-# endif
       _nss_files_init (cb);
     }
 #endif
@@ -239,9 +235,7 @@ module_load (struct nss_module *module)
         }
       pointers[idx] = __libc_dlsym (handle, function_name);
       free (function_name);
-#ifdef PTR_MANGLE
       PTR_MANGLE (pointers[idx]);
-#endif
     }
 
 # ifdef USE_NSCD
@@ -264,9 +258,7 @@ module_load (struct nss_module *module)
       if (ifct != NULL)
 	{
 	  void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
-#  ifdef PTR_DEMANGLE
 	  PTR_DEMANGLE (cb);
-#  endif
 	  ifct (cb);
 	}
     }
@@ -349,9 +341,7 @@ __nss_module_get_function (struct nss_module *module, const char *name)
   assert (name_entry != NULL);
   size_t idx = name_entry - nss_function_name_array;
   void *fptr = module->functions.untyped[idx];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (fptr);
-#endif
   return fptr;
 }
 
@@ -382,9 +372,7 @@ __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
 {
   void (*cb1) (size_t, struct traced_file *);
   cb1 = cb;
-# ifdef PTR_MANGLE
   PTR_MANGLE (cb);
-# endif
   nscd_init_cb = cb;
   is_nscd = true;
 
diff --git a/stdlib/cxa_atexit.c b/stdlib/cxa_atexit.c
index adf89e93f5..fad2d2b4e0 100644
--- a/stdlib/cxa_atexit.c
+++ b/stdlib/cxa_atexit.c
@@ -49,9 +49,7 @@ __internal_atexit (void (*func) (void *), void *arg, void *d,
       return -1;
     }
 
-#ifdef PTR_MANGLE
   PTR_MANGLE (func);
-#endif
   new->func.cxa.fn = (void (*) (void *, int)) func;
   new->func.cxa.arg = arg;
   new->func.cxa.dso_handle = d;
diff --git a/stdlib/cxa_finalize.c b/stdlib/cxa_finalize.c
index f2479569a5..1958c28801 100644
--- a/stdlib/cxa_finalize.c
+++ b/stdlib/cxa_finalize.c
@@ -75,9 +75,8 @@ __cxa_finalize (void *d)
 	       parallel.  */
 	    f->flavor = ef_free;
 
-#ifdef PTR_DEMANGLE
 	    PTR_DEMANGLE (cxafn);
-#endif
+
 	    /* Unlock the list while we call a foreign function.  */
 	    __libc_lock_unlock (__exit_funcs_lock);
 	    cxafn (cxaarg, 0);
diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c
index faacab3990..b5ecfee10c 100644
--- a/stdlib/cxa_thread_atexit_impl.c
+++ b/stdlib/cxa_thread_atexit_impl.c
@@ -100,9 +100,7 @@ static __thread struct link_map *lm_cache;
 int
 __cxa_thread_atexit_impl (dtor_func func, void *obj, void *dso_symbol)
 {
-#ifdef PTR_MANGLE
   PTR_MANGLE (func);
-#endif
 
   /* Prepend.  */
   struct dtor_list *new = calloc (1, sizeof (struct dtor_list));
@@ -152,9 +150,7 @@ __call_tls_dtors (void)
     {
       struct dtor_list *cur = tls_dtor_list;
       dtor_func func = cur->func;
-#ifdef PTR_DEMANGLE
       PTR_DEMANGLE (func);
-#endif
 
       tls_dtor_list = tls_dtor_list->next;
       func (cur->obj);
diff --git a/stdlib/exit.c b/stdlib/exit.c
index e59156bbf6..10c44e1449 100644
--- a/stdlib/exit.c
+++ b/stdlib/exit.c
@@ -81,9 +81,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
 	    case ef_on:
 	      onfct = f->func.on.fn;
 	      arg = f->func.on.arg;
-#ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (onfct);
-#endif
+
 	      /* Unlock the list while we call a foreign function.  */
 	      __libc_lock_unlock (__exit_funcs_lock);
 	      onfct (status, arg);
@@ -91,9 +90,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
 	      break;
 	    case ef_at:
 	      atfct = f->func.at;
-#ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (atfct);
-#endif
+
 	      /* Unlock the list while we call a foreign function.  */
 	      __libc_lock_unlock (__exit_funcs_lock);
 	      atfct ();
@@ -105,9 +103,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
 	      f->flavor = ef_free;
 	      cxafct = f->func.cxa.fn;
 	      arg = f->func.cxa.arg;
-#ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (cxafct);
-#endif
+
 	      /* Unlock the list while we call a foreign function.  */
 	      __libc_lock_unlock (__exit_funcs_lock);
 	      cxafct (arg, status);
diff --git a/stdlib/on_exit.c b/stdlib/on_exit.c
index fb59db20ca..2ac70e18bd 100644
--- a/stdlib/on_exit.c
+++ b/stdlib/on_exit.c
@@ -39,9 +39,7 @@ __on_exit (void (*func) (int status, void *arg), void *arg)
       return -1;
     }
 
-#ifdef PTR_MANGLE
   PTR_MANGLE (func);
-#endif
   new->func.on.fn = func;
   new->func.on.arg = arg;
   new->flavor = ef_on;
diff --git a/sysdeps/aarch64/jmpbuf-offsets.h b/sysdeps/aarch64/jmpbuf-offsets.h
index 78bdd4a539..841da965a6 100644
--- a/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/sysdeps/aarch64/jmpbuf-offsets.h
@@ -49,9 +49,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf jmpbuf)
 {
   uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 #endif
diff --git a/sysdeps/alpha/jmpbuf-unwind.h b/sysdeps/alpha/jmpbuf-unwind.h
index 318b73b100..05a0dc9cba 100644
--- a/sysdeps/alpha/jmpbuf-unwind.h
+++ b/sysdeps/alpha/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/arc/jmpbuf-unwind.h b/sysdeps/arc/jmpbuf-unwind.h
index e5434a95dd..2eadc5d22f 100644
--- a/sysdeps/arc/jmpbuf-unwind.h
+++ b/sysdeps/arc/jmpbuf-unwind.h
@@ -35,9 +35,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf jmpbuf)
 {
   uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/arm/jmpbuf-unwind.h b/sysdeps/arm/jmpbuf-unwind.h
index 641444eaf3..be99b4f9be 100644
--- a/sysdeps/arm/jmpbuf-unwind.h
+++ b/sysdeps/arm/jmpbuf-unwind.h
@@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[__JMP_BUF_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/csky/jmpbuf-unwind.h b/sysdeps/csky/jmpbuf-unwind.h
index 76fca431c6..61e9c45875 100644
--- a/sysdeps/csky/jmpbuf-unwind.h
+++ b/sysdeps/csky/jmpbuf-unwind.h
@@ -36,9 +36,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = (uintptr_t) regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/generic/unwind-link.h b/sysdeps/generic/unwind-link.h
index a2076a23bf..ea031a04d0 100644
--- a/sysdeps/generic/unwind-link.h
+++ b/sysdeps/generic/unwind-link.h
@@ -61,16 +61,12 @@ libc_hidden_proto (__libc_unwind_link_get)
 /* UNWIND_LINK_PTR returns the stored function pointer NAME from the
    cached unwind link OBJ (which was previously returned by
    __libc_unwind_link_get).  */
-# ifdef PTR_DEMANGLE
-#  define UNWIND_LINK_PTR(obj, name, ...)                          \
+# define UNWIND_LINK_PTR(obj, name, ...)                             \
   ({                                                                \
     __typeof ((obj)->ptr_##name) __unwind_fptr = (obj)->ptr_##name; \
     PTR_DEMANGLE (__unwind_fptr);                                   \
     __unwind_fptr;                                                  \
   })
-# else /* !PTR_DEMANGLE */
-#  define UNWIND_LINK_PTR(obj, name, ...) ((obj)->ptr_##name)
-# endif
 
 /* Called from fork, in the new subprocess.  */
 void __libc_unwind_link_after_fork (void);
diff --git a/sysdeps/i386/jmpbuf-unwind.h b/sysdeps/i386/jmpbuf-unwind.h
index 73d214fd31..25b54f8bb0 100644
--- a/sysdeps/i386/jmpbuf-unwind.h
+++ b/sysdeps/i386/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/i386/unwind-arch.h b/sysdeps/i386/unwind-arch.h
index ae23469d3f..bb2e878dd0 100644
--- a/sysdeps/i386/unwind-arch.h
+++ b/sysdeps/i386/unwind-arch.h
@@ -28,12 +28,8 @@
   local.ptr__Unwind_GetGR                                   \
     = __libc_dlsym (local_libgcc_handle, "_Unwind_GetGR");  \
   assert (local.ptr__Unwind_GetGR != NULL);
-#ifdef PTR_MANGLE
-# define UNWIND_LINK_EXTRA_INIT                 \
+#define UNWIND_LINK_EXTRA_INIT                  \
   UNWIND_LINK_EXTRA_INIT_SHARED                 \
   PTR_MANGLE (local.ptr__Unwind_GetGR);
-#else
-# define UNWIND_LINK_EXTRA_INIT UNWIND_LINK_EXTRA_INIT_SHARED
-#endif
 
 #endif /* _ARCH_UNWIND_LINK_H */
diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
index 458edec135..bd58dd7cc5 100644
--- a/sysdeps/loongarch/jmpbuf-unwind.h
+++ b/sysdeps/loongarch/jmpbuf-unwind.h
@@ -33,9 +33,7 @@
 static inline uintptr_t __attribute__ ((unused)) _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/m68k/jmpbuf-unwind.h b/sysdeps/m68k/jmpbuf-unwind.h
index 3ee46c050c..baf6f79b88 100644
--- a/sysdeps/m68k/jmpbuf-unwind.h
+++ b/sysdeps/m68k/jmpbuf-unwind.h
@@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = (uintptr_t) regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/mach/hurd/jmp-unwind.c b/sysdeps/mach/hurd/jmp-unwind.c
index 2577fbf3ee..1ac2815aac 100644
--- a/sysdeps/mach/hurd/jmp-unwind.c
+++ b/sysdeps/mach/hurd/jmp-unwind.c
@@ -31,9 +31,7 @@
 static inline uintptr_t
 demangle_ptr (uintptr_t x)
 {
-# ifdef PTR_DEMANGLE
   PTR_DEMANGLE (x);
-# endif
   return x;
 }
 
diff --git a/sysdeps/microblaze/jmpbuf-unwind.h b/sysdeps/microblaze/jmpbuf-unwind.h
index 302e950ced..79fc493971 100644
--- a/sysdeps/microblaze/jmpbuf-unwind.h
+++ b/sysdeps/microblaze/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   void *sp = (void *) regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return (uintptr_t) sp;
 }
 
diff --git a/sysdeps/mips/jmpbuf-unwind.h b/sysdeps/mips/jmpbuf-unwind.h
index 28ecffedb0..827000a729 100644
--- a/sysdeps/mips/jmpbuf-unwind.h
+++ b/sysdeps/mips/jmpbuf-unwind.h
@@ -35,9 +35,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = (uintptr_t) regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/nios2/jmpbuf-offsets.h b/sysdeps/nios2/jmpbuf-offsets.h
index 76fea64ffe..50f938c8cf 100644
--- a/sysdeps/nios2/jmpbuf-offsets.h
+++ b/sysdeps/nios2/jmpbuf-offsets.h
@@ -38,9 +38,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf jmpbuf)
 {
   uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 #endif
diff --git a/sysdeps/powerpc/jmpbuf-unwind.h b/sysdeps/powerpc/jmpbuf-unwind.h
index 93573ce238..82499594a3 100644
--- a/sysdeps/powerpc/jmpbuf-unwind.h
+++ b/sysdeps/powerpc/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[JB_GPR1];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/riscv/jmpbuf-unwind.h b/sysdeps/riscv/jmpbuf-unwind.h
index b411a246d1..0aeb0a76c6 100644
--- a/sysdeps/riscv/jmpbuf-unwind.h
+++ b/sysdeps/riscv/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[0].__sp;
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/s390/jmpbuf-unwind.h b/sysdeps/s390/jmpbuf-unwind.h
index 10b37f09c3..d125f3100a 100644
--- a/sysdeps/s390/jmpbuf-unwind.h
+++ b/sysdeps/s390/jmpbuf-unwind.h
@@ -41,9 +41,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   void *sp = (void *) (uintptr_t) regs[0].__gregs[__JB_GPR15];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return (uintptr_t) sp;
 }
 
diff --git a/sysdeps/s390/s390-32/__longjmp.c b/sysdeps/s390/s390-32/__longjmp.c
index 83d42329a3..f0317f6a03 100644
--- a/sysdeps/s390/s390-32/__longjmp.c
+++ b/sysdeps/s390/s390-32/__longjmp.c
@@ -24,6 +24,11 @@
 #include <unistd.h>
 #include <stap-probe.h>
 
+/* See sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h.  */
+#if IS_IN (rtld)
+# undef PTR_DEMANGLE
+#endif
+
 /* Jump to the position specified by ENV, causing the
    setjmp call there to return VAL, or 1 if VAL is 0.  */
 void
diff --git a/sysdeps/s390/s390-64/__longjmp.c b/sysdeps/s390/s390-64/__longjmp.c
index 9fe4939e5e..eabe245d95 100644
--- a/sysdeps/s390/s390-64/__longjmp.c
+++ b/sysdeps/s390/s390-64/__longjmp.c
@@ -24,6 +24,11 @@
 #include <unistd.h>
 #include <stap-probe.h>
 
+/* See sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h.  */
+#if IS_IN (rtld)
+# undef PTR_DEMANGLE
+#endif
+
 /* Jump to the position specified by ENV, causing the
    setjmp call there to return VAL, or 1 if VAL is 0.  */
 void
diff --git a/sysdeps/sh/jmpbuf-unwind.h b/sysdeps/sh/jmpbuf-unwind.h
index 1957e5275d..2c8b8b3696 100644
--- a/sysdeps/sh/jmpbuf-unwind.h
+++ b/sysdeps/sh/jmpbuf-unwind.h
@@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   void *sp = (void *) regs[0].__regs[7];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return (uintptr_t) sp;
 }
 
diff --git a/sysdeps/sparc/sparc32/jmpbuf-unwind.h b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
index 8b697ed95b..a225a33dc5 100644
--- a/sysdeps/sparc/sparc32/jmpbuf-unwind.h
+++ b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
@@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[JB_SP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/sysdeps/x86_64/jmpbuf-unwind.h b/sysdeps/x86_64/jmpbuf-unwind.h
index c92b2633bc..6fc5097e11 100644
--- a/sysdeps/x86_64/jmpbuf-unwind.h
+++ b/sysdeps/x86_64/jmpbuf-unwind.h
@@ -36,9 +36,7 @@ static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)
 {
   uintptr_t sp = regs[JB_RSP];
-#ifdef PTR_DEMANGLE
   PTR_DEMANGLE (sp);
-#endif
   return sp;
 }
 
diff --git a/wcsmbs/btowc.c b/wcsmbs/btowc.c
index 7023ec99f1..da1c28732f 100644
--- a/wcsmbs/btowc.c
+++ b/wcsmbs/btowc.c
@@ -45,10 +45,8 @@ __btowc (int c)
   /* Get the conversion functions.  */
   fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
   __gconv_btowc_fct btowc_fct = fcts->towc->__btowc_fct;
-#ifdef PTR_DEMANGLE
   if (fcts->towc->__shlib_handle != NULL)
     PTR_DEMANGLE (btowc_fct);
-#endif
 
   if (__builtin_expect (fcts->towc_nsteps == 1, 1)
       && __builtin_expect (btowc_fct != NULL, 1))
@@ -81,10 +79,8 @@ __btowc (int c)
       inbuf[0] = c;
 
       __gconv_fct fct = fcts->towc->__fct;
-#ifdef PTR_DEMANGLE
       if (fcts->towc->__shlib_handle != NULL)
 	PTR_DEMANGLE (fct);
-#endif
       status = DL_CALL_FCT (fct, (fcts->towc, &data, &inptr, inptr + 1,
 				  NULL, &dummy, 0, 1));
 
diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
index f8b029b58a..f45f73e246 100644
--- a/wcsmbs/mbrtoc16.c
+++ b/wcsmbs/mbrtoc16.c
@@ -96,10 +96,8 @@ mbrtoc16 (char16_t *pc16, const char *s, size_t n, mbstate_t *ps)
 	goto ilseq;
     }
   __gconv_fct fct = fcts->towc->__fct;
-#ifdef PTR_DEMANGLE
   if (fcts->towc->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf,
 			      NULL, &dummy, 0, 1));
diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
index 46a1cc38df..3d06acbd5a 100644
--- a/wcsmbs/mbrtowc.c
+++ b/wcsmbs/mbrtowc.c
@@ -78,10 +78,8 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 	goto ilseq;
     }
   __gconv_fct fct = fcts->towc->__fct;
-#ifdef PTR_DEMANGLE
   if (fcts->towc->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
   status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf,
 			      NULL, &dummy, 0, 1));
 
diff --git a/wcsmbs/mbsnrtowcs.c b/wcsmbs/mbsnrtowcs.c
index 06a1f2d36f..47f5de408a 100644
--- a/wcsmbs/mbsnrtowcs.c
+++ b/wcsmbs/mbsnrtowcs.c
@@ -64,10 +64,8 @@ __mbsnrtowcs (wchar_t *dst, const char **src, size_t nmc, size_t len,
   /* Get the structure with the function pointers.  */
   towc = fcts->towc;
   __gconv_fct fct = towc->__fct;
-#ifdef PTR_DEMANGLE
   if (towc->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* We have to handle DST == NULL special.  */
   if (dst == NULL)
diff --git a/wcsmbs/mbsrtowcs_l.c b/wcsmbs/mbsrtowcs_l.c
index 526b88e1dd..5fe70cb8a1 100644
--- a/wcsmbs/mbsrtowcs_l.c
+++ b/wcsmbs/mbsrtowcs_l.c
@@ -58,10 +58,8 @@ __mbsrtowcs_l (wchar_t *dst, const char **src, size_t len, mbstate_t *ps,
   /* Get the structure with the function pointers.  */
   towc = fcts->towc;
   __gconv_fct fct = towc->__fct;
-#ifdef PTR_DEMANGLE
   if (towc->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* We have to handle DST == NULL special.  */
   if (dst == NULL)
diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c
index 42690f2efd..b71ca79de7 100644
--- a/wcsmbs/wcrtomb.c
+++ b/wcsmbs/wcrtomb.c
@@ -63,10 +63,8 @@ __wcrtomb_internal (char *s, wchar_t wc, mbstate_t *ps, size_t s_size)
   /* Get the conversion functions.  */
   fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
   __gconv_fct fct = fcts->tomb->__fct;
-#ifdef PTR_DEMANGLE
   if (fcts->tomb->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* If WC is the NUL character we write into the output buffer the byte
      sequence necessary for PS to get into the initial state, followed
diff --git a/wcsmbs/wcsnrtombs.c b/wcsmbs/wcsnrtombs.c
index 6ba180cdc2..12b116a837 100644
--- a/wcsmbs/wcsnrtombs.c
+++ b/wcsmbs/wcsnrtombs.c
@@ -62,10 +62,8 @@ __wcsnrtombs (char *dst, const wchar_t **src, size_t nwc, size_t len,
   /* Get the structure with the function pointers.  */
   tomb = fcts->tomb;
   __gconv_fct fct = tomb->__fct;
-#ifdef PTR_DEMANGLE
   if (tomb->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* We have to handle DST == NULL special.  */
   if (dst == NULL)
diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c
index 7db2b181b3..962176c183 100644
--- a/wcsmbs/wcsrtombs.c
+++ b/wcsmbs/wcsrtombs.c
@@ -54,10 +54,8 @@ __wcsrtombs (char *dst, const wchar_t **src, size_t len, mbstate_t *ps)
   /* Get the structure with the function pointers.  */
   tomb = fcts->tomb;
   __gconv_fct fct = tomb->__fct;
-#ifdef PTR_DEMANGLE
   if (tomb->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
 
   /* We have to handle DST == NULL special.  */
   if (dst == NULL)
diff --git a/wcsmbs/wctob.c b/wcsmbs/wctob.c
index 5dfbd7ab7e..63764d1425 100644
--- a/wcsmbs/wctob.c
+++ b/wcsmbs/wctob.c
@@ -63,10 +63,8 @@ wctob (wint_t c)
 
   const unsigned char *argptr = (const unsigned char *) inptr;
   __gconv_fct fct = fcts->tomb->__fct;
-#ifdef PTR_DEMANGLE
   if (fcts->tomb->__shlib_handle != NULL)
     PTR_DEMANGLE (fct);
-#endif
   status = DL_CALL_FCT (fct,
 			(fcts->tomb, &data, &argptr,
 			 argptr + sizeof (inbuf[0]), NULL, &dummy, 0, 1));
-- 
2.37.3


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h>
  2022-10-13 12:20 ` [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h> Florian Weimer
@ 2022-10-14  3:30   ` DJ Delorie
  2022-10-14  8:14     ` Florian Weimer
  2022-10-17 16:13   ` Adhemerval Zanella Netto
  1 sibling, 1 reply; 10+ messages in thread
From: DJ Delorie @ 2022-10-14  3:30 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> writes:
> +++ b/sysdeps/generic/pointer_guard.h
> +#ifndef __ASSEMBLER__
> +# define PTR_MANGLE(x) (void) (x)
> +# define PTR_DEMANGLE(x) (void) (x)
> +#endif

These macros will always be called standalone, i.e.

       inline uintptr_t demangle_ptr (uintptr_t x)
 	{
 	  PTR_DEMANGLE (x);
 	  return x;
 	}

If that's the expectation, is there a reason why we need to even
reference X at all?  Would an empty declaration be valid?  This should
only affect volatile variables, but those would be referenced shortly
after anyway.  Atomic boundaries aren't an issue as atomics are not used
in the mangling compuation.

I can see having a non-empty body as a valid way to validate the usage,
but in that case something that actually validates it makes more sense
by only accepting a LHS:

> +# define PTR_MANGLE(x) (void) (&(x))

(the non-generic usages should enforce this through their assignments)

Also, is there any case where code could be corrupted by the lack of
overall parens?  I.e. is this better:

> +# define PTR_MANGLE(x) ((void) (x))


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h>
  2022-10-14  3:30   ` DJ Delorie
@ 2022-10-14  8:14     ` Florian Weimer
  0 siblings, 0 replies; 10+ messages in thread
From: Florian Weimer @ 2022-10-14  8:14 UTC (permalink / raw)
  To: DJ Delorie; +Cc: libc-alpha

* DJ Delorie:

> Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> writes:
>> +++ b/sysdeps/generic/pointer_guard.h
>> +#ifndef __ASSEMBLER__
>> +# define PTR_MANGLE(x) (void) (x)
>> +# define PTR_DEMANGLE(x) (void) (x)
>> +#endif
>
> These macros will always be called standalone, i.e.
>
>        inline uintptr_t demangle_ptr (uintptr_t x)
>  	{
>  	  PTR_DEMANGLE (x);
>  	  return x;
>  	}
>
> If that's the expectation, is there a reason why we need to even
> reference X at all?  Would an empty declaration be valid?  This should
> only affect volatile variables, but those would be referenced shortly
> after anyway.  Atomic boundaries aren't an issue as atomics are not used
> in the mangling compuation.
>
> I can see having a non-empty body as a valid way to validate the usage,
> but in that case something that actually validates it makes more sense
> by only accepting a LHS:
>
>> +# define PTR_MANGLE(x) (void) (&(x))
>
> (the non-generic usages should enforce this through their assignments)
>
> Also, is there any case where code could be corrupted by the lack of
> overall parens?  I.e. is this better:
>
>> +# define PTR_MANGLE(x) ((void) (x))

I copied this from the existing macros, e.g.

#define PTR_MANGLE(var) (void) (var)

in sysdeps/unix/sysv/linux/mips/mips64/sysdep.h.  I would rather not
tweak this and focus on replacing it with a generic version (that won't
protect setjmp/longjmp, but global variables).

Thanks,
Florian


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header
  2022-10-13 12:20 ` [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header Florian Weimer
@ 2022-10-17 16:03   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-17 16:03 UTC (permalink / raw)
  To: libc-alpha, Florian Weimer



On 13/10/22 09:20, Florian Weimer via Libc-alpha wrote:
> This way, we can define the pointer guard macros without including
> <sysdep.h> on x86-64.  Other architectures will not have such an
> inclusion dependency, and the implied header file inclusion would
> create a porting hazard.

LGTM with a minor nit below.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/x86_64/sysdep.h          |  7 +------
>  sysdeps/x86_64/x32/sysdep.h      |  6 +-----
>  sysdeps/x86_64/x32/x86-lp_size.h | 23 +++++++++++++++++++++++
>  sysdeps/x86_64/x86-lp_size.h     | 23 +++++++++++++++++++++++
>  4 files changed, 48 insertions(+), 11 deletions(-)
>  create mode 100644 sysdeps/x86_64/x32/x86-lp_size.h
>  create mode 100644 sysdeps/x86_64/x86-lp_size.h
> 
> diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
> index 7f5defa4ec..d1a43dc14c 100644
> --- a/sysdeps/x86_64/sysdep.h
> +++ b/sysdeps/x86_64/sysdep.h
> @@ -20,6 +20,7 @@
>  #define _X86_64_SYSDEP_H 1
>  
>  #include <sysdeps/x86/sysdep.h>
> +#include <x86-lp_size.h>
>  
>  #ifdef	__ASSEMBLER__
>  
> @@ -68,9 +69,6 @@ lose:									      \
>  # define JUMPTARGET(name)	name
>  #endif
>  
> -/* Long and pointer size in bytes.  */
> -#define LP_SIZE	8
> -
>  /* Instruction to operate on long and pointer.  */
>  #define LP_OP(insn) insn##q
>  
> @@ -137,9 +135,6 @@ lose:									      \
>  
>  #else	/* __ASSEMBLER__ */
>  
> -/* Long and pointer size in bytes.  */
> -#define LP_SIZE "8"
> -
>  /* Instruction to operate on long and pointer.  */
>  #define LP_OP(insn) #insn "q"
>  
> diff --git a/sysdeps/x86_64/x32/sysdep.h b/sysdeps/x86_64/x32/sysdep.h
> index 645ea4ae69..92d987780d 100644
> --- a/sysdeps/x86_64/x32/sysdep.h
> +++ b/sysdeps/x86_64/x32/sysdep.h
> @@ -17,8 +17,8 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdeps/x86_64/sysdep.h>
> +#include <x86-lp_size.h>
>  
> -#undef LP_SIZE
>  #undef LP_OP
>  #undef ASM_ADDR
>  
> @@ -41,8 +41,6 @@
>  
>  #ifdef	__ASSEMBLER__
>  
> -# define LP_SIZE 4
> -
>  # define LP_OP(insn) insn##l
>  
>  # define ASM_ADDR .long
> @@ -66,8 +64,6 @@
>  
>  #else	/* __ASSEMBLER__ */
>  
> -# define LP_SIZE "4"
> -
>  # define LP_OP(insn) #insn "l"
>  
>  # define ASM_ADDR ".long"
> diff --git a/sysdeps/x86_64/x32/x86-lp_size.h b/sysdeps/x86_64/x32/x86-lp_size.h
> new file mode 100644
> index 0000000000..ad03eb66b2
> --- /dev/null
> +++ b/sysdeps/x86_64/x32/x86-lp_size.h
> @@ -0,0 +1,23 @@
> +/* Pointer size definition for x86-64 x42.

s/42/32

> +   Copyright (C) 2022 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/>.  */
> +
> +#ifdef __ASSEMBLER__
> +# define LP_SIZE 4
> +#else
> +# define LP_SIZE "4"
> +#endif
> diff --git a/sysdeps/x86_64/x86-lp_size.h b/sysdeps/x86_64/x86-lp_size.h
> new file mode 100644
> index 0000000000..76877240e8
> --- /dev/null
> +++ b/sysdeps/x86_64/x86-lp_size.h
> @@ -0,0 +1,23 @@
> +/* Pointer size definition for x86-64.
> +   Copyright (C) 2022 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/>.  */
> +
> +#ifdef __ASSEMBLER__
> +# define LP_SIZE 8
> +#else
> +# define LP_SIZE "8"
> +#endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h>
  2022-10-13 12:20 ` [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h> Florian Weimer
  2022-10-14  3:30   ` DJ Delorie
@ 2022-10-17 16:13   ` Adhemerval Zanella Netto
  2022-10-18 15:03     ` Florian Weimer
  1 sibling, 1 reply; 10+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-17 16:13 UTC (permalink / raw)
  To: libc-alpha, Florian Weimer, DJ Delorie



On 13/10/22 09:20, Florian Weimer via Libc-alpha wrote:
> This allows us to define a generic no-op version of PTR_MANGLE and
> PTR_DEMANGLE.  In the future, we can use PTR_MANGLE and PTR_DEMANGLE
> unconditionally in C sources, avoiding an unintended loss of hardening
> due to missing include files or unlucky header inclusion ordering.

Could we also improve the generic implementation to always XOR with the
pointer guard and move it to be a proper static inline function?  I think
we can then remove a lot of boilerplate code each architecture need to
have.

> 
> In i386 and x86_64, we can avoid a <tls.h> dependency in the C
> code by using the computed constant from <tcb-offsets.h>.  <sysdep.h>
> no longer includes these definitions, so there is no cyclic dependency
> anymore when computing the <tcb-offsets.h> constants.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> ---
>  hurd/sigunwind.c                              |  2 +-
>  iconv/gconv.c                                 |  2 +-
>  iconv/gconv_cache.c                           |  1 +
>  iconv/gconv_db.c                              |  2 +-
>  iconv/gconv_dl.c                              |  2 +-
>  iconv/gconv_trans.c                           |  1 +
>  iconv/skeleton.c                              |  2 +-
>  inet/idna.c                                   |  1 +
>  libio/iofopncook.c                            |  1 +
>  libio/iofwide.c                               |  2 +-
>  libio/libioP.h                                |  1 +
>  libio/vtables.c                               |  1 +
>  misc/unwind-link.c                            |  1 +
>  nss/nss_module.c                              |  2 +-
>  stdlib/cxa_atexit.c                           |  2 +-
>  stdlib/cxa_finalize.c                         |  2 +-
>  stdlib/cxa_thread_atexit_impl.c               |  1 +
>  stdlib/exit.c                                 |  2 +-
>  stdlib/on_exit.c                              |  2 +-
>  sysdeps/aarch64/__longjmp.S                   |  1 +
>  sysdeps/aarch64/jmpbuf-offsets.h              |  1 +
>  sysdeps/aarch64/setjmp.S                      |  1 +
>  sysdeps/alpha/__longjmp.S                     |  1 +
>  sysdeps/alpha/jmpbuf-unwind.h                 |  1 +
>  sysdeps/alpha/setjmp.S                        |  1 +
>  sysdeps/arc/jmpbuf-unwind.h                   |  1 +
>  sysdeps/arm/__longjmp.S                       |  1 +
>  sysdeps/arm/jmpbuf-unwind.h                   |  1 +
>  sysdeps/arm/pointer_guard.h                   | 67 +++++++++++++++
>  sysdeps/arm/setjmp.S                          |  1 +
>  sysdeps/arm/sysdep.h                          | 44 ----------
>  sysdeps/csky/abiv2/__longjmp.S                |  1 +
>  sysdeps/csky/abiv2/setjmp.S                   |  1 +
>  sysdeps/csky/jmpbuf-unwind.h                  |  1 +
>  sysdeps/generic/pointer_guard.h               | 29 +++++++
>  sysdeps/generic/unwind-link.h                 |  2 +-
>  sysdeps/i386/__longjmp.S                      |  1 +
>  sysdeps/i386/bsd-_setjmp.S                    |  1 +
>  sysdeps/i386/bsd-setjmp.S                     |  1 +
>  sysdeps/i386/jmpbuf-unwind.h                  |  1 +
>  sysdeps/i386/setjmp.S                         |  1 +
>  sysdeps/loongarch/__longjmp.S                 |  1 +
>  sysdeps/loongarch/jmpbuf-unwind.h             |  1 +
>  sysdeps/loongarch/setjmp.S                    |  1 +
>  sysdeps/m68k/jmpbuf-unwind.h                  |  1 +
>  sysdeps/mach/hurd/i386/____longjmp_chk.S      |  1 +
>  sysdeps/mach/hurd/i386/__longjmp.S            |  1 +
>  sysdeps/mach/hurd/jmp-unwind.c                |  2 +-
>  sysdeps/microblaze/jmpbuf-unwind.h            |  1 +
>  sysdeps/mips/jmpbuf-unwind.h                  |  1 +
>  sysdeps/nios2/__longjmp.S                     |  1 +
>  sysdeps/nios2/jmpbuf-offsets.h                |  1 +
>  sysdeps/nios2/setjmp.S                        |  1 +
>  sysdeps/powerpc/jmpbuf-unwind.h               |  1 +
>  sysdeps/powerpc/powerpc32/__longjmp-common.S  |  1 +
>  .../powerpc/powerpc32/fpu/__longjmp-common.S  |  1 +
>  sysdeps/powerpc/powerpc32/fpu/setjmp-common.S |  1 +
>  sysdeps/powerpc/powerpc32/setjmp-common.S     |  1 +
>  sysdeps/powerpc/powerpc64/__longjmp-common.S  |  1 +
>  sysdeps/powerpc/powerpc64/setjmp-common.S     |  1 +
>  sysdeps/riscv/jmpbuf-unwind.h                 |  1 +
>  sysdeps/s390/jmpbuf-unwind.h                  |  1 +
>  sysdeps/s390/s390-32/__longjmp.c              |  1 +
>  sysdeps/s390/s390-32/setjmp.S                 |  1 +
>  sysdeps/s390/s390-64/__longjmp.c              |  1 +
>  sysdeps/s390/s390-64/setjmp.S                 |  1 +
>  sysdeps/sh/jmpbuf-unwind.h                    |  1 +
>  sysdeps/sh/sh3/__longjmp.S                    |  1 +
>  sysdeps/sh/sh3/setjmp.S                       |  1 +
>  sysdeps/sh/sh4/__longjmp.S                    |  1 +
>  sysdeps/sh/sh4/setjmp.S                       |  1 +
>  sysdeps/sparc/sparc32/__longjmp.S             |  1 +
>  sysdeps/sparc/sparc32/jmpbuf-unwind.h         |  1 +
>  sysdeps/sparc/sparc32/setjmp.S                |  1 +
>  .../unix/sysv/linux/aarch64/pointer_guard.h   | 68 +++++++++++++++
>  sysdeps/unix/sysv/linux/aarch64/sysdep.h      | 45 ----------
>  .../unix/sysv/linux/alpha/____longjmp_chk.S   |  1 +
>  sysdeps/unix/sysv/linux/alpha/pointer_guard.h | 62 ++++++++++++++
>  sysdeps/unix/sysv/linux/alpha/sysdep.h        | 40 ---------
>  sysdeps/unix/sysv/linux/arc/sysdep.h          |  4 -
>  sysdeps/unix/sysv/linux/csky/pointer_guard.h  | 68 +++++++++++++++
>  sysdeps/unix/sysv/linux/csky/sysdep.h         | 46 -----------
>  sysdeps/unix/sysv/linux/hppa/sysdep.h         |  4 -
>  .../unix/sysv/linux/i386/____longjmp_chk.S    |  1 +
>  sysdeps/unix/sysv/linux/i386/pointer_guard.h  | 49 +++++++++++
>  sysdeps/unix/sysv/linux/i386/sysdep.h         | 28 -------
>  sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S |  1 +
>  sysdeps/unix/sysv/linux/ia64/__longjmp.S      |  1 +
>  sysdeps/unix/sysv/linux/ia64/pointer_guard.h  | 44 ++++++++++
>  sysdeps/unix/sysv/linux/ia64/setjmp.S         |  1 +
>  sysdeps/unix/sysv/linux/ia64/sysdep.h         | 20 -----
>  .../unix/sysv/linux/loongarch/pointer_guard.h | 82 +++++++++++++++++++
>  sysdeps/unix/sysv/linux/loongarch/sysdep.h    | 60 --------------
>  sysdeps/unix/sysv/linux/m68k/sysdep.h         |  4 -
>  sysdeps/unix/sysv/linux/microblaze/sysdep.h   |  4 -
>  sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |  4 -
>  sysdeps/unix/sysv/linux/mips/mips64/sysdep.h  |  4 -
>  sysdeps/unix/sysv/linux/nios2/pointer_guard.h | 40 +++++++++
>  sysdeps/unix/sysv/linux/nios2/sysdep.h        | 17 ----
>  sysdeps/unix/sysv/linux/or1k/sysdep.h         |  4 -
>  .../unix/sysv/linux/powerpc/pointer_guard.h   | 55 +++++++++++++
>  sysdeps/unix/sysv/linux/powerpc/sysdep.h      | 32 --------
>  sysdeps/unix/sysv/linux/riscv/sysdep.h        |  4 -
>  .../sysv/linux/s390/s390-32/pointer_guard.h   | 45 ++++++++++
>  sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h | 21 -----
>  .../sysv/linux/s390/s390-64/pointer_guard.h   | 47 +++++++++++
>  sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h | 23 ------
>  sysdeps/unix/sysv/linux/sh/____longjmp_chk.S  |  1 +
>  sysdeps/unix/sysv/linux/sh/pointer_guard.h    | 43 ++++++++++
>  sysdeps/unix/sysv/linux/sh/sysdep.h           | 19 -----
>  .../linux/sparc/sparc32/____longjmp_chk.S     |  1 +
>  .../sysv/linux/sparc/sparc32/pointer_guard.h  | 44 ++++++++++
>  .../unix/sysv/linux/sparc/sparc32/sysdep.h    | 20 -----
>  .../sysv/linux/sparc/sparc64/pointer_guard.h  | 44 ++++++++++
>  .../unix/sysv/linux/sparc/sparc64/sysdep.h    | 20 -----
>  .../unix/sysv/linux/x86_64/____longjmp_chk.S  |  1 +
>  .../unix/sysv/linux/x86_64/pointer_guard.h    | 61 ++++++++++++++
>  sysdeps/unix/sysv/linux/x86_64/sysdep.h       | 40 ---------
>  sysdeps/x86_64/__longjmp.S                    |  1 +
>  sysdeps/x86_64/jmpbuf-unwind.h                |  1 +
>  sysdeps/x86_64/setjmp.S                       |  1 +
>  sysdeps/x86_64/x32/x86-lp_size.h              |  2 +-
>  wcsmbs/btowc.c                                |  2 +-
>  wcsmbs/mbrtoc16.c                             |  2 +-
>  wcsmbs/mbrtoc8.c                              |  2 -
>  wcsmbs/mbrtowc.c                              |  2 +-
>  wcsmbs/mbsnrtowcs.c                           |  2 +-
>  wcsmbs/mbsrtowcs_l.c                          |  2 +-
>  wcsmbs/wcrtomb.c                              |  2 +-
>  wcsmbs/wcsnrtombs.c                           |  2 +-
>  wcsmbs/wcsrtombs.c                            |  2 +-
>  wcsmbs/wctob.c                                |  2 +-
>  132 files changed, 940 insertions(+), 532 deletions(-)
>  create mode 100644 sysdeps/arm/pointer_guard.h
>  create mode 100644 sysdeps/generic/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/alpha/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/csky/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/i386/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/ia64/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/nios2/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/sh/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
>  create mode 100644 sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
> 
> diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
> index de76cf2436..28213091e3 100644
> --- a/hurd/sigunwind.c
> +++ b/hurd/sigunwind.c
> @@ -22,7 +22,7 @@
>  #include <jmpbuf-unwind.h>
>  #include <assert.h>
>  #include <stdint.h>
> -
> +#include <pointer_guard.h>
>  
>  /* _hurd_setup_sighandler puts a link on the `active resources' chain so that
>     _longjmp_unwind will call this function with the `struct sigcontext *'
> diff --git a/iconv/gconv.c b/iconv/gconv.c
> index 62d2b37bcd..dea9c80fee 100644
> --- a/iconv/gconv.c
> +++ b/iconv/gconv.c
> @@ -23,7 +23,7 @@
>  #include <sys/param.h>
>  
>  #include <gconv_int.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  int
> diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
> index c772856d1f..5dbf596b8d 100644
> --- a/iconv/gconv_cache.c
> +++ b/iconv/gconv_cache.c
> @@ -28,6 +28,7 @@
>  #include <gconv_int.h>
>  #include <iconvconfig.h>
>  #include <not-cancel.h>
> +#include <pointer_guard.h>
>  
>  #include "../intl/hash-string.h"
>  
> diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
> index bf385ac7b1..90037fdf58 100644
> --- a/iconv/gconv_db.c
> +++ b/iconv/gconv_db.c
> @@ -27,7 +27,7 @@
>  
>  #include <dlfcn.h>
>  #include <gconv_int.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  /* Simple data structure for alias mapping.  We have two names, `from'
> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
> index 24c0bd1d39..c93c5dd380 100644
> --- a/iconv/gconv_dl.c
> +++ b/iconv/gconv_dl.c
> @@ -26,7 +26,7 @@
>  #include <sys/param.h>
>  
>  #include <gconv_int.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  #ifdef DEBUG
> diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c
> index 1ebbbfd51b..0f4ce10996 100644
> --- a/iconv/gconv_trans.c
> +++ b/iconv/gconv_trans.c
> @@ -26,6 +26,7 @@
>  #include <libc-lock.h>
>  #include "gconv_int.h"
>  #include "../locale/localeinfo.h"
> +#include <pointer_guard.h>
>  
>  
>  int
> diff --git a/iconv/skeleton.c b/iconv/skeleton.c
> index 0356dbf92b..42ee0b6508 100644
> --- a/iconv/skeleton.c
> +++ b/iconv/skeleton.c
> @@ -147,7 +147,7 @@
>  # include <dlfcn.h>
>  #endif
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stdint.h>
>  
>  #ifndef DL_CALL_FCT
> diff --git a/inet/idna.c b/inet/idna.c
> index 9c76681c6a..df5811fd6a 100644
> --- a/inet/idna.c
> +++ b/inet/idna.c
> @@ -21,6 +21,7 @@
>  #include <inet/net-internal.h>
>  #include <netdb.h>
>  #include <stdbool.h>
> +#include <pointer_guard.h>
>  
>  /* Use the soname and version to locate libidn2, to ensure a
>     compatible ABI.  */
> diff --git a/libio/iofopncook.c b/libio/iofopncook.c
> index e108ad2199..a7db4ef1c9 100644
> --- a/libio/iofopncook.c
> +++ b/libio/iofopncook.c
> @@ -28,6 +28,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <shlib-compat.h>
> +#include <pointer_guard.h>
>  
>  static ssize_t
>  _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
> diff --git a/libio/iofwide.c b/libio/iofwide.c
> index 01616e06c7..1ce685f48a 100644
> --- a/libio/iofwide.c
> +++ b/libio/iofwide.c
> @@ -36,7 +36,7 @@
>  #include <wcsmbs/wcsmbsload.h>
>  #include <iconv/gconv_int.h>
>  #include <shlib-compat.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  /* Return orientation of stream.  If mode is nonzero try to change
> diff --git a/libio/libioP.h b/libio/libioP.h
> index ba4fdbd200..dac3de73a1 100644
> --- a/libio/libioP.h
> +++ b/libio/libioP.h
> @@ -47,6 +47,7 @@
>  #include "iolibio.h"
>  
>  #include <shlib-compat.h>
> +#include <pointer_guard.h>
>  
>  /* For historical reasons this is the name of the sysdeps header that
>     adjusts the libio configuration.  */
> diff --git a/libio/vtables.c b/libio/vtables.c
> index 50acab7f21..32459e4fac 100644
> --- a/libio/vtables.c
> +++ b/libio/vtables.c
> @@ -20,6 +20,7 @@
>  #include <libioP.h>
>  #include <stdio.h>
>  #include <ldsodefs.h>
> +#include <pointer_guard.h>
>  
>  #ifdef SHARED
>  
> diff --git a/misc/unwind-link.c b/misc/unwind-link.c
> index 9ae9561206..45b7886b46 100644
> --- a/misc/unwind-link.c
> +++ b/misc/unwind-link.c
> @@ -23,6 +23,7 @@
>  #include <gnu/lib-names.h>
>  #include <unwind-link.h>
>  #include <libc-lock.h>
> +#include <pointer_guard.h>
>  
>  /* Statically allocate the object, so that we do not have to deal with
>     malloc failure.  __libc_unwind_link_get must not fail if libgcc_s
> diff --git a/nss/nss_module.c b/nss/nss_module.c
> index f00bbd9e1a..9a8f3ddf94 100644
> --- a/nss/nss_module.c
> +++ b/nss/nss_module.c
> @@ -32,7 +32,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Suffix after .so of NSS service modules.  This is a bit of magic,
>     but we assume LIBNSS_FILES_SO looks like "libnss_files.so.2" and we
> diff --git a/stdlib/cxa_atexit.c b/stdlib/cxa_atexit.c
> index 1412dacb07..adf89e93f5 100644
> --- a/stdlib/cxa_atexit.c
> +++ b/stdlib/cxa_atexit.c
> @@ -21,7 +21,7 @@
>  
>  #include <libc-lock.h>
>  #include "exit.h"
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #undef __cxa_atexit
>  
> diff --git a/stdlib/cxa_finalize.c b/stdlib/cxa_finalize.c
> index d4db2e1fe0..f2479569a5 100644
> --- a/stdlib/cxa_finalize.c
> +++ b/stdlib/cxa_finalize.c
> @@ -19,7 +19,7 @@
>  #include <stdlib.h>
>  #include "exit.h"
>  #include <register-atfork.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stdint.h>
>  
>  /* If D is non-NULL, call all functions registered with `__cxa_atexit'
> diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c
> index 5cc8eb55dd..faacab3990 100644
> --- a/stdlib/cxa_thread_atexit_impl.c
> +++ b/stdlib/cxa_thread_atexit_impl.c
> @@ -75,6 +75,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <ldsodefs.h>
> +#include <pointer_guard.h>
>  
>  typedef void (*dtor_func) (void *);
>  
> diff --git a/stdlib/exit.c b/stdlib/exit.c
> index bc46109f3e..e59156bbf6 100644
> --- a/stdlib/exit.c
> +++ b/stdlib/exit.c
> @@ -18,7 +18,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <unistd.h>
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <libc-lock.h>
>  #include "exit.h"
>  
> diff --git a/stdlib/on_exit.c b/stdlib/on_exit.c
> index 3e2d640d65..fb59db20ca 100644
> --- a/stdlib/on_exit.c
> +++ b/stdlib/on_exit.c
> @@ -18,7 +18,7 @@
>  #include <assert.h>
>  #include <stdlib.h>
>  #include "exit.h"
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Register a function to be called by exit.  */
>  int
> diff --git a/sysdeps/aarch64/__longjmp.S b/sysdeps/aarch64/__longjmp.S
> index 5f83f9f264..d934e00ec3 100644
> --- a/sysdeps/aarch64/__longjmp.S
> +++ b/sysdeps/aarch64/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <stap-probe.h>
>  
> diff --git a/sysdeps/aarch64/jmpbuf-offsets.h b/sysdeps/aarch64/jmpbuf-offsets.h
> index 6256bda7a9..78bdd4a539 100644
> --- a/sysdeps/aarch64/jmpbuf-offsets.h
> +++ b/sysdeps/aarch64/jmpbuf-offsets.h
> @@ -43,6 +43,7 @@
>  #include <setjmp.h>
>  #include <stdint.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf jmpbuf)
> diff --git a/sysdeps/aarch64/setjmp.S b/sysdeps/aarch64/setjmp.S
> index 3860f4e0ec..2ed2feb488 100644
> --- a/sysdeps/aarch64/setjmp.S
> +++ b/sysdeps/aarch64/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <stap-probe.h>
>  
> diff --git a/sysdeps/alpha/__longjmp.S b/sysdeps/alpha/__longjmp.S
> index ec7510bb55..aed7a17ed8 100644
> --- a/sysdeps/alpha/__longjmp.S
> +++ b/sysdeps/alpha/__longjmp.S
> @@ -18,6 +18,7 @@
>  #define __ASSEMBLY__
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  
> diff --git a/sysdeps/alpha/jmpbuf-unwind.h b/sysdeps/alpha/jmpbuf-unwind.h
> index 13b27990b3..318b73b100 100644
> --- a/sysdeps/alpha/jmpbuf-unwind.h
> +++ b/sysdeps/alpha/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame containing a local
>     variable at ADDRESS.  */
> diff --git a/sysdeps/alpha/setjmp.S b/sysdeps/alpha/setjmp.S
> index f86367ae08..deb888c072 100644
> --- a/sysdeps/alpha/setjmp.S
> +++ b/sysdeps/alpha/setjmp.S
> @@ -18,6 +18,7 @@
>  #define __ASSEMBLY__
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  	.ent __sigsetjmp
> diff --git a/sysdeps/arc/jmpbuf-unwind.h b/sysdeps/arc/jmpbuf-unwind.h
> index 5488707919..e5434a95dd 100644
> --- a/sysdeps/arc/jmpbuf-unwind.h
> +++ b/sysdeps/arc/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <jmpbuf-offsets.h>
>  #include <stdint.h>
>  #include <unwind.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/arm/__longjmp.S b/sysdeps/arm/__longjmp.S
> index 5f1cf3643f..411055b9b3 100644
> --- a/sysdeps/arm/__longjmp.S
> +++ b/sysdeps/arm/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #include <bits/setjmp.h>
>  #include <rtld-global-offsets.h>
> diff --git a/sysdeps/arm/jmpbuf-unwind.h b/sysdeps/arm/jmpbuf-unwind.h
> index e6b118f4d0..641444eaf3 100644
> --- a/sysdeps/arm/jmpbuf-unwind.h
> +++ b/sysdeps/arm/jmpbuf-unwind.h
> @@ -18,6 +18,7 @@
>  #include <setjmp.h>
>  #include <stdint.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <unwind.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame

Ok.

> diff --git a/sysdeps/arm/pointer_guard.h b/sysdeps/arm/pointer_guard.h
> new file mode 100644
> index 0000000000..6b90cec2f3
> --- /dev/null
> +++ b/sysdeps/arm/pointer_guard.h
> @@ -0,0 +1,67 @@
> +/* Pointer guard implementation.  Arm version.
> +   Copyright (C) 2013-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +/* Pointer mangling support.  */
> +#if (IS_IN (rtld) \
> +     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE_LOAD(guard, tmp)                                   \
> +  LDR_HIDDEN (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local), 0)
> +#  define PTR_MANGLE(dst, src, guard, tmp)                              \
> +  PTR_MANGLE_LOAD(guard, tmp);                                          \
> +  PTR_MANGLE2(dst, src, guard)
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#  define PTR_MANGLE2(dst, src, guard)          \
> +  eor dst, src, guard
> +#  define PTR_DEMANGLE(dst, src, guard, tmp)    \
> +  PTR_MANGLE (dst, src, guard, tmp)
> +#  define PTR_DEMANGLE2(dst, src, guard)        \
> +  PTR_MANGLE2 (dst, src, guard)
> +# else
> +extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE_LOAD(guard, tmp)                                   \
> +  LDR_GLOBAL (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard), 0);
> +#  define PTR_MANGLE(dst, src, guard, tmp)                              \
> +  PTR_MANGLE_LOAD(guard, tmp);                                          \
> +  PTR_MANGLE2(dst, src, guard)
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#  define PTR_MANGLE2(dst, src, guard)          \
> +  eor dst, src, guard
> +#  define PTR_DEMANGLE(dst, src, guard, tmp)    \
> +  PTR_MANGLE (dst, src, guard, tmp)
> +#  define PTR_DEMANGLE2(dst, src, guard)        \
> +  PTR_MANGLE2 (dst, src, guard)
> +# else
> +#  include <stdint.h>
> +extern uintptr_t __pointer_chk_guard attribute_relro;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/arm/setjmp.S b/sysdeps/arm/setjmp.S
> index 1c26227437..271454d769 100644
> --- a/sysdeps/arm/setjmp.S
> +++ b/sysdeps/arm/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #include <bits/setjmp.h>
>  #include <rtld-global-offsets.h>
> diff --git a/sysdeps/arm/sysdep.h b/sysdeps/arm/sysdep.h
> index f19146b85f..ffd848de88 100644
> --- a/sysdeps/arm/sysdep.h
> +++ b/sysdeps/arm/sysdep.h
> @@ -293,47 +293,3 @@
>  #else
>  # define PC_OFS  8
>  #endif
> -
> -/* Pointer mangling support.  */
> -#if (IS_IN (rtld) \
> -     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE_LOAD(guard, tmp)					\
> -  LDR_HIDDEN (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local), 0)
> -#  define PTR_MANGLE(dst, src, guard, tmp)				\
> -  PTR_MANGLE_LOAD(guard, tmp);						\
> -  PTR_MANGLE2(dst, src, guard)
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#  define PTR_MANGLE2(dst, src, guard)		\
> -  eor dst, src, guard
> -#  define PTR_DEMANGLE(dst, src, guard, tmp)	\
> -  PTR_MANGLE (dst, src, guard, tmp)
> -#  define PTR_DEMANGLE2(dst, src, guard)	\
> -  PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> -#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> -# endif
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE_LOAD(guard, tmp)					\
> -  LDR_GLOBAL (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard), 0);
> -#  define PTR_MANGLE(dst, src, guard, tmp)				\
> -  PTR_MANGLE_LOAD(guard, tmp);						\
> -  PTR_MANGLE2(dst, src, guard)
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#  define PTR_MANGLE2(dst, src, guard)		\
> -  eor dst, src, guard
> -#  define PTR_DEMANGLE(dst, src, guard, tmp)	\
> -  PTR_MANGLE (dst, src, guard, tmp)
> -#  define PTR_DEMANGLE2(dst, src, guard)	\
> -  PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard attribute_relro;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> -#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> -# endif
> -#endif

Ok.

> diff --git a/sysdeps/csky/abiv2/__longjmp.S b/sysdeps/csky/abiv2/__longjmp.S
> index 762b2cb47f..bb7da548c2 100644
> --- a/sysdeps/csky/abiv2/__longjmp.S
> +++ b/sysdeps/csky/abiv2/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  ENTRY (__longjmp)
>  	mov	a2, a0
> diff --git a/sysdeps/csky/abiv2/setjmp.S b/sysdeps/csky/abiv2/setjmp.S
> index 0acf197d02..afef3ce390 100644
> --- a/sysdeps/csky/abiv2/setjmp.S
> +++ b/sysdeps/csky/abiv2/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  ENTRY (setjmp)
>  	movi	a1, 1
> diff --git a/sysdeps/csky/jmpbuf-unwind.h b/sysdeps/csky/jmpbuf-unwind.h
> index 358e912856..76fca431c6 100644
> --- a/sysdeps/csky/jmpbuf-unwind.h
> +++ b/sysdeps/csky/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/generic/pointer_guard.h b/sysdeps/generic/pointer_guard.h
> new file mode 100644
> index 0000000000..58a624e1d5
> --- /dev/null
> +++ b/sysdeps/generic/pointer_guard.h
> @@ -0,0 +1,29 @@
> +/* Pointer obfuscation implenentation.  Generic (no-op) version.
> +   Copyright (C) 2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +/* Assembler code depends on PTR_MANGLE not being defined for
> +   optimization purposes.  */
> +#ifndef __ASSEMBLER__
> +# define PTR_MANGLE(x) (void) (x)
> +# define PTR_DEMANGLE(x) (void) (x)
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok, I think we can improve to use an empty declaration if we really need to
(since the ideia is to eventually always have a generic implementation to 
C code);

> diff --git a/sysdeps/generic/unwind-link.h b/sysdeps/generic/unwind-link.h
> index 93ee80f3f8..a2076a23bf 100644
> --- a/sysdeps/generic/unwind-link.h
> +++ b/sysdeps/generic/unwind-link.h
> @@ -31,7 +31,7 @@ unwind_arch_adjustment (void *prev, void *addr)
>  #endif
>  
>  #ifdef SHARED
> -# include <sysdep.h>
> +# include <pointer_guard.h>
>  # include <unwind-resume.h>
>  
>  # if UNWIND_LINK_FRAME_STATE_FOR
> diff --git a/sysdeps/i386/__longjmp.S b/sysdeps/i386/__longjmp.S
> index 508d370d5c..b67781ceb7 100644
> --- a/sysdeps/i386/__longjmp.S
> +++ b/sysdeps/i386/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/i386/bsd-_setjmp.S b/sysdeps/i386/bsd-_setjmp.S
> index 190e35b0c7..80399dba6e 100644
> --- a/sysdeps/i386/bsd-_setjmp.S
> +++ b/sysdeps/i386/bsd-_setjmp.S
> @@ -21,6 +21,7 @@
>     in setjmp doesn't clobber the state restored by longjmp.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <stap-probe.h>
> diff --git a/sysdeps/i386/bsd-setjmp.S b/sysdeps/i386/bsd-setjmp.S
> index 575ac96208..b367bad85f 100644
> --- a/sysdeps/i386/bsd-setjmp.S
> +++ b/sysdeps/i386/bsd-setjmp.S
> @@ -21,6 +21,7 @@
>     in setjmp doesn't clobber the state restored by longjmp.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <stap-probe.h>
> diff --git a/sysdeps/i386/jmpbuf-unwind.h b/sysdeps/i386/jmpbuf-unwind.h
> index 416c816b45..73d214fd31 100644
> --- a/sysdeps/i386/jmpbuf-unwind.h
> +++ b/sysdeps/i386/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/i386/setjmp.S b/sysdeps/i386/setjmp.S
> index 217efbdf8a..b528245806 100644
> --- a/sysdeps/i386/setjmp.S
> +++ b/sysdeps/i386/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/loongarch/__longjmp.S b/sysdeps/loongarch/__longjmp.S
> index d6a99fcbc8..4c40ffa158 100644
> --- a/sysdeps/loongarch/__longjmp.S
> +++ b/sysdeps/loongarch/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <sys/asm.h>
>  
>  ENTRY (__longjmp)
> diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
> index 6fa509151d..458edec135 100644
> --- a/sysdeps/loongarch/jmpbuf-unwind.h
> +++ b/sysdeps/loongarch/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/loongarch/setjmp.S b/sysdeps/loongarch/setjmp.S
> index 9b1cdea48c..e5f480d453 100644
> --- a/sysdeps/loongarch/setjmp.S
> +++ b/sysdeps/loongarch/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <sys/asm.h>
>  
>  ENTRY (_setjmp)
> diff --git a/sysdeps/m68k/jmpbuf-unwind.h b/sysdeps/m68k/jmpbuf-unwind.h
> index 17e4b859ab..3ee46c050c 100644
> --- a/sysdeps/m68k/jmpbuf-unwind.h
> +++ b/sysdeps/m68k/jmpbuf-unwind.h
> @@ -19,6 +19,7 @@
>  #include <setjmp.h>
>  #include <stdint.h>
>  #include <unwind.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/mach/hurd/i386/____longjmp_chk.S b/sysdeps/mach/hurd/i386/____longjmp_chk.S
> index 1a019e2e2b..81d297de0c 100644
> --- a/sysdeps/mach/hurd/i386/____longjmp_chk.S
> +++ b/sysdeps/mach/hurd/i386/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <tcb-offsets.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/mach/hurd/i386/__longjmp.S b/sysdeps/mach/hurd/i386/__longjmp.S
> index 72fcc79f4b..22915fb21e 100644
> --- a/sysdeps/mach/hurd/i386/__longjmp.S
> +++ b/sysdeps/mach/hurd/i386/__longjmp.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <tcb-offsets.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/mach/hurd/jmp-unwind.c b/sysdeps/mach/hurd/jmp-unwind.c
> index f8938bc6f4..2577fbf3ee 100644
> --- a/sysdeps/mach/hurd/jmp-unwind.c
> +++ b/sysdeps/mach/hurd/jmp-unwind.c
> @@ -22,7 +22,7 @@
>  #include <hurd/sigpreempt.h>
>  #include <assert.h>
>  #include <stdint.h>
> -
> +#include <pointer_guard.h>
>  
>  #ifndef _JMPBUF_UNWINDS
>  #error "<jmpbuf-unwind.h> fails to define _JMPBUF_UNWINDS"
> diff --git a/sysdeps/microblaze/jmpbuf-unwind.h b/sysdeps/microblaze/jmpbuf-unwind.h
> index f23c7581a7..302e950ced 100644
> --- a/sysdeps/microblaze/jmpbuf-unwind.h
> +++ b/sysdeps/microblaze/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/mips/jmpbuf-unwind.h b/sysdeps/mips/jmpbuf-unwind.h
> index 813c24f3b1..28ecffedb0 100644
> --- a/sysdeps/mips/jmpbuf-unwind.h
> +++ b/sysdeps/mips/jmpbuf-unwind.h
> @@ -19,6 +19,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/nios2/__longjmp.S b/sysdeps/nios2/__longjmp.S
> index 214901d67d..13695e25a6 100644
> --- a/sysdeps/nios2/__longjmp.S
> +++ b/sysdeps/nios2/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  /* __longjmp(jmpbuf, val) */
> diff --git a/sysdeps/nios2/jmpbuf-offsets.h b/sysdeps/nios2/jmpbuf-offsets.h
> index a13aa76c16..76fea64ffe 100644
> --- a/sysdeps/nios2/jmpbuf-offsets.h
> +++ b/sysdeps/nios2/jmpbuf-offsets.h
> @@ -32,6 +32,7 @@
>  #include <setjmp.h>
>  #include <stdint.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf jmpbuf)
> diff --git a/sysdeps/nios2/setjmp.S b/sysdeps/nios2/setjmp.S
> index 0aa5b23d4f..ec75108b87 100644
> --- a/sysdeps/nios2/setjmp.S
> +++ b/sysdeps/nios2/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  	.text
> diff --git a/sysdeps/powerpc/jmpbuf-unwind.h b/sysdeps/powerpc/jmpbuf-unwind.h
> index 706ceda5d4..93573ce238 100644
> --- a/sysdeps/powerpc/jmpbuf-unwind.h
> +++ b/sysdeps/powerpc/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/powerpc/powerpc32/__longjmp-common.S b/sysdeps/powerpc/powerpc32/__longjmp-common.S
> index 13ded200e2..0e0361e4fd 100644
> --- a/sysdeps/powerpc/powerpc32/__longjmp-common.S
> +++ b/sysdeps/powerpc/powerpc32/__longjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #ifdef __NO_VMX__
> diff --git a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
> index e3937222a7..de04a62be2 100644
> --- a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
> +++ b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #ifdef __NO_VMX__
> diff --git a/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S b/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
> index f82196e6c2..1943ffd229 100644
> --- a/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
> +++ b/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #ifdef __NO_VMX__
> diff --git a/sysdeps/powerpc/powerpc32/setjmp-common.S b/sysdeps/powerpc/powerpc32/setjmp-common.S
> index c632a3f8f2..281dd65f6a 100644
> --- a/sysdeps/powerpc/powerpc32/setjmp-common.S
> +++ b/sysdeps/powerpc/powerpc32/setjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #ifdef __NO_VMX__
> diff --git a/sysdeps/powerpc/powerpc64/__longjmp-common.S b/sysdeps/powerpc/powerpc64/__longjmp-common.S
> index 5f629e1e0f..ff3e0beb23 100644
> --- a/sysdeps/powerpc/powerpc64/__longjmp-common.S
> +++ b/sysdeps/powerpc/powerpc64/__longjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #define _SETJMP_H
> diff --git a/sysdeps/powerpc/powerpc64/setjmp-common.S b/sysdeps/powerpc/powerpc64/setjmp-common.S
> index 19e76d59ee..75389e4d26 100644
> --- a/sysdeps/powerpc/powerpc64/setjmp-common.S
> +++ b/sysdeps/powerpc/powerpc64/setjmp-common.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <stap-probe.h>
>  #define _ASM
>  #ifdef __NO_VMX__
> diff --git a/sysdeps/riscv/jmpbuf-unwind.h b/sysdeps/riscv/jmpbuf-unwind.h
> index 28e73dda55..b411a246d1 100644
> --- a/sysdeps/riscv/jmpbuf-unwind.h
> +++ b/sysdeps/riscv/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/s390/jmpbuf-unwind.h b/sysdeps/s390/jmpbuf-unwind.h
> index b4ff8da6e2..10b37f09c3 100644
> --- a/sysdeps/s390/jmpbuf-unwind.h
> +++ b/sysdeps/s390/jmpbuf-unwind.h
> @@ -21,6 +21,7 @@
>  #include <unwind.h>
>  #include <bits/wordsize.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
> diff --git a/sysdeps/s390/s390-32/__longjmp.c b/sysdeps/s390/s390-32/__longjmp.c
> index 09a3a2b8f8..83d42329a3 100644
> --- a/sysdeps/s390/s390-32/__longjmp.c
> +++ b/sysdeps/s390/s390-32/__longjmp.c
> @@ -17,6 +17,7 @@
>  
>  #include <errno.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <setjmp.h>
>  #include <bits/setjmp.h>
>  #include <stdlib.h>
> diff --git a/sysdeps/s390/s390-32/setjmp.S b/sysdeps/s390/s390-32/setjmp.S
> index c15c7bb99a..08704238f8 100644
> --- a/sysdeps/s390/s390-32/setjmp.S
> +++ b/sysdeps/s390/s390-32/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #define _ASM
>  #define _SETJMP_H
>  #include <bits/setjmp.h>
> diff --git a/sysdeps/s390/s390-64/__longjmp.c b/sysdeps/s390/s390-64/__longjmp.c
> index 2ca96e1b1b..9fe4939e5e 100644
> --- a/sysdeps/s390/s390-64/__longjmp.c
> +++ b/sysdeps/s390/s390-64/__longjmp.c
> @@ -17,6 +17,7 @@
>  
>  #include <errno.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <setjmp.h>
>  #include <bits/setjmp.h>
>  #include <stdlib.h>
> diff --git a/sysdeps/s390/s390-64/setjmp.S b/sysdeps/s390/s390-64/setjmp.S
> index 6dcd77df15..5c59f571a2 100644
> --- a/sysdeps/s390/s390-64/setjmp.S
> +++ b/sysdeps/s390/s390-64/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #define _ASM
>  #define _SETJMP_H
>  #include <bits/setjmp.h>
> diff --git a/sysdeps/sh/jmpbuf-unwind.h b/sysdeps/sh/jmpbuf-unwind.h
> index c6672955ae..1957e5275d 100644
> --- a/sysdeps/sh/jmpbuf-unwind.h
> +++ b/sysdeps/sh/jmpbuf-unwind.h
> @@ -19,6 +19,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/sh/sh3/__longjmp.S b/sysdeps/sh/sh3/__longjmp.S
> index 4228b5fef7..f10bed2afe 100644
> --- a/sysdeps/sh/sh3/__longjmp.S
> +++ b/sysdeps/sh/sh3/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #define _SETJMP_H
>  #define _ASM
>  #include <bits/setjmp.h>
> diff --git a/sysdeps/sh/sh3/setjmp.S b/sysdeps/sh/sh3/setjmp.S
> index 0dd0003efe..363e16fb15 100644
> --- a/sysdeps/sh/sh3/setjmp.S
> +++ b/sysdeps/sh/sh3/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  ENTRY (__sigsetjmp)
> diff --git a/sysdeps/sh/sh4/__longjmp.S b/sysdeps/sh/sh4/__longjmp.S
> index 2013b71794..bc179e4584 100644
> --- a/sysdeps/sh/sh4/__longjmp.S
> +++ b/sysdeps/sh/sh4/__longjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #define _SETJMP_H
>  #define _ASM
>  #include <bits/setjmp.h>
> diff --git a/sysdeps/sh/sh4/setjmp.S b/sysdeps/sh/sh4/setjmp.S
> index b73aa3c18c..f28ec42091 100644
> --- a/sysdeps/sh/sh4/setjmp.S
> +++ b/sysdeps/sh/sh4/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  ENTRY (__sigsetjmp)
> diff --git a/sysdeps/sparc/sparc32/__longjmp.S b/sysdeps/sparc/sparc32/__longjmp.S
> index 5bed2440ac..68b3b15cb1 100644
> --- a/sysdeps/sparc/sparc32/__longjmp.S
> +++ b/sysdeps/sparc/sparc32/__longjmp.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #include <jmpbuf-offsets.h>
>  #define ENV(base,reg) [%base + (reg * 4)]
> diff --git a/sysdeps/sparc/sparc32/jmpbuf-unwind.h b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> index 3ab5088555..8b697ed95b 100644
> --- a/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> +++ b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/sparc/sparc32/setjmp.S b/sysdeps/sparc/sparc32/setjmp.S
> index 9c7531bc95..c4e29c47b9 100644
> --- a/sysdeps/sparc/sparc32/setjmp.S
> +++ b/sysdeps/sparc/sparc32/setjmp.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <sys/trap.h>
>  
>  #include <jmpbuf-offsets.h>

Ok.

> diff --git a/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
> new file mode 100644
> index 0000000000..b81c9075f3
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
> @@ -0,0 +1,68 @@
> +/* Pointer guard implementation.  AArch64 version.
> +   Copyright (C) 2014-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +/* Pointer mangling is supported for AArch64.  */
> +#if (IS_IN (rtld) \
> +     || (!defined SHARED && (IS_IN (libc) \
> +                             || IS_IN (libpthread))))
> +# ifdef __ASSEMBLER__
> +/* Note, dst, src, guard, and tmp are all register numbers rather than
> +   register names so they will work with both ILP32 and LP64. */
> +#  define PTR_MANGLE(dst, src, guard, tmp)                                \
> +  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
> +  PTR_MANGLE2 (dst, src, guard)
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#  define PTR_MANGLE2(dst, src, guard)\
> +  eor x##dst, x##src, x##guard
> +#  define PTR_DEMANGLE(dst, src, guard, tmp)\
> +  PTR_MANGLE (dst, src, guard, tmp)
> +#  define PTR_DEMANGLE2(dst, src, guard)\
> +  PTR_MANGLE2 (dst, src, guard)
> +# else
> +extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#else
> +# ifdef __ASSEMBLER__
> +/* Note, dst, src, guard, and tmp are all register numbers rather than
> +   register names so they will work with both ILP32 and LP64. */
> +#  define PTR_MANGLE(dst, src, guard, tmp)                             \
> +  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
> +  PTR_MANGLE2 (dst, src, guard)
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#  define PTR_MANGLE2(dst, src, guard)\
> +  eor x##dst, x##src, x##guard
> +#  define PTR_DEMANGLE(dst, src, guard, tmp)\
> +  PTR_MANGLE (dst, src, guard, tmp)
> +#  define PTR_DEMANGLE2(dst, src, guard)\
> +  PTR_MANGLE2 (dst, src, guard)
> +# else
> +#  include <stdint.h>
> +extern uintptr_t __pointer_chk_guard attribute_relro;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> +#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> index f1853e012f..8ba50dab8f 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> @@ -233,49 +233,4 @@
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -/* Pointer mangling is supported for AArch64.  */
> -#if (IS_IN (rtld) \
> -     || (!defined SHARED && (IS_IN (libc) \
> -			     || IS_IN (libpthread))))
> -# ifdef __ASSEMBLER__
> -/* Note, dst, src, guard, and tmp are all register numbers rather than
> -   register names so they will work with both ILP32 and LP64. */
> -#  define PTR_MANGLE(dst, src, guard, tmp)                                \
> -  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
> -  PTR_MANGLE2 (dst, src, guard)
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#  define PTR_MANGLE2(dst, src, guard)\
> -  eor x##dst, x##src, x##guard
> -#  define PTR_DEMANGLE(dst, src, guard, tmp)\
> -  PTR_MANGLE (dst, src, guard, tmp)
> -#  define PTR_DEMANGLE2(dst, src, guard)\
> -  PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> -#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> -# endif
> -#else
> -# ifdef __ASSEMBLER__
> -/* Note, dst, src, guard, and tmp are all register numbers rather than
> -   register names so they will work with both ILP32 and LP64. */
> -#  define PTR_MANGLE(dst, src, guard, tmp)                             \
> -  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
> -  PTR_MANGLE2 (dst, src, guard)
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#  define PTR_MANGLE2(dst, src, guard)\
> -  eor x##dst, x##src, x##guard
> -#  define PTR_DEMANGLE(dst, src, guard, tmp)\
> -  PTR_MANGLE (dst, src, guard, tmp)
> -#  define PTR_DEMANGLE2(dst, src, guard)\
> -  PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard attribute_relro;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> -#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/aarch64/sysdep.h */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S b/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
> index 610f401d45..566a3b0211 100644
> --- a/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/pointer_guard.h b/sysdeps/unix/sysv/linux/alpha/pointer_guard.h
> new file mode 100644
> index 0000000000..d4d513d816
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/pointer_guard.h
> @@ -0,0 +1,62 @@
> +/* Pointer guard implementation.  Alpha version.
> +   Copyright (C) 2006-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +/* Pointer mangling support.  Note that tls access is slow enough that
> +   we don't deoptimize things by placing the pointer check value there.  */
> +
> +#ifdef __ASSEMBLER__
> +# if IS_IN (rtld)
> +#  define PTR_MANGLE(dst, src, tmp)                             \
> +        ldah    tmp, __pointer_chk_guard_local($29) !gprelhigh; \
> +        ldq     tmp, __pointer_chk_guard_local(tmp) !gprellow;  \
> +        xor     src, tmp, dst
> +#  define PTR_MANGLE2(dst, src, tmp)                            \
> +        xor     src, tmp, dst
> +# elif defined SHARED
> +#  define PTR_MANGLE(dst, src, tmp)             \
> +        ldq     tmp, __pointer_chk_guard;       \
> +        xor     src, tmp, dst
> +# else
> +#  define PTR_MANGLE(dst, src, tmp)             \
> +        ldq     tmp, __pointer_chk_guard_local; \
> +        xor     src, tmp, dst
> +# endif
> +# define PTR_MANGLE2(dst, src, tmp)             \
> +        xor     src, tmp, dst
> +# define PTR_DEMANGLE(dst, tmp)   PTR_MANGLE(dst, dst, tmp)
> +# define PTR_DEMANGLE2(dst, tmp)  PTR_MANGLE2(dst, dst, tmp)
> +#else
> +# include <stdint.h>
> +# if (IS_IN (rtld) \
> +      || (!defined SHARED && (IS_IN (libc) \
> +                              || IS_IN (libpthread))))
> +extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> +#  define PTR_MANGLE(var) \
> +        (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> +# else
> +extern uintptr_t __pointer_chk_guard attribute_relro;
> +#  define PTR_MANGLE(var) \
> +        (var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> +# endif
> +# define PTR_DEMANGLE(var)  PTR_MANGLE(var)
> +#endif /* ASSEMBLER */
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep.h b/sysdeps/unix/sysv/linux/alpha/sysdep.h
> index 77ec2b5400..0ddcb58b30 100644
> --- a/sysdeps/unix/sysv/linux/alpha/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/alpha/sysdep.h
> @@ -313,44 +313,4 @@ __LABEL(name)						\
>  })
>  #endif /* ASSEMBLER */
>  
> -/* Pointer mangling support.  Note that tls access is slow enough that
> -   we don't deoptimize things by placing the pointer check value there.  */
> -
> -#ifdef __ASSEMBLER__
> -# if IS_IN (rtld)
> -#  define PTR_MANGLE(dst, src, tmp)				\
> -	ldah	tmp, __pointer_chk_guard_local($29) !gprelhigh;	\
> -	ldq	tmp, __pointer_chk_guard_local(tmp) !gprellow;	\
> -	xor	src, tmp, dst
> -#  define PTR_MANGLE2(dst, src, tmp)				\
> -	xor	src, tmp, dst
> -# elif defined SHARED
> -#  define PTR_MANGLE(dst, src, tmp)		\
> -	ldq	tmp, __pointer_chk_guard;	\
> -	xor	src, tmp, dst
> -# else
> -#  define PTR_MANGLE(dst, src, tmp)		\
> -	ldq	tmp, __pointer_chk_guard_local;	\
> -	xor	src, tmp, dst
> -# endif
> -# define PTR_MANGLE2(dst, src, tmp)		\
> -	xor	src, tmp, dst
> -# define PTR_DEMANGLE(dst, tmp)   PTR_MANGLE(dst, dst, tmp)
> -# define PTR_DEMANGLE2(dst, tmp)  PTR_MANGLE2(dst, dst, tmp)
> -#else
> -# include <stdint.h>
> -# if (IS_IN (rtld) \
> -      || (!defined SHARED && (IS_IN (libc) \
> -			      || IS_IN (libpthread))))
> -extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> -#  define PTR_MANGLE(var) \
> -	(var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> -# else
> -extern uintptr_t __pointer_chk_guard attribute_relro;
> -#  define PTR_MANGLE(var) \
> -	(var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> -# endif
> -# define PTR_DEMANGLE(var)  PTR_MANGLE(var)
> -#endif /* ASSEMBLER */
> -
>  #endif /* _LINUX_ALPHA_SYSDEP_H  */
> diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
> index d0c1a78381..512284a705 100644
> --- a/sysdeps/unix/sysv/linux/arc/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
> @@ -215,10 +215,6 @@ hidden_proto (__syscall_error)
>    LOAD_ARGS_6 (nm, arg1, arg2, arg3, arg4, arg5, arg6)	\
>    register long int _arg7 __asm__ ("r6") = _tmp7;
>  
> -/* Pointer mangling not yet supported.  */
> -# define PTR_MANGLE(var) (void) (var)
> -# define PTR_DEMANGLE(var) (void) (var)
> -
>  # undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
>  # define HAVE_INTERNAL_BRK_ADDR_SYMBOL  1
>  

Ok.

> diff --git a/sysdeps/unix/sysv/linux/csky/pointer_guard.h b/sysdeps/unix/sysv/linux/csky/pointer_guard.h
> new file mode 100644
> index 0000000000..ed683220c9
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/csky/pointer_guard.h
> @@ -0,0 +1,68 @@
> +/* Pointer obfuscation implenentation.  C-SKY version.
> +   Copyright (C) 2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if (IS_IN (rtld) \
> +     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(dst, src, guard)                   \
> +        grs     t0, 1f;                                 \
> +1:                                                      \
> +        lrw     guard, 1b@GOTPC;                        \
> +        addu    t0, guard;                              \
> +        lrw     guard, __pointer_chk_guard_local@GOT;   \
> +        ldr.w   guard, (t0, guard << 0);                \
> +        ldw     guard, (guard, 0);                      \
> +        xor     dst, src, guard;
> +#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> +#  define PTR_MANGLE2(dst, src, guard) \
> +        xor     dst, src, guard
> +#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
> +# else
> +extern uintptr_t __pointer_chk_guard_local;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> +#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> +# endif
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(dst, src, guard)           \
> +        grs     t0, 1f;                         \
> +1:                                              \
> +        lrw     guard, 1b@GOTPC;                \
> +        addu    t0, guard;                      \
> +        lrw     guard, __pointer_chk_guard@GOT; \
> +        ldr.w   guard, (t0, guard << 0);        \
> +        ldw     guard, (guard, 0);              \
> +        xor     dst, src, guard;
> +#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> +#  define PTR_MANGLE2(dst, src, guard) \
> +        xor     dst, src, guard
> +#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
> +# else
> +# include <stdint.h>
> +extern uintptr_t __pointer_chk_guard;
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> +#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/csky/sysdep.h b/sysdeps/unix/sysv/linux/csky/sysdep.h
> index 56c527fa8b..76b09f0cc6 100644
> --- a/sysdeps/unix/sysv/linux/csky/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/csky/sysdep.h
> @@ -466,50 +466,4 @@ __local_syscall_error:				\
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if (IS_IN (rtld) \
> -     || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(dst, src, guard)			\
> -	grs	t0, 1f;					\
> -1:							\
> -	lrw	guard, 1b@GOTPC;			\
> -	addu	t0, guard;				\
> -	lrw	guard, __pointer_chk_guard_local@GOT;	\
> -	ldr.w	guard, (t0, guard << 0);		\
> -	ldw	guard, (guard, 0);			\
> -	xor	dst, src, guard;
> -#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> -#  define PTR_MANGLE2(dst, src, guard) \
> -	xor	dst, src, guard
> -#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard_local;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> -#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> -# endif
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(dst, src, guard)		\
> -	grs	t0, 1f;				\
> -1:						\
> -	lrw	guard, 1b@GOTPC;		\
> -	addu	t0, guard;			\
> -	lrw	guard, __pointer_chk_guard@GOT;	\
> -	ldr.w	guard, (t0, guard << 0);	\
> -	ldw	guard, (guard, 0);		\
> -	xor	dst, src, guard;
> -#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> -#  define PTR_MANGLE2(dst, src, guard) \
> -	xor	dst, src, guard
> -#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
> -# else
> -extern uintptr_t __pointer_chk_guard;
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> -#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/csky/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.h b/sysdeps/unix/sysv/linux/hppa/sysdep.h
> index 2f339a4bd6..3aef8f536a 100644
> --- a/sysdeps/unix/sysv/linux/hppa/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/hppa/sysdep.h
> @@ -470,8 +470,4 @@ L(pre_end):					ASM_LINE_SEP	\
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -/* Pointer mangling is not yet supported for HPPA.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  #endif /* _LINUX_HPPA_SYSDEP_H */
> diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
> index a1cf9a4b21..f409542a62 100644
> --- a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/unix/sysv/linux/i386/pointer_guard.h b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
> new file mode 100644
> index 0000000000..a2d2a0c38b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
> @@ -0,0 +1,49 @@
> +/* Pointer obfuscation implenentation.  i386 version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#include <tcb-offsets.h>
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  Using a global variable
> +   is too complicated here since we have no PC-relative addressing mode.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg)       xorl %gs:POINTER_GUARD, reg;                  \
> +                                roll $9, reg
> +#  define PTR_DEMANGLE(reg)     rorl $9, reg;                                 \
> +                                xorl %gs:POINTER_GUARD, reg
> +# else
> +#  define PTR_MANGLE(var)       asm ("xorl %%gs:%c2, %0\n"                    \
> +                                     "roll $9, %0"                            \
> +                                     : "=r" (var)                             \
> +                                     : "0" (var),                             \
> +                                       "i" (POINTER_GUARD))
> +#  define PTR_DEMANGLE(var)     asm ("rorl $9, %0\n"                          \
> +                                     "xorl %%gs:%c2, %0"                      \
> +                                     : "=r" (var)                             \
> +                                     : "0" (var),                             \
> +                                       "i" (POINTER_GUARD))
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */


Ok.
> diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
> index 7085f7e19a..b8be668a42 100644
> --- a/sysdeps/unix/sysv/linux/i386/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
> @@ -446,34 +446,6 @@ struct libc_do_syscall_args
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  Using a global variable
> -   is too complicated here since we have no PC-relative addressing mode.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg)	xorl %gs:POINTER_GUARD, reg;		      \
> -				roll $9, reg
> -#  define PTR_DEMANGLE(reg)	rorl $9, reg;				      \
> -				xorl %gs:POINTER_GUARD, reg
> -# else
> -#  define PTR_MANGLE(var)	asm ("xorl %%gs:%c2, %0\n"		      \
> -				     "roll $9, %0"			      \
> -				     : "=r" (var)			      \
> -				     : "0" (var),			      \
> -				       "i" (offsetof (tcbhead_t,	      \
> -						      pointer_guard)))
> -#  define PTR_DEMANGLE(var)	asm ("rorl $9, %0\n"			      \
> -				     "xorl %%gs:%c2, %0"		      \
> -				     : "=r" (var)			      \
> -				     : "0" (var),			      \
> -				       "i" (offsetof (tcbhead_t,	      \
> -						      pointer_guard)))
> -# endif
> -#endif
> -
>  /* Each shadow stack slot takes 4 bytes.  Assuming that each stack
>     frame takes 128 bytes, this is used to compute shadow stack size
>     from stack size.  */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S b/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
> index 9511c15945..4ef5129623 100644
> --- a/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
> +++ b/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
> @@ -15,6 +15,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <features.h>
>  
>  LEAF(__ia64_flush_rbs)
> diff --git a/sysdeps/unix/sysv/linux/ia64/__longjmp.S b/sysdeps/unix/sysv/linux/ia64/__longjmp.S
> index 793dc98cc1..da9653d8a7 100644
> --- a/sysdeps/unix/sysv/linux/ia64/__longjmp.S
> +++ b/sysdeps/unix/sysv/linux/ia64/__longjmp.S
> @@ -31,6 +31,7 @@
>  		bits into ar.rnat after setting ar.bspstore. */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <features.h>
>  
>  #	define	pPos	p6	/* is rotate count positive? */
> diff --git a/sysdeps/unix/sysv/linux/ia64/pointer_guard.h b/sysdeps/unix/sysv/linux/ia64/pointer_guard.h
> new file mode 100644
> index 0000000000..8631f39374
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/ia64/pointer_guard.h
> @@ -0,0 +1,44 @@
> +/* Pointer obfuscation implenentation.  ia64 version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg, tmpreg) \
> +        add     tmpreg=-16,r13          \
> +        ;;                              \
> +        ld8     tmpreg=[tmpreg]         \
> +        ;;                              \
> +        xor     reg=reg, tmpreg
> +#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/ia64/setjmp.S b/sysdeps/unix/sysv/linux/ia64/setjmp.S
> index c29a31f7a6..a978dd4360 100644
> --- a/sysdeps/unix/sysv/linux/ia64/setjmp.S
> +++ b/sysdeps/unix/sysv/linux/ia64/setjmp.S
> @@ -63,6 +63,7 @@
>  	0x1c0	f31 */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <features.h>
>  
>  	/* The following two entry points are the traditional entry points: */
> diff --git a/sysdeps/unix/sysv/linux/ia64/sysdep.h b/sysdeps/unix/sysv/linux/ia64/sysdep.h
> index 14adbdf4ff..b450c6c224 100644
> --- a/sysdeps/unix/sysv/linux/ia64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/ia64/sysdep.h
> @@ -324,24 +324,4 @@
>  
>  #endif /* not __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg, tmpreg) \
> -        add	tmpreg=-16,r13		\
> -        ;;				\
> -        ld8	tmpreg=[tmpreg]		\
> -        ;;				\
> -        xor	reg=reg, tmpreg
> -#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/ia64/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h b/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
> new file mode 100644
> index 0000000000..4b2ed46167
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/pointer_guard.h
> @@ -0,0 +1,82 @@
> +/* Pointer obfuscation implenentation.  LoongArch version.
> +   Copyright (C) 2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +/* Load a got-relative EXPR into G, using T.
> +   Note G and T are register names.  */
> +#define LD_GLOBAL(G, EXPR) \
> +  la.global G,  EXPR; \
> +  REG_L     G,  G,  0;
> +
> +/* Load a pc-relative EXPR into G, using T.
> +   Note G and T are register names.  */
> +#define LD_PCREL(G, EXPR) \
> +  la.pcrel  G,  EXPR; \
> +  REG_L     G,  G,  0;
> +
> +#if (IS_IN (rtld) \
> +     || (!defined SHARED && (IS_IN (libc) \
> +     || IS_IN (libpthread))))
> +
> +#ifdef __ASSEMBLER__
> +#define PTR_MANGLE(dst, src, guard) \
> +  LD_PCREL (guard, __pointer_chk_guard_local); \
> +  PTR_MANGLE2 (dst, src, guard);
> +#define PTR_DEMANGLE(dst, src, guard) \
> +  LD_PCREL (guard, __pointer_chk_guard_local); \
> +  PTR_DEMANGLE2 (dst, src, guard);
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#define PTR_MANGLE2(dst, src, guard) \
> +  xor  dst, src, guard;
> +#define PTR_DEMANGLE2(dst, src, guard) \
> +  PTR_MANGLE2 (dst, src, guard);
> +#else
> +# include <stdint.h>
> +extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> +#define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> +#define PTR_DEMANGLE(var) PTR_MANGLE (var)
> +#endif
> +
> +#else
> +
> +#ifdef __ASSEMBLER__
> +#define PTR_MANGLE(dst, src, guard) \
> +  LD_GLOBAL (guard, __pointer_chk_guard); \
> +  PTR_MANGLE2 (dst, src, guard);
> +#define PTR_DEMANGLE(dst, src, guard) \
> +  LD_GLOBAL (guard, __pointer_chk_guard); \
> +  PTR_DEMANGLE2 (dst, src, guard);
> +/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> +#define PTR_MANGLE2(dst, src, guard) \
> +  xor dst, src, guard;
> +#define PTR_DEMANGLE2(dst, src, guard) \
> +  PTR_MANGLE2 (dst, src, guard);
> +#else
> +# include <stdint.h>
> +extern uintptr_t __pointer_chk_guard attribute_relro;
> +#define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> +#define PTR_DEMANGLE(var) PTR_MANGLE (var)
> +#endif
> +
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> index f4a1d23a97..09f8243f25 100644
> --- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> @@ -314,64 +314,4 @@ extern long int __syscall_error (long int neg_errno);
>  
>  #endif /* ! __ASSEMBLER__ */
>  
> -/* Pointer mangling is supported for LoongArch.  */
> -
> -/* Load a got-relative EXPR into G, using T.
> -   Note G and T are register names.  */
> -#define LD_GLOBAL(G, EXPR) \
> -  la.global G,	EXPR; \
> -  REG_L	    G,	G,  0;
> -
> -/* Load a pc-relative EXPR into G, using T.
> -   Note G and T are register names.  */
> -#define LD_PCREL(G, EXPR) \
> -  la.pcrel  G,	EXPR; \
> -  REG_L	    G,	G,  0;
> -
> -#if (IS_IN (rtld) \
> -     || (!defined SHARED && (IS_IN (libc) \
> -     || IS_IN (libpthread))))
> -
> -#ifdef __ASSEMBLER__
> -#define PTR_MANGLE(dst, src, guard) \
> -  LD_PCREL (guard, __pointer_chk_guard_local); \
> -  PTR_MANGLE2 (dst, src, guard);
> -#define PTR_DEMANGLE(dst, src, guard) \
> -  LD_PCREL (guard, __pointer_chk_guard_local); \
> -  PTR_DEMANGLE2 (dst, src, guard);
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#define PTR_MANGLE2(dst, src, guard) \
> -  xor  dst, src, guard;
> -#define PTR_DEMANGLE2(dst, src, guard) \
> -  PTR_MANGLE2 (dst, src, guard);
> -#else
> -extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
> -#define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
> -#define PTR_DEMANGLE(var) PTR_MANGLE (var)
> -#endif
> -
> -#else
> -
> -#ifdef __ASSEMBLER__
> -#define PTR_MANGLE(dst, src, guard) \
> -  LD_GLOBAL (guard, __pointer_chk_guard); \
> -  PTR_MANGLE2 (dst, src, guard);
> -#define PTR_DEMANGLE(dst, src, guard) \
> -  LD_GLOBAL (guard, __pointer_chk_guard); \
> -  PTR_DEMANGLE2 (dst, src, guard);
> -/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
> -#define PTR_MANGLE2(dst, src, guard) \
> -  xor dst, src, guard;
> -#define PTR_DEMANGLE2(dst, src, guard) \
> -  PTR_MANGLE2 (dst, src, guard);
> -#else
> -extern uintptr_t __pointer_chk_guard attribute_relro;
> -#define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
> -#define PTR_DEMANGLE(var) PTR_MANGLE (var)
> -#endif
> -
> -#endif
> -
>  #endif /* linux/loongarch/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep.h b/sysdeps/unix/sysv/linux/m68k/sysdep.h
> index d87892a377..064240330a 100644
> --- a/sysdeps/unix/sysv/linux/m68k/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/m68k/sysdep.h
> @@ -295,10 +295,6 @@ SYSCALL_ERROR_LABEL:							      \
>  
>  #endif /* not __ASSEMBLER__ */
>  
> -/* Pointer mangling is not yet supported for M68K.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  /* M68K needs system-supplied DSO to access TLS helpers
>     even when statically linked.  */
>  #define NEED_STATIC_SYSINFO_DSO 1
> diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
> index fda78f6467..19805f6b5d 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
> @@ -304,10 +304,6 @@ SYSCALL_ERROR_LABEL_DCL:                            \
>    })
>  
>  
> -/* Pointer mangling is not yet supported for Microblaze.  */
> -# define PTR_MANGLE(var) (void) (var)
> -# define PTR_DEMANGLE(var) (void) (var)
> -
>  #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
>  #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
>  
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
> index a2a93bc840..0ef410c3c9 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
> @@ -337,8 +337,4 @@ libc_hidden_proto (__mips_syscall7, nomips16)
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling is not yet supported for MIPS.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  #endif /* linux/mips/mips32/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
> index 2c16a6758d..e362f15300 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
> @@ -300,8 +300,4 @@ typedef long int __syscall_arg_t;
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling is not yet supported for MIPS.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  #endif /* linux/mips/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/nios2/pointer_guard.h b/sysdeps/unix/sysv/linux/nios2/pointer_guard.h
> new file mode 100644
> index 0000000000..da17809592
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/nios2/pointer_guard.h
> @@ -0,0 +1,40 @@
> +/* Pointer obfuscation implenentation.  Nios II version.
> +   Copyright (C) 2015-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23)
> +#  define PTR_MANGLE(dst, src, guard) xor dst, src, guard
> +#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.h b/sysdeps/unix/sysv/linux/nios2/sysdep.h
> index 5fe960c2a5..46667b9c19 100644
> --- a/sysdeps/unix/sysv/linux/nios2/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/nios2/sysdep.h
> @@ -220,21 +220,4 @@
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23)
> -#  define PTR_MANGLE(dst, src, guard) xor dst, src, guard
> -#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
> -
>  #endif /* linux/nios2/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/or1k/sysdep.h b/sysdeps/unix/sysv/linux/or1k/sysdep.h
> index 941c934554..b1fdf2a806 100644
> --- a/sysdeps/unix/sysv/linux/or1k/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/or1k/sysdep.h
> @@ -119,10 +119,6 @@ L(pseudo_end): \
>  
>  extern long int __syscall_error (long int neg_errno);
>  
> -/* Pointer mangling is not yet supported for or1k.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  #undef INTERNAL_SYSCALL
>  #define INTERNAL_SYSCALL(name, nr, args...) \
>  	INTERNAL_SYSCALL_NCS (SYS_ify (name), nr, args)
> diff --git a/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h b/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
> new file mode 100644
> index 0000000000..5961793c0d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/powerpc/pointer_guard.h
> @@ -0,0 +1,55 @@
> +/* Pointer obfuscation implenentation.  PowerpC version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  if defined(__PPC64__) || defined(__powerpc64__)
> +#   define LOAD  ld
> +#   define TPREG r13
> +#  else
> +#   define LOAD  lwz
> +#   define TPREG r2
> +#  endif
> +#  define PTR_MANGLE(reg, tmpreg) \
> +        LOAD    tmpreg,POINTER_GUARD(TPREG); \
> +        xor     reg,tmpreg,reg
> +#  define PTR_MANGLE2(reg, tmpreg) \
> +        xor     reg,tmpreg,reg
> +#  define PTR_MANGLE3(destreg, reg, tmpreg) \
> +        LOAD    tmpreg,POINTER_GUARD(TPREG); \
> +        xor     destreg,tmpreg,reg
> +#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> +#  define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
> +#  define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
> index 4fb135aa8d..9e44818978 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
> @@ -207,38 +207,6 @@
>  #define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
>  #define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
>  
> -
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  if defined(__PPC64__) || defined(__powerpc64__)
> -#   define LOAD  ld
> -#   define TPREG r13
> -#  else
> -#   define LOAD  lwz
> -#   define TPREG r2
> -#  endif
> -#  define PTR_MANGLE(reg, tmpreg) \
> -	LOAD	tmpreg,POINTER_GUARD(TPREG); \
> -	xor	reg,tmpreg,reg
> -#  define PTR_MANGLE2(reg, tmpreg) \
> -	xor	reg,tmpreg,reg
> -#  define PTR_MANGLE3(destreg, reg, tmpreg) \
> -	LOAD	tmpreg,POINTER_GUARD(TPREG); \
> -	xor	destreg,tmpreg,reg
> -#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> -#  define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
> -#  define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  /* List of system calls which are supported as vsyscalls.  */
>  #define VDSO_NAME  "LINUX_2.6.15"
>  #define VDSO_HASH  123718565
> diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> index 9b03b10567..c9af888132 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> @@ -357,8 +357,4 @@ extern long int __syscall_error (long int neg_errno);
>  
>  #endif /* ! __ASSEMBLER__ */
>  
> -/* Pointer mangling is not supported.  */
> -#define PTR_MANGLE(var) (void) (var)
> -#define PTR_DEMANGLE(var) (void) (var)
> -
>  #endif /* linux/riscv/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h b/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
> new file mode 100644
> index 0000000000..0e85d4ccbb
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h
> @@ -0,0 +1,45 @@
> +/* Pointer obfuscation implenentation.  s390 version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +/* For the time being just use stack_guard rather than a separate
> +   pointer_guard.  */
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg, tmpreg) \
> +  ear     tmpreg,%a0;                   \
> +  x       reg,STACK_GUARD(tmpreg)
> +#  define PTR_MANGLE2(reg, tmpreg) \
> +  x       reg,STACK_GUARD(tmpreg)
> +#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
> index e41106b377..a24fde7c6d 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
> @@ -177,25 +177,4 @@
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -/* For the time being just use stack_guard rather than a separate
> -   pointer_guard.  */
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg, tmpreg) \
> -  ear     tmpreg,%a0;			\
> -  x       reg,STACK_GUARD(tmpreg)
> -#  define PTR_MANGLE2(reg, tmpreg) \
> -  x       reg,STACK_GUARD(tmpreg)
> -#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* _LINUX_S390_SYSDEP_H */
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h b/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
> new file mode 100644
> index 0000000000..5285456806
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h
> @@ -0,0 +1,47 @@
> +/* Pointer obfuscation implenentation.  s390x version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +/* For the time being just use stack_guard rather than a separate
> +   pointer_guard.  */
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg, tmpreg) \
> +  ear     tmpreg,%a0;			\
> +  sllg    tmpreg,tmpreg,32;		\
> +  ear     tmpreg,%a1;			\
> +  xg      reg,STACK_GUARD(tmpreg)
> +#  define PTR_MANGLE2(reg, tmpreg) \
> +  xg      reg,STACK_GUARD(tmpreg)
> +#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
> index 150e33981a..79bc0fa4a6 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
> @@ -175,27 +175,4 @@
>  
>  #endif /* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -/* For the time being just use stack_guard rather than a separate
> -   pointer_guard.  */
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg, tmpreg) \
> -  ear     tmpreg,%a0;			\
> -  sllg    tmpreg,tmpreg,32;		\
> -  ear     tmpreg,%a1;			\
> -  xg      reg,STACK_GUARD(tmpreg)
> -#  define PTR_MANGLE2(reg, tmpreg) \
> -  xg      reg,STACK_GUARD(tmpreg)
> -#  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* _LINUX_S390_SYSDEP_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
> index e821e158c4..cf69926316 100644
> --- a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #include <sigaltstack-offsets.h>
>  

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sh/pointer_guard.h b/sysdeps/unix/sysv/linux/sh/pointer_guard.h
> new file mode 100644
> index 0000000000..32a571d496
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sh/pointer_guard.h
> @@ -0,0 +1,43 @@
> +/* Pointer obfuscation implenentation.  Generic (no-op) version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  Using a global variable
> +   is too complicated here since we have no PC-relative addressing mode.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg, tmp) \
> +     stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
> +#  define PTR_MANGLE2(reg, tmp) xor tmp,reg
> +#  define PTR_DEMANGLE(reg, tmp)        PTR_MANGLE (reg, tmp)
> +#  define PTR_DEMANGLE2(reg, tmp)       PTR_MANGLE2 (reg, tmp)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +     (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/sh/sysdep.h b/sysdeps/unix/sysv/linux/sh/sysdep.h
> index e9e13cd184..a2f43f68c3 100644
> --- a/sysdeps/unix/sysv/linux/sh/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/sh/sysdep.h
> @@ -315,23 +315,4 @@
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  Using a global variable
> -   is too complicated here since we have no PC-relative addressing mode.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg, tmp) \
> -     stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
> -#  define PTR_MANGLE2(reg, tmp)	xor tmp,reg
> -#  define PTR_DEMANGLE(reg, tmp)	PTR_MANGLE (reg, tmp)
> -#  define PTR_DEMANGLE2(reg, tmp)	PTR_MANGLE2 (reg, tmp)
> -# else
> -#  define PTR_MANGLE(var) \
> -     (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)	PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/sh/sysdep.h */
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
> index 8e8cb4d751..ad23840bcd 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  
>  #define ENV(base,reg) [%base + (reg * 4)]

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h b/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
> new file mode 100644
> index 0000000000..4063513cd8
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h
> @@ -0,0 +1,44 @@
> +/* Pointer obfuscation implenentation.  32-bit SPARC version.
> +   Copyright (C) 2006-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(dreg, reg, tmpreg) \
> +  ld    [%g7 + POINTER_GUARD], tmpreg; \
> +  xor   reg, tmpreg, dreg
> +#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
> +#  define PTR_MANGLE2(dreg, reg, tmpreg) \
> +  xor   reg, tmpreg, dreg
> +#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
> index 032608a4e0..1783af8178 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
> @@ -125,24 +125,4 @@ ENTRY(name);					\
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(dreg, reg, tmpreg) \
> -  ld	[%g7 + POINTER_GUARD], tmpreg; \
> -  xor	reg, tmpreg, dreg
> -#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
> -#  define PTR_MANGLE2(dreg, reg, tmpreg) \
> -  xor	reg, tmpreg, dreg
> -#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/sparc/sysdep.h */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h b/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
> new file mode 100644
> index 0000000000..7865e87c73
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h
> @@ -0,0 +1,44 @@
> +/* Pointer obfuscation implenentation.  64-bit SPARC version.
> +   Copyright (C) 2006-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# include <sysdeps/generic/pointer_guard.h>
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(dreg, reg, tmpreg) \
> +  ldx   [%g7 + POINTER_GUARD], tmpreg; \
> +  xor   reg, tmpreg, dreg
> +#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
> +#  define PTR_MANGLE2(dreg, reg, tmpreg) \
> +  xor   reg, tmpreg, dreg
> +#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
> +# else
> +#  include <stdint.h>
> +#  include <tls.h>
> +#  define PTR_MANGLE(var) \
> +  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> +#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
> index 4aaa2912ce..4ae22ae25b 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
> @@ -127,24 +127,4 @@ ENTRY(name);					\
>     register windows.  So if you poke stack memory directly you add this.  */
>  #define STACK_BIAS	2047
>  
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(dreg, reg, tmpreg) \
> -  ldx	[%g7 + POINTER_GUARD], tmpreg; \
> -  xor	reg, tmpreg, dreg
> -#  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
> -#  define PTR_MANGLE2(dreg, reg, tmpreg) \
> -  xor	reg, tmpreg, dreg
> -#  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
> -# else
> -#  define PTR_MANGLE(var) \
> -  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
> -#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
> -# endif
> -#endif
> -
>  #endif /* linux/sparc64/sysdep.h */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> index ffdf4624bf..5ff275c436 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <asm-syntax.h>
>  #include <stap-probe.h>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h b/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
> new file mode 100644
> index 0000000000..2df3912897
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/x86_64/pointer_guard.h
> @@ -0,0 +1,61 @@
> +/* Pointer obfuscation implenentation.  x86-64 version.
> +   Copyright (C) 2005-2022 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 POINTER_GUARD_H
> +#define POINTER_GUARD_H
> +
> +#include <x86-lp_size.h>
> +#include <tcb-offsets.h>
> +
> +#if IS_IN (rtld)
> +/* We cannot use the thread descriptor because in ld.so we use setjmp
> +   earlier than the descriptor is initialized.  */
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg)       xor __pointer_chk_guard_local(%rip), reg;    \
> +                                rol $2*LP_SIZE+1, reg
> +#  define PTR_DEMANGLE(reg)     ror $2*LP_SIZE+1, reg;                       \
> +                                xor __pointer_chk_guard_local(%rip), reg
> +# else
> +#  define PTR_MANGLE(reg)       asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
> +                                     "rol $2*" LP_SIZE "+1, %0"                   \
> +                                     : "=r" (reg) : "0" (reg))
> +#  define PTR_DEMANGLE(reg)     asm ("ror $2*" LP_SIZE "+1, %0\n"                 \
> +                                     "xor __pointer_chk_guard_local(%%rip), %0"   \
> +                                     : "=r" (reg) : "0" (reg))
> +# endif
> +#else
> +# ifdef __ASSEMBLER__
> +#  define PTR_MANGLE(reg)       xor %fs:POINTER_GUARD, reg;                   \
> +                                rol $2*LP_SIZE+1, reg
> +#  define PTR_DEMANGLE(reg)     ror $2*LP_SIZE+1, reg;                        \
> +                                xor %fs:POINTER_GUARD, reg
> +# else
> +#  define PTR_MANGLE(var)       asm ("xor %%fs:%c2, %0\n"                     \
> +                                     "rol $2*" LP_SIZE "+1, %0"               \
> +                                     : "=r" (var)                             \
> +                                     : "0" (var),                             \
> +                                       "i" (POINTER_GUARD))
> +#  define PTR_DEMANGLE(var)     asm ("ror $2*" LP_SIZE "+1, %0\n"             \
> +                                     "xor %%fs:%c2, %0"                       \
> +                                     : "=r" (var)                             \
> +                                     : "0" (var),                             \
> +                                       "i" (POINTER_GUARD))
> +# endif
> +#endif
> +
> +#endif /* POINTER_GUARD_H */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> index 740abefcfd..5e4d7827d7 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> @@ -381,46 +381,6 @@
>  
>  #endif	/* __ASSEMBLER__ */
>  
> -
> -/* Pointer mangling support.  */
> -#if IS_IN (rtld)
> -/* We cannot use the thread descriptor because in ld.so we use setjmp
> -   earlier than the descriptor is initialized.  */
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg)	xor __pointer_chk_guard_local(%rip), reg;    \
> -				rol $2*LP_SIZE+1, reg
> -#  define PTR_DEMANGLE(reg)	ror $2*LP_SIZE+1, reg;			     \
> -				xor __pointer_chk_guard_local(%rip), reg
> -# else
> -#  define PTR_MANGLE(reg)	asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
> -				     "rol $2*" LP_SIZE "+1, %0"			  \
> -				     : "=r" (reg) : "0" (reg))
> -#  define PTR_DEMANGLE(reg)	asm ("ror $2*" LP_SIZE "+1, %0\n"		  \
> -				     "xor __pointer_chk_guard_local(%%rip), %0"   \
> -				     : "=r" (reg) : "0" (reg))
> -# endif
> -#else
> -# ifdef __ASSEMBLER__
> -#  define PTR_MANGLE(reg)	xor %fs:POINTER_GUARD, reg;		      \
> -				rol $2*LP_SIZE+1, reg
> -#  define PTR_DEMANGLE(reg)	ror $2*LP_SIZE+1, reg;			      \
> -				xor %fs:POINTER_GUARD, reg
> -# else
> -#  define PTR_MANGLE(var)	asm ("xor %%fs:%c2, %0\n"		      \
> -				     "rol $2*" LP_SIZE "+1, %0"		      \
> -				     : "=r" (var)			      \
> -				     : "0" (var),			      \
> -				       "i" (offsetof (tcbhead_t,	      \
> -						      pointer_guard)))
> -#  define PTR_DEMANGLE(var)	asm ("ror $2*" LP_SIZE "+1, %0\n"	      \
> -				     "xor %%fs:%c2, %0"			      \
> -				     : "=r" (var)			      \
> -				     : "0" (var),			      \
> -				       "i" (offsetof (tcbhead_t,	      \
> -						      pointer_guard)))
> -# endif
> -#endif
> -
>  /* How to pass the off{64}_t argument on p{readv,writev}{64}.  */
>  #undef LO_HI_LONG
>  #define LO_HI_LONG(val) (val), 0

Ok.

> diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S
> index b51d79168c..6fdb4ccfbf 100644
> --- a/sysdeps/x86_64/__longjmp.S
> +++ b/sysdeps/x86_64/__longjmp.S
> @@ -16,6 +16,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/x86_64/jmpbuf-unwind.h b/sysdeps/x86_64/jmpbuf-unwind.h
> index 42ea37508e..c92b2633bc 100644
> --- a/sysdeps/x86_64/jmpbuf-unwind.h
> +++ b/sysdeps/x86_64/jmpbuf-unwind.h
> @@ -20,6 +20,7 @@
>  #include <stdint.h>
>  #include <unwind.h>
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  /* Test if longjmp to JMPBUF would unwind the frame
>     containing a local variable at ADDRESS.  */
> diff --git a/sysdeps/x86_64/setjmp.S b/sysdeps/x86_64/setjmp.S
> index 1b77dcd4f9..3897e66dc4 100644
> --- a/sysdeps/x86_64/setjmp.S
> +++ b/sysdeps/x86_64/setjmp.S
> @@ -17,6 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <sysdep.h>
> +#include <pointer_guard.h>
>  #include <jmpbuf-offsets.h>
>  #include <jmp_buf-ssp.h>
>  #include <asm-syntax.h>
> diff --git a/sysdeps/x86_64/x32/x86-lp_size.h b/sysdeps/x86_64/x32/x86-lp_size.h
> index ad03eb66b2..0b71e58be5 100644
> --- a/sysdeps/x86_64/x32/x86-lp_size.h
> +++ b/sysdeps/x86_64/x32/x86-lp_size.h
> @@ -1,4 +1,4 @@
> -/* Pointer size definition for x86-64 x42.
> +/* Pointer size definition for x86-64 x32.
>     Copyright (C) 2022 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
> diff --git a/wcsmbs/btowc.c b/wcsmbs/btowc.c
> index 21e52a67f4..7023ec99f1 100644
> --- a/wcsmbs/btowc.c
> +++ b/wcsmbs/btowc.c
> @@ -24,7 +24,7 @@
>  #include <wcsmbsload.h>
>  #include <limits.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  wint_t
> diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
> index b23d9b0160..f8b029b58a 100644
> --- a/wcsmbs/mbrtoc16.c
> +++ b/wcsmbs/mbrtoc16.c
> @@ -22,7 +22,7 @@
>  #include <uchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/mbrtoc8.c b/wcsmbs/mbrtoc8.c
> index dd80b5282d..e745a49e09 100644
> --- a/wcsmbs/mbrtoc8.c
> +++ b/wcsmbs/mbrtoc8.c
> @@ -23,8 +23,6 @@
>  #include <uchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> -
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
>  #endif
> diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
> index 78d9994f67..46a1cc38df 100644
> --- a/wcsmbs/mbrtowc.c
> +++ b/wcsmbs/mbrtowc.c
> @@ -22,7 +22,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/mbsnrtowcs.c b/wcsmbs/mbsnrtowcs.c
> index 5860822400..06a1f2d36f 100644
> --- a/wcsmbs/mbsnrtowcs.c
> +++ b/wcsmbs/mbsnrtowcs.c
> @@ -23,7 +23,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/mbsrtowcs_l.c b/wcsmbs/mbsrtowcs_l.c
> index 0ebc389fdb..526b88e1dd 100644
> --- a/wcsmbs/mbsrtowcs_l.c
> +++ b/wcsmbs/mbsrtowcs_l.c
> @@ -27,7 +27,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c
> index c0cce3792f..42690f2efd 100644
> --- a/wcsmbs/wcrtomb.c
> +++ b/wcsmbs/wcrtomb.c
> @@ -25,7 +25,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/wcsnrtombs.c b/wcsmbs/wcsnrtombs.c
> index 9707f6f4bc..6ba180cdc2 100644
> --- a/wcsmbs/wcsnrtombs.c
> +++ b/wcsmbs/wcsnrtombs.c
> @@ -22,7 +22,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c
> index b1ac704b28..7db2b181b3 100644
> --- a/wcsmbs/wcsrtombs.c
> +++ b/wcsmbs/wcsrtombs.c
> @@ -23,7 +23,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  #ifndef EILSEQ
>  # define EILSEQ EINVAL
> diff --git a/wcsmbs/wctob.c b/wcsmbs/wctob.c
> index 573c2c9448..5dfbd7ab7e 100644
> --- a/wcsmbs/wctob.c
> +++ b/wcsmbs/wctob.c
> @@ -22,7 +22,7 @@
>  #include <wchar.h>
>  #include <wcsmbsload.h>
>  
> -#include <sysdep.h>
> +#include <pointer_guard.h>
>  
>  
>  int

Ok.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources
  2022-10-13 12:20 ` [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources Florian Weimer
@ 2022-10-17 16:15   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-17 16:15 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 13/10/22 09:20, Florian Weimer via Libc-alpha wrote:
> In the future, this will result in a compilation failure if the
> macros are unexpectedly undefined (due to header inclusion ordering
> or header inclusion missing altogether).
> 
> Assembler sources are more difficult to convert.  In many cases,
> they are hand-optimized for the mangling and no-mangling variants,
> which is why they are not converted.
> 
> sysdeps/s390/s390-32/__longjmp.c and sysdeps/s390/s390-64/__longjmp.c
> are special: These are C sources, but most of the implementation is
> in assembler, so the PTR_DEMANGLE macro has to be undefined in some
> cases, to match the assembler style.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  hurd/sigunwind.c                      |  2 --
>  iconv/gconv.c                         |  2 --
>  iconv/gconv_cache.c                   |  5 -----
>  iconv/gconv_db.c                      | 15 ---------------
>  iconv/gconv_dl.c                      |  2 --
>  iconv/gconv_trans.c                   |  2 --
>  iconv/skeleton.c                      |  2 --
>  inet/idna.c                           |  6 ------
>  libio/iofopncook.c                    | 12 ------------
>  libio/iofwide.c                       |  6 ------
>  libio/libioP.h                        |  2 --
>  libio/vtables.c                       |  2 --
>  misc/unwind-link.c                    | 10 ++++------
>  nss/nss_module.c                      | 12 ------------
>  stdlib/cxa_atexit.c                   |  2 --
>  stdlib/cxa_finalize.c                 |  3 +--
>  stdlib/cxa_thread_atexit_impl.c       |  4 ----
>  stdlib/exit.c                         |  9 +++------
>  stdlib/on_exit.c                      |  2 --
>  sysdeps/aarch64/jmpbuf-offsets.h      |  2 --
>  sysdeps/alpha/jmpbuf-unwind.h         |  2 --
>  sysdeps/arc/jmpbuf-unwind.h           |  2 --
>  sysdeps/arm/jmpbuf-unwind.h           |  2 --
>  sysdeps/csky/jmpbuf-unwind.h          |  2 --
>  sysdeps/generic/unwind-link.h         |  6 +-----
>  sysdeps/i386/jmpbuf-unwind.h          |  2 --
>  sysdeps/i386/unwind-arch.h            |  6 +-----
>  sysdeps/loongarch/jmpbuf-unwind.h     |  2 --
>  sysdeps/m68k/jmpbuf-unwind.h          |  2 --
>  sysdeps/mach/hurd/jmp-unwind.c        |  2 --
>  sysdeps/microblaze/jmpbuf-unwind.h    |  2 --
>  sysdeps/mips/jmpbuf-unwind.h          |  2 --
>  sysdeps/nios2/jmpbuf-offsets.h        |  2 --
>  sysdeps/powerpc/jmpbuf-unwind.h       |  2 --
>  sysdeps/riscv/jmpbuf-unwind.h         |  2 --
>  sysdeps/s390/jmpbuf-unwind.h          |  2 --
>  sysdeps/s390/s390-32/__longjmp.c      |  5 +++++
>  sysdeps/s390/s390-64/__longjmp.c      |  5 +++++
>  sysdeps/sh/jmpbuf-unwind.h            |  2 --
>  sysdeps/sparc/sparc32/jmpbuf-unwind.h |  2 --
>  sysdeps/x86_64/jmpbuf-unwind.h        |  2 --
>  wcsmbs/btowc.c                        |  4 ----
>  wcsmbs/mbrtoc16.c                     |  2 --
>  wcsmbs/mbrtowc.c                      |  2 --
>  wcsmbs/mbsnrtowcs.c                   |  2 --
>  wcsmbs/mbsrtowcs_l.c                  |  2 --
>  wcsmbs/wcrtomb.c                      |  2 --
>  wcsmbs/wcsnrtombs.c                   |  2 --
>  wcsmbs/wcsrtombs.c                    |  2 --
>  wcsmbs/wctob.c                        |  2 --
>  50 files changed, 20 insertions(+), 158 deletions(-)
> 
> diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
> index 28213091e3..f114990b6f 100644
> --- a/hurd/sigunwind.c
> +++ b/hurd/sigunwind.c
> @@ -73,9 +73,7 @@ _hurdsig_longjmp_from_handler (void *data, jmp_buf env, int val)
>  
>        inline uintptr_t demangle_ptr (uintptr_t x)
>  	{
> -# ifdef PTR_DEMANGLE
>  	  PTR_DEMANGLE (x);
> -# endif
>  	  return x;
>  	}
>  
> diff --git a/iconv/gconv.c b/iconv/gconv.c
> index dea9c80fee..592a75956c 100644
> --- a/iconv/gconv.c
> +++ b/iconv/gconv.c
> @@ -46,10 +46,8 @@ __gconv (__gconv_t cd, const unsigned char **inbuf,
>    cd->__data[last_step].__outbufend = outbufend;
>  
>    __gconv_fct fct = cd->__steps->__fct;
> -#ifdef PTR_DEMANGLE
>    if (cd->__steps->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    if (inbuf == NULL || *inbuf == NULL)
>      {
> diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
> index 5dbf596b8d..8d47545c41 100644
> --- a/iconv/gconv_cache.c
> +++ b/iconv/gconv_cache.c
> @@ -205,16 +205,11 @@ find_module (const char *directory, const char *filename,
>  
>        /* Call the init function.  */
>        __gconv_init_fct init_fct = result->__init_fct;
> -#ifdef PTR_DEMANGLE
>        PTR_DEMANGLE (init_fct);
> -#endif
>        if (init_fct != NULL)
>  	{
>  	  status = DL_CALL_FCT (init_fct, (result));
> -
> -#ifdef PTR_MANGLE
>  	  PTR_MANGLE (result->__btowc_fct);
> -#endif
>  	}
>      }
>  
> diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
> index 90037fdf58..4943c954a3 100644
> --- a/iconv/gconv_db.c
> +++ b/iconv/gconv_db.c
> @@ -180,9 +180,7 @@ free_derivation (void *p)
>  	&& deriv->steps[cnt].__shlib_handle != NULL)
>        {
>  	__gconv_end_fct end_fct = deriv->steps[cnt].__end_fct;
> -#ifdef PTR_DEMANGLE
>  	PTR_DEMANGLE (end_fct);
> -#endif
>  	if (end_fct != NULL)
>  	  DL_CALL_FCT (end_fct, (&deriv->steps[cnt]));
>        }
> @@ -208,9 +206,7 @@ __gconv_release_step (struct __gconv_step *step)
>      {
>        /* Call the destructor.  */
>  	__gconv_end_fct end_fct = step->__end_fct;
> -#ifdef PTR_DEMANGLE
>  	PTR_DEMANGLE (end_fct);
> -#endif
>        if (end_fct != NULL)
>  	DL_CALL_FCT (end_fct, (step));
>  
> @@ -303,9 +299,7 @@ gen_steps (struct derivation_step *best, const char *toset,
>  
>  	      /* Call the init function.  */
>  	      __gconv_init_fct init_fct = result[step_cnt].__init_fct;
> -# ifdef PTR_DEMANGLE
>  	      PTR_DEMANGLE (init_fct);
> -# endif
>  	      if (init_fct != NULL)
>  		{
>  		  status = DL_CALL_FCT (init_fct, (&result[step_cnt]));
> @@ -316,17 +310,13 @@ gen_steps (struct derivation_step *best, const char *toset,
>  		      /* Do not call the end function because the init
>  			 function has failed.  */
>  		      result[step_cnt].__end_fct = NULL;
> -# ifdef PTR_MANGLE
>  		      PTR_MANGLE (result[step_cnt].__end_fct);
> -# endif
>  		      /* Make sure we unload this module.  */
>  		      --step_cnt;
>  		      break;
>  		    }
>  		}
> -# ifdef PTR_MANGLE
>  	      PTR_MANGLE (result[step_cnt].__btowc_fct);
> -# endif
>  	    }
>  	  else
>  #endif
> @@ -404,15 +394,10 @@ increment_counter (struct __gconv_step *steps, size_t nsteps)
>  
>  	      /* Call the init function.  */
>  	      __gconv_init_fct init_fct = step->__init_fct;
> -#ifdef PTR_DEMANGLE
>  	      PTR_DEMANGLE (init_fct);
> -#endif
>  	      if (init_fct != NULL)
>  		DL_CALL_FCT (init_fct, (step));
> -
> -#ifdef PTR_MANGLE
>  	      PTR_MANGLE (step->__btowc_fct);
> -#endif
>  	    }
>  	}
>      }
> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
> index c93c5dd380..5ed982636a 100644
> --- a/iconv/gconv_dl.c
> +++ b/iconv/gconv_dl.c
> @@ -127,11 +127,9 @@ __gconv_find_shlib (const char *name)
>  		  found->init_fct = __libc_dlsym (found->handle, "gconv_init");
>  		  found->end_fct = __libc_dlsym (found->handle, "gconv_end");
>  
> -#ifdef PTR_MANGLE
>  		  PTR_MANGLE (found->fct);
>  		  PTR_MANGLE (found->init_fct);
>  		  PTR_MANGLE (found->end_fct);
> -#endif
>  
>  		  /* We have succeeded in loading the shared object.  */
>  		  found->counter = 1;
> diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c
> index 0f4ce10996..2255531452 100644
> --- a/iconv/gconv_trans.c
> +++ b/iconv/gconv_trans.c
> @@ -53,10 +53,8 @@ __gconv_transliterate (struct __gconv_step *step,
>    winbufend = (const uint32_t *) inbufend;
>  
>    __gconv_fct fct = step->__fct;
> -#ifdef PTR_DEMANGLE
>    if (step->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* If there is no transliteration information in the locale don't do
>       anything and return the error.  */
> diff --git a/iconv/skeleton.c b/iconv/skeleton.c
> index 42ee0b6508..9eaf9a4948 100644
> --- a/iconv/skeleton.c
> +++ b/iconv/skeleton.c
> @@ -404,10 +404,8 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
>    if ((data->__flags & __GCONV_IS_LAST) == 0)
>      {
>        fct = next_step->__fct;
> -#ifdef PTR_DEMANGLE
>        if (next_step->__shlib_handle != NULL)
>  	PTR_DEMANGLE (fct);
> -#endif
>      }
>  
>    /* If the function is called with no input this means we have to reset
> diff --git a/inet/idna.c b/inet/idna.c
> index df5811fd6a..2243d3e7d9 100644
> --- a/inet/idna.c
> +++ b/inet/idna.c
> @@ -73,10 +73,8 @@ functions_allocate (void *closure)
>    result->handle = handle;
>    result->lookup_ul = ptr_lookup_ul;
>    result->to_unicode_lzlz = ptr_to_unicode_lzlz;
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (result->lookup_ul);
>    PTR_MANGLE (result->to_unicode_lzlz);
> -#endif
>  
>    return result;
>  }
> @@ -138,9 +136,7 @@ __idna_to_dns_encoding (const char *name, char **result)
>      return EAI_IDN_ENCODE;
>    char *ptr = NULL;
>    __typeof__ (functions->lookup_ul) fptr = functions->lookup_ul;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (fptr);
> -#endif
>    int ret = fptr (name, &ptr, 0);
>    if (ret == 0)
>      {
> @@ -165,9 +161,7 @@ __idna_from_dns_encoding (const char *name, char **result)
>      return gai_strdup (name, result);
>    char *ptr = NULL;
>    __typeof__ (functions->to_unicode_lzlz) fptr = functions->to_unicode_lzlz;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (fptr);
> -#endif
>    int ret = fptr (name, &ptr, 0);
>    if (ret == 0)
>      {
> diff --git a/libio/iofopncook.c b/libio/iofopncook.c
> index a7db4ef1c9..6c27610319 100644
> --- a/libio/iofopncook.c
> +++ b/libio/iofopncook.c
> @@ -35,9 +35,7 @@ _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
>  {
>    struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
>    cookie_read_function_t *read_cb = cfile->__io_functions.read;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (read_cb);
> -#endif
>  
>    if (read_cb == NULL)
>      return -1;
> @@ -50,9 +48,7 @@ _IO_cookie_write (FILE *fp, const void *buf, ssize_t size)
>  {
>    struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
>    cookie_write_function_t *write_cb = cfile->__io_functions.write;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (write_cb);
> -#endif
>  
>    if (write_cb == NULL)
>      {
> @@ -72,9 +68,7 @@ _IO_cookie_seek (FILE *fp, off64_t offset, int dir)
>  {
>    struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
>    cookie_seek_function_t *seek_cb = cfile->__io_functions.seek;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (seek_cb);
> -#endif
>  
>    return ((seek_cb == NULL
>  	   || (seek_cb (cfile->__cookie, &offset, dir)
> @@ -88,9 +82,7 @@ _IO_cookie_close (FILE *fp)
>  {
>    struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
>    cookie_close_function_t *close_cb = cfile->__io_functions.close;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (close_cb);
> -#endif
>  
>    if (close_cb == NULL)
>      return 0;
> @@ -139,12 +131,10 @@ static void
>  set_callbacks (cookie_io_functions_t *target,
>  	       cookie_io_functions_t source)
>  {
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (source.read);
>    PTR_MANGLE (source.write);
>    PTR_MANGLE (source.seek);
>    PTR_MANGLE (source.close);
> -#endif
>    *target = source;
>  }
>  
> @@ -226,9 +216,7 @@ _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir)
>    struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
>    int (*seek_cb) (FILE *, off_t, int)
>      = (int (*) (FILE *, off_t, int)) cfile->__io_functions.seek;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (seek_cb);
> -#endif
>  
>    if (seek_cb == NULL)
>      return _IO_pos_BAD;
> diff --git a/libio/iofwide.c b/libio/iofwide.c
> index 1ce685f48a..37c353e3aa 100644
> --- a/libio/iofwide.c
> +++ b/libio/iofwide.c
> @@ -124,10 +124,8 @@ __libio_codecvt_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
>    codecvt->__cd_out.step_data.__statep = statep;
>  
>    __gconv_fct fct = gs->__fct;
> -#ifdef PTR_DEMANGLE
>    if (gs->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    status = DL_CALL_FCT (fct,
>  			(gs, &codecvt->__cd_out.step_data, &from_start_copy,
> @@ -176,10 +174,8 @@ __libio_codecvt_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
>    codecvt->__cd_in.step_data.__statep = statep;
>  
>    __gconv_fct fct = gs->__fct;
> -#ifdef PTR_DEMANGLE
>    if (gs->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    status = DL_CALL_FCT (fct,
>  			(gs, &codecvt->__cd_in.step_data, &from_start_copy,
> @@ -243,10 +239,8 @@ __libio_codecvt_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
>    codecvt->__cd_in.step_data.__statep = statep;
>  
>    __gconv_fct fct = gs->__fct;
> -#ifdef PTR_DEMANGLE
>    if (gs->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    DL_CALL_FCT (fct,
>  	       (gs, &codecvt->__cd_in.step_data, &cp,
> diff --git a/libio/libioP.h b/libio/libioP.h
> index dac3de73a1..3a5498bd65 100644
> --- a/libio/libioP.h
> +++ b/libio/libioP.h
> @@ -911,9 +911,7 @@ extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
>  static inline void
>  IO_set_accept_foreign_vtables (void (*flag) (void))
>  {
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (flag);
> -#endif
>    atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
>  }
>  
> diff --git a/libio/vtables.c b/libio/vtables.c
> index 32459e4fac..e3809c28ce 100644
> --- a/libio/vtables.c
> +++ b/libio/vtables.c
> @@ -39,9 +39,7 @@ _IO_vtable_check (void)
>  #ifdef SHARED
>    /* Honor the compatibility flag.  */
>    void (*flag) (void) = atomic_load_relaxed (&IO_accept_foreign_vtables);
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (flag);
> -#endif
>    if (flag == &_IO_vtable_check)
>      return;
>  
> diff --git a/misc/unwind-link.c b/misc/unwind-link.c
> index 45b7886b46..e8653bbaf1 100644
> --- a/misc/unwind-link.c
> +++ b/misc/unwind-link.c
> @@ -86,19 +86,17 @@ __libc_unwind_link_get (void)
>    assert (local.ptr__Unwind_Resume != NULL);
>    assert (local.ptr_personality != NULL);
>  
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (local.ptr__Unwind_Backtrace);
>    PTR_MANGLE (local.ptr__Unwind_ForcedUnwind);
>    PTR_MANGLE (local.ptr__Unwind_GetCFA);
> -# if UNWIND_LINK_GETIP
> +#if UNWIND_LINK_GETIP
>    PTR_MANGLE (local.ptr__Unwind_GetIP);
> -# endif
> +#endif
>    PTR_MANGLE (local.ptr__Unwind_Resume);
> -# if UNWIND_LINK_FRAME_STATE_FOR
> +#if UNWIND_LINK_FRAME_STATE_FOR
>    PTR_MANGLE (local.ptr___frame_state_for);
> -# endif
> -  PTR_MANGLE (local.ptr_personality);
>  #endif
> +  PTR_MANGLE (local.ptr_personality);
>  
>    __libc_lock_lock (lock);
>    if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
> diff --git a/nss/nss_module.c b/nss/nss_module.c
> index 9a8f3ddf94..444facb9b8 100644
> --- a/nss/nss_module.c
> +++ b/nss/nss_module.c
> @@ -128,10 +128,8 @@ module_load_builtin (struct nss_module *module,
>      case nss_module_failed:
>        bind (module->functions.untyped);
>  
> -#ifdef PTR_MANGLE
>        for (int i = 0; i < nss_module_functions_count; ++i)
>  	PTR_MANGLE (module->functions.untyped[i]);
> -#endif
>  
>        module->handle = NULL;
>        /* Synchronizes with unlocked __nss_module_load atomic_load_acquire.  */
> @@ -153,9 +151,7 @@ module_load_nss_files (struct nss_module *module)
>    if (is_nscd)
>      {
>        void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
> -# ifdef PTR_DEMANGLE
>        PTR_DEMANGLE (cb);
> -# endif
>        _nss_files_init (cb);
>      }
>  #endif
> @@ -239,9 +235,7 @@ module_load (struct nss_module *module)
>          }
>        pointers[idx] = __libc_dlsym (handle, function_name);
>        free (function_name);
> -#ifdef PTR_MANGLE
>        PTR_MANGLE (pointers[idx]);
> -#endif
>      }
>  
>  # ifdef USE_NSCD
> @@ -264,9 +258,7 @@ module_load (struct nss_module *module)
>        if (ifct != NULL)
>  	{
>  	  void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
> -#  ifdef PTR_DEMANGLE
>  	  PTR_DEMANGLE (cb);
> -#  endif
>  	  ifct (cb);
>  	}
>      }
> @@ -349,9 +341,7 @@ __nss_module_get_function (struct nss_module *module, const char *name)
>    assert (name_entry != NULL);
>    size_t idx = name_entry - nss_function_name_array;
>    void *fptr = module->functions.untyped[idx];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (fptr);
> -#endif
>    return fptr;
>  }
>  
> @@ -382,9 +372,7 @@ __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
>  {
>    void (*cb1) (size_t, struct traced_file *);
>    cb1 = cb;
> -# ifdef PTR_MANGLE
>    PTR_MANGLE (cb);
> -# endif
>    nscd_init_cb = cb;
>    is_nscd = true;
>  
> diff --git a/stdlib/cxa_atexit.c b/stdlib/cxa_atexit.c
> index adf89e93f5..fad2d2b4e0 100644
> --- a/stdlib/cxa_atexit.c
> +++ b/stdlib/cxa_atexit.c
> @@ -49,9 +49,7 @@ __internal_atexit (void (*func) (void *), void *arg, void *d,
>        return -1;
>      }
>  
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (func);
> -#endif
>    new->func.cxa.fn = (void (*) (void *, int)) func;
>    new->func.cxa.arg = arg;
>    new->func.cxa.dso_handle = d;
> diff --git a/stdlib/cxa_finalize.c b/stdlib/cxa_finalize.c
> index f2479569a5..1958c28801 100644
> --- a/stdlib/cxa_finalize.c
> +++ b/stdlib/cxa_finalize.c
> @@ -75,9 +75,8 @@ __cxa_finalize (void *d)
>  	       parallel.  */
>  	    f->flavor = ef_free;
>  
> -#ifdef PTR_DEMANGLE
>  	    PTR_DEMANGLE (cxafn);
> -#endif
> +
>  	    /* Unlock the list while we call a foreign function.  */
>  	    __libc_lock_unlock (__exit_funcs_lock);
>  	    cxafn (cxaarg, 0);
> diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c
> index faacab3990..b5ecfee10c 100644
> --- a/stdlib/cxa_thread_atexit_impl.c
> +++ b/stdlib/cxa_thread_atexit_impl.c
> @@ -100,9 +100,7 @@ static __thread struct link_map *lm_cache;
>  int
>  __cxa_thread_atexit_impl (dtor_func func, void *obj, void *dso_symbol)
>  {
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (func);
> -#endif
>  
>    /* Prepend.  */
>    struct dtor_list *new = calloc (1, sizeof (struct dtor_list));
> @@ -152,9 +150,7 @@ __call_tls_dtors (void)
>      {
>        struct dtor_list *cur = tls_dtor_list;
>        dtor_func func = cur->func;
> -#ifdef PTR_DEMANGLE
>        PTR_DEMANGLE (func);
> -#endif
>  
>        tls_dtor_list = tls_dtor_list->next;
>        func (cur->obj);
> diff --git a/stdlib/exit.c b/stdlib/exit.c
> index e59156bbf6..10c44e1449 100644
> --- a/stdlib/exit.c
> +++ b/stdlib/exit.c
> @@ -81,9 +81,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
>  	    case ef_on:
>  	      onfct = f->func.on.fn;
>  	      arg = f->func.on.arg;
> -#ifdef PTR_DEMANGLE
>  	      PTR_DEMANGLE (onfct);
> -#endif
> +
>  	      /* Unlock the list while we call a foreign function.  */
>  	      __libc_lock_unlock (__exit_funcs_lock);
>  	      onfct (status, arg);
> @@ -91,9 +90,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
>  	      break;
>  	    case ef_at:
>  	      atfct = f->func.at;
> -#ifdef PTR_DEMANGLE
>  	      PTR_DEMANGLE (atfct);
> -#endif
> +
>  	      /* Unlock the list while we call a foreign function.  */
>  	      __libc_lock_unlock (__exit_funcs_lock);
>  	      atfct ();
> @@ -105,9 +103,8 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
>  	      f->flavor = ef_free;
>  	      cxafct = f->func.cxa.fn;
>  	      arg = f->func.cxa.arg;
> -#ifdef PTR_DEMANGLE
>  	      PTR_DEMANGLE (cxafct);
> -#endif
> +
>  	      /* Unlock the list while we call a foreign function.  */
>  	      __libc_lock_unlock (__exit_funcs_lock);
>  	      cxafct (arg, status);
> diff --git a/stdlib/on_exit.c b/stdlib/on_exit.c
> index fb59db20ca..2ac70e18bd 100644
> --- a/stdlib/on_exit.c
> +++ b/stdlib/on_exit.c
> @@ -39,9 +39,7 @@ __on_exit (void (*func) (int status, void *arg), void *arg)
>        return -1;
>      }
>  
> -#ifdef PTR_MANGLE
>    PTR_MANGLE (func);
> -#endif
>    new->func.on.fn = func;
>    new->func.on.arg = arg;
>    new->flavor = ef_on;
> diff --git a/sysdeps/aarch64/jmpbuf-offsets.h b/sysdeps/aarch64/jmpbuf-offsets.h
> index 78bdd4a539..841da965a6 100644
> --- a/sysdeps/aarch64/jmpbuf-offsets.h
> +++ b/sysdeps/aarch64/jmpbuf-offsets.h
> @@ -49,9 +49,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf jmpbuf)
>  {
>    uintptr_t sp = jmpbuf[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  #endif
> diff --git a/sysdeps/alpha/jmpbuf-unwind.h b/sysdeps/alpha/jmpbuf-unwind.h
> index 318b73b100..05a0dc9cba 100644
> --- a/sysdeps/alpha/jmpbuf-unwind.h
> +++ b/sysdeps/alpha/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/arc/jmpbuf-unwind.h b/sysdeps/arc/jmpbuf-unwind.h
> index e5434a95dd..2eadc5d22f 100644
> --- a/sysdeps/arc/jmpbuf-unwind.h
> +++ b/sysdeps/arc/jmpbuf-unwind.h
> @@ -35,9 +35,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf jmpbuf)
>  {
>    uintptr_t sp = jmpbuf[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/arm/jmpbuf-unwind.h b/sysdeps/arm/jmpbuf-unwind.h
> index 641444eaf3..be99b4f9be 100644
> --- a/sysdeps/arm/jmpbuf-unwind.h
> +++ b/sysdeps/arm/jmpbuf-unwind.h
> @@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[__JMP_BUF_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/csky/jmpbuf-unwind.h b/sysdeps/csky/jmpbuf-unwind.h
> index 76fca431c6..61e9c45875 100644
> --- a/sysdeps/csky/jmpbuf-unwind.h
> +++ b/sysdeps/csky/jmpbuf-unwind.h
> @@ -36,9 +36,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = (uintptr_t) regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/generic/unwind-link.h b/sysdeps/generic/unwind-link.h
> index a2076a23bf..ea031a04d0 100644
> --- a/sysdeps/generic/unwind-link.h
> +++ b/sysdeps/generic/unwind-link.h
> @@ -61,16 +61,12 @@ libc_hidden_proto (__libc_unwind_link_get)
>  /* UNWIND_LINK_PTR returns the stored function pointer NAME from the
>     cached unwind link OBJ (which was previously returned by
>     __libc_unwind_link_get).  */
> -# ifdef PTR_DEMANGLE
> -#  define UNWIND_LINK_PTR(obj, name, ...)                          \
> +# define UNWIND_LINK_PTR(obj, name, ...)                             \
>    ({                                                                \
>      __typeof ((obj)->ptr_##name) __unwind_fptr = (obj)->ptr_##name; \
>      PTR_DEMANGLE (__unwind_fptr);                                   \
>      __unwind_fptr;                                                  \
>    })
> -# else /* !PTR_DEMANGLE */
> -#  define UNWIND_LINK_PTR(obj, name, ...) ((obj)->ptr_##name)
> -# endif
>  
>  /* Called from fork, in the new subprocess.  */
>  void __libc_unwind_link_after_fork (void);
> diff --git a/sysdeps/i386/jmpbuf-unwind.h b/sysdeps/i386/jmpbuf-unwind.h
> index 73d214fd31..25b54f8bb0 100644
> --- a/sysdeps/i386/jmpbuf-unwind.h
> +++ b/sysdeps/i386/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/i386/unwind-arch.h b/sysdeps/i386/unwind-arch.h
> index ae23469d3f..bb2e878dd0 100644
> --- a/sysdeps/i386/unwind-arch.h
> +++ b/sysdeps/i386/unwind-arch.h
> @@ -28,12 +28,8 @@
>    local.ptr__Unwind_GetGR                                   \
>      = __libc_dlsym (local_libgcc_handle, "_Unwind_GetGR");  \
>    assert (local.ptr__Unwind_GetGR != NULL);
> -#ifdef PTR_MANGLE
> -# define UNWIND_LINK_EXTRA_INIT                 \
> +#define UNWIND_LINK_EXTRA_INIT                  \
>    UNWIND_LINK_EXTRA_INIT_SHARED                 \
>    PTR_MANGLE (local.ptr__Unwind_GetGR);
> -#else
> -# define UNWIND_LINK_EXTRA_INIT UNWIND_LINK_EXTRA_INIT_SHARED
> -#endif
>  
>  #endif /* _ARCH_UNWIND_LINK_H */
> diff --git a/sysdeps/loongarch/jmpbuf-unwind.h b/sysdeps/loongarch/jmpbuf-unwind.h
> index 458edec135..bd58dd7cc5 100644
> --- a/sysdeps/loongarch/jmpbuf-unwind.h
> +++ b/sysdeps/loongarch/jmpbuf-unwind.h
> @@ -33,9 +33,7 @@
>  static inline uintptr_t __attribute__ ((unused)) _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/m68k/jmpbuf-unwind.h b/sysdeps/m68k/jmpbuf-unwind.h
> index 3ee46c050c..baf6f79b88 100644
> --- a/sysdeps/m68k/jmpbuf-unwind.h
> +++ b/sysdeps/m68k/jmpbuf-unwind.h
> @@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = (uintptr_t) regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/mach/hurd/jmp-unwind.c b/sysdeps/mach/hurd/jmp-unwind.c
> index 2577fbf3ee..1ac2815aac 100644
> --- a/sysdeps/mach/hurd/jmp-unwind.c
> +++ b/sysdeps/mach/hurd/jmp-unwind.c
> @@ -31,9 +31,7 @@
>  static inline uintptr_t
>  demangle_ptr (uintptr_t x)
>  {
> -# ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (x);
> -# endif
>    return x;
>  }
>  
> diff --git a/sysdeps/microblaze/jmpbuf-unwind.h b/sysdeps/microblaze/jmpbuf-unwind.h
> index 302e950ced..79fc493971 100644
> --- a/sysdeps/microblaze/jmpbuf-unwind.h
> +++ b/sysdeps/microblaze/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    void *sp = (void *) regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return (uintptr_t) sp;
>  }
>  
> diff --git a/sysdeps/mips/jmpbuf-unwind.h b/sysdeps/mips/jmpbuf-unwind.h
> index 28ecffedb0..827000a729 100644
> --- a/sysdeps/mips/jmpbuf-unwind.h
> +++ b/sysdeps/mips/jmpbuf-unwind.h
> @@ -35,9 +35,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = (uintptr_t) regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/nios2/jmpbuf-offsets.h b/sysdeps/nios2/jmpbuf-offsets.h
> index 76fea64ffe..50f938c8cf 100644
> --- a/sysdeps/nios2/jmpbuf-offsets.h
> +++ b/sysdeps/nios2/jmpbuf-offsets.h
> @@ -38,9 +38,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf jmpbuf)
>  {
>    uintptr_t sp = jmpbuf[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  #endif
> diff --git a/sysdeps/powerpc/jmpbuf-unwind.h b/sysdeps/powerpc/jmpbuf-unwind.h
> index 93573ce238..82499594a3 100644
> --- a/sysdeps/powerpc/jmpbuf-unwind.h
> +++ b/sysdeps/powerpc/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[JB_GPR1];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/riscv/jmpbuf-unwind.h b/sysdeps/riscv/jmpbuf-unwind.h
> index b411a246d1..0aeb0a76c6 100644
> --- a/sysdeps/riscv/jmpbuf-unwind.h
> +++ b/sysdeps/riscv/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[0].__sp;
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/s390/jmpbuf-unwind.h b/sysdeps/s390/jmpbuf-unwind.h
> index 10b37f09c3..d125f3100a 100644
> --- a/sysdeps/s390/jmpbuf-unwind.h
> +++ b/sysdeps/s390/jmpbuf-unwind.h
> @@ -41,9 +41,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    void *sp = (void *) (uintptr_t) regs[0].__gregs[__JB_GPR15];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return (uintptr_t) sp;
>  }
>  
> diff --git a/sysdeps/s390/s390-32/__longjmp.c b/sysdeps/s390/s390-32/__longjmp.c
> index 83d42329a3..f0317f6a03 100644
> --- a/sysdeps/s390/s390-32/__longjmp.c
> +++ b/sysdeps/s390/s390-32/__longjmp.c
> @@ -24,6 +24,11 @@
>  #include <unistd.h>
>  #include <stap-probe.h>
>  
> +/* See sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h.  */
> +#if IS_IN (rtld)
> +# undef PTR_DEMANGLE
> +#endif
> +
>  /* Jump to the position specified by ENV, causing the
>     setjmp call there to return VAL, or 1 if VAL is 0.  */
>  void
> diff --git a/sysdeps/s390/s390-64/__longjmp.c b/sysdeps/s390/s390-64/__longjmp.c
> index 9fe4939e5e..eabe245d95 100644
> --- a/sysdeps/s390/s390-64/__longjmp.c
> +++ b/sysdeps/s390/s390-64/__longjmp.c
> @@ -24,6 +24,11 @@
>  #include <unistd.h>
>  #include <stap-probe.h>
>  
> +/* See sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h.  */
> +#if IS_IN (rtld)
> +# undef PTR_DEMANGLE
> +#endif
> +
>  /* Jump to the position specified by ENV, causing the
>     setjmp call there to return VAL, or 1 if VAL is 0.  */
>  void
> diff --git a/sysdeps/sh/jmpbuf-unwind.h b/sysdeps/sh/jmpbuf-unwind.h
> index 1957e5275d..2c8b8b3696 100644
> --- a/sysdeps/sh/jmpbuf-unwind.h
> +++ b/sysdeps/sh/jmpbuf-unwind.h
> @@ -33,9 +33,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    void *sp = (void *) regs[0].__regs[7];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return (uintptr_t) sp;
>  }
>  
> diff --git a/sysdeps/sparc/sparc32/jmpbuf-unwind.h b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> index 8b697ed95b..a225a33dc5 100644
> --- a/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> +++ b/sysdeps/sparc/sparc32/jmpbuf-unwind.h
> @@ -34,9 +34,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[JB_SP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/sysdeps/x86_64/jmpbuf-unwind.h b/sysdeps/x86_64/jmpbuf-unwind.h
> index c92b2633bc..6fc5097e11 100644
> --- a/sysdeps/x86_64/jmpbuf-unwind.h
> +++ b/sysdeps/x86_64/jmpbuf-unwind.h
> @@ -36,9 +36,7 @@ static inline uintptr_t __attribute__ ((unused))
>  _jmpbuf_sp (__jmp_buf regs)
>  {
>    uintptr_t sp = regs[JB_RSP];
> -#ifdef PTR_DEMANGLE
>    PTR_DEMANGLE (sp);
> -#endif
>    return sp;
>  }
>  
> diff --git a/wcsmbs/btowc.c b/wcsmbs/btowc.c
> index 7023ec99f1..da1c28732f 100644
> --- a/wcsmbs/btowc.c
> +++ b/wcsmbs/btowc.c
> @@ -45,10 +45,8 @@ __btowc (int c)
>    /* Get the conversion functions.  */
>    fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
>    __gconv_btowc_fct btowc_fct = fcts->towc->__btowc_fct;
> -#ifdef PTR_DEMANGLE
>    if (fcts->towc->__shlib_handle != NULL)
>      PTR_DEMANGLE (btowc_fct);
> -#endif
>  
>    if (__builtin_expect (fcts->towc_nsteps == 1, 1)
>        && __builtin_expect (btowc_fct != NULL, 1))
> @@ -81,10 +79,8 @@ __btowc (int c)
>        inbuf[0] = c;
>  
>        __gconv_fct fct = fcts->towc->__fct;
> -#ifdef PTR_DEMANGLE
>        if (fcts->towc->__shlib_handle != NULL)
>  	PTR_DEMANGLE (fct);
> -#endif
>        status = DL_CALL_FCT (fct, (fcts->towc, &data, &inptr, inptr + 1,
>  				  NULL, &dummy, 0, 1));
>  
> diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
> index f8b029b58a..f45f73e246 100644
> --- a/wcsmbs/mbrtoc16.c
> +++ b/wcsmbs/mbrtoc16.c
> @@ -96,10 +96,8 @@ mbrtoc16 (char16_t *pc16, const char *s, size_t n, mbstate_t *ps)
>  	goto ilseq;
>      }
>    __gconv_fct fct = fcts->towc->__fct;
> -#ifdef PTR_DEMANGLE
>    if (fcts->towc->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf,
>  			      NULL, &dummy, 0, 1));
> diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
> index 46a1cc38df..3d06acbd5a 100644
> --- a/wcsmbs/mbrtowc.c
> +++ b/wcsmbs/mbrtowc.c
> @@ -78,10 +78,8 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
>  	goto ilseq;
>      }
>    __gconv_fct fct = fcts->towc->__fct;
> -#ifdef PTR_DEMANGLE
>    if (fcts->towc->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>    status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf,
>  			      NULL, &dummy, 0, 1));
>  
> diff --git a/wcsmbs/mbsnrtowcs.c b/wcsmbs/mbsnrtowcs.c
> index 06a1f2d36f..47f5de408a 100644
> --- a/wcsmbs/mbsnrtowcs.c
> +++ b/wcsmbs/mbsnrtowcs.c
> @@ -64,10 +64,8 @@ __mbsnrtowcs (wchar_t *dst, const char **src, size_t nmc, size_t len,
>    /* Get the structure with the function pointers.  */
>    towc = fcts->towc;
>    __gconv_fct fct = towc->__fct;
> -#ifdef PTR_DEMANGLE
>    if (towc->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* We have to handle DST == NULL special.  */
>    if (dst == NULL)
> diff --git a/wcsmbs/mbsrtowcs_l.c b/wcsmbs/mbsrtowcs_l.c
> index 526b88e1dd..5fe70cb8a1 100644
> --- a/wcsmbs/mbsrtowcs_l.c
> +++ b/wcsmbs/mbsrtowcs_l.c
> @@ -58,10 +58,8 @@ __mbsrtowcs_l (wchar_t *dst, const char **src, size_t len, mbstate_t *ps,
>    /* Get the structure with the function pointers.  */
>    towc = fcts->towc;
>    __gconv_fct fct = towc->__fct;
> -#ifdef PTR_DEMANGLE
>    if (towc->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* We have to handle DST == NULL special.  */
>    if (dst == NULL)
> diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c
> index 42690f2efd..b71ca79de7 100644
> --- a/wcsmbs/wcrtomb.c
> +++ b/wcsmbs/wcrtomb.c
> @@ -63,10 +63,8 @@ __wcrtomb_internal (char *s, wchar_t wc, mbstate_t *ps, size_t s_size)
>    /* Get the conversion functions.  */
>    fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
>    __gconv_fct fct = fcts->tomb->__fct;
> -#ifdef PTR_DEMANGLE
>    if (fcts->tomb->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* If WC is the NUL character we write into the output buffer the byte
>       sequence necessary for PS to get into the initial state, followed
> diff --git a/wcsmbs/wcsnrtombs.c b/wcsmbs/wcsnrtombs.c
> index 6ba180cdc2..12b116a837 100644
> --- a/wcsmbs/wcsnrtombs.c
> +++ b/wcsmbs/wcsnrtombs.c
> @@ -62,10 +62,8 @@ __wcsnrtombs (char *dst, const wchar_t **src, size_t nwc, size_t len,
>    /* Get the structure with the function pointers.  */
>    tomb = fcts->tomb;
>    __gconv_fct fct = tomb->__fct;
> -#ifdef PTR_DEMANGLE
>    if (tomb->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* We have to handle DST == NULL special.  */
>    if (dst == NULL)
> diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c
> index 7db2b181b3..962176c183 100644
> --- a/wcsmbs/wcsrtombs.c
> +++ b/wcsmbs/wcsrtombs.c
> @@ -54,10 +54,8 @@ __wcsrtombs (char *dst, const wchar_t **src, size_t len, mbstate_t *ps)
>    /* Get the structure with the function pointers.  */
>    tomb = fcts->tomb;
>    __gconv_fct fct = tomb->__fct;
> -#ifdef PTR_DEMANGLE
>    if (tomb->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>  
>    /* We have to handle DST == NULL special.  */
>    if (dst == NULL)
> diff --git a/wcsmbs/wctob.c b/wcsmbs/wctob.c
> index 5dfbd7ab7e..63764d1425 100644
> --- a/wcsmbs/wctob.c
> +++ b/wcsmbs/wctob.c
> @@ -63,10 +63,8 @@ wctob (wint_t c)
>  
>    const unsigned char *argptr = (const unsigned char *) inptr;
>    __gconv_fct fct = fcts->tomb->__fct;
> -#ifdef PTR_DEMANGLE
>    if (fcts->tomb->__shlib_handle != NULL)
>      PTR_DEMANGLE (fct);
> -#endif
>    status = DL_CALL_FCT (fct,
>  			(fcts->tomb, &data, &argptr,
>  			 argptr + sizeof (inbuf[0]), NULL, &dummy, 0, 1));

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h>
  2022-10-17 16:13   ` Adhemerval Zanella Netto
@ 2022-10-18 15:03     ` Florian Weimer
  0 siblings, 0 replies; 10+ messages in thread
From: Florian Weimer @ 2022-10-18 15:03 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha, DJ Delorie

* Adhemerval Zanella Netto:

> On 13/10/22 09:20, Florian Weimer via Libc-alpha wrote:
>> This allows us to define a generic no-op version of PTR_MANGLE and
>> PTR_DEMANGLE.  In the future, we can use PTR_MANGLE and PTR_DEMANGLE
>> unconditionally in C sources, avoiding an unintended loss of hardening
>> due to missing include files or unlucky header inclusion ordering.
>
> Could we also improve the generic implementation to always XOR with the
> pointer guard and move it to be a proper static inline function?  I think
> we can then remove a lot of boilerplate code each architecture need to
> have.

I think the assembler implementation in part aims to avoid leaving the
plain guard value behind in a register, at least on some targets.

>> In i386 and x86_64, we can avoid a <tls.h> dependency in the C
>> code by using the computed constant from <tcb-offsets.h>.  <sysdep.h>
>> no longer includes these definitions, so there is no cyclic dependency
>> anymore when computing the <tcb-offsets.h> constants.
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

Thanks,
Florian


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-18 15:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 12:20 [PATCH 0/3] PTR_MANGLE/PTR_DEMANGLE refactoring Florian Weimer
2022-10-13 12:20 ` [PATCH 1/3] x86-64: Move LP_SIZE definition to its own header Florian Weimer
2022-10-17 16:03   ` Adhemerval Zanella Netto
2022-10-13 12:20 ` [PATCH 2/3] Introduce <pointer_guard.h>, extracted from <sysdep.h> Florian Weimer
2022-10-14  3:30   ` DJ Delorie
2022-10-14  8:14     ` Florian Weimer
2022-10-17 16:13   ` Adhemerval Zanella Netto
2022-10-18 15:03     ` Florian Weimer
2022-10-13 12:20 ` [PATCH 3/3] Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources Florian Weimer
2022-10-17 16:15   ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).