]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Introduce <pointer_guard.h>, extracted from <sysdep.h>
authorFlorian Weimer <fweimer@redhat.com>
Tue, 18 Oct 2022 15:00:07 +0000 (17:00 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 18 Oct 2022 15:03:55 +0000 (17:03 +0200)
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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
131 files changed:
hurd/sigunwind.c
iconv/gconv.c
iconv/gconv_cache.c
iconv/gconv_db.c
iconv/gconv_dl.c
iconv/gconv_trans.c
iconv/skeleton.c
inet/idna.c
libio/iofopncook.c
libio/iofwide.c
libio/libioP.h
libio/vtables.c
misc/unwind-link.c
nss/nss_module.c
stdlib/cxa_atexit.c
stdlib/cxa_finalize.c
stdlib/cxa_thread_atexit_impl.c
stdlib/exit.c
stdlib/on_exit.c
sysdeps/aarch64/__longjmp.S
sysdeps/aarch64/jmpbuf-offsets.h
sysdeps/aarch64/setjmp.S
sysdeps/alpha/__longjmp.S
sysdeps/alpha/jmpbuf-unwind.h
sysdeps/alpha/setjmp.S
sysdeps/arc/jmpbuf-unwind.h
sysdeps/arm/__longjmp.S
sysdeps/arm/jmpbuf-unwind.h
sysdeps/arm/pointer_guard.h [new file with mode: 0644]
sysdeps/arm/setjmp.S
sysdeps/arm/sysdep.h
sysdeps/csky/abiv2/__longjmp.S
sysdeps/csky/abiv2/setjmp.S
sysdeps/csky/jmpbuf-unwind.h
sysdeps/generic/pointer_guard.h [new file with mode: 0644]
sysdeps/generic/unwind-link.h
sysdeps/i386/__longjmp.S
sysdeps/i386/bsd-_setjmp.S
sysdeps/i386/bsd-setjmp.S
sysdeps/i386/jmpbuf-unwind.h
sysdeps/i386/setjmp.S
sysdeps/loongarch/__longjmp.S
sysdeps/loongarch/jmpbuf-unwind.h
sysdeps/loongarch/setjmp.S
sysdeps/m68k/jmpbuf-unwind.h
sysdeps/mach/hurd/i386/____longjmp_chk.S
sysdeps/mach/hurd/i386/__longjmp.S
sysdeps/mach/hurd/jmp-unwind.c
sysdeps/microblaze/jmpbuf-unwind.h
sysdeps/mips/jmpbuf-unwind.h
sysdeps/nios2/__longjmp.S
sysdeps/nios2/jmpbuf-offsets.h
sysdeps/nios2/setjmp.S
sysdeps/powerpc/jmpbuf-unwind.h
sysdeps/powerpc/powerpc32/__longjmp-common.S
sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
sysdeps/powerpc/powerpc32/setjmp-common.S
sysdeps/powerpc/powerpc64/__longjmp-common.S
sysdeps/powerpc/powerpc64/setjmp-common.S
sysdeps/riscv/jmpbuf-unwind.h
sysdeps/s390/jmpbuf-unwind.h
sysdeps/s390/s390-32/__longjmp.c
sysdeps/s390/s390-32/setjmp.S
sysdeps/s390/s390-64/__longjmp.c
sysdeps/s390/s390-64/setjmp.S
sysdeps/sh/jmpbuf-unwind.h
sysdeps/sh/sh3/__longjmp.S
sysdeps/sh/sh3/setjmp.S
sysdeps/sh/sh4/__longjmp.S
sysdeps/sh/sh4/setjmp.S
sysdeps/sparc/sparc32/__longjmp.S
sysdeps/sparc/sparc32/jmpbuf-unwind.h
sysdeps/sparc/sparc32/setjmp.S
sysdeps/unix/sysv/linux/aarch64/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/aarch64/sysdep.h
sysdeps/unix/sysv/linux/alpha/____longjmp_chk.S
sysdeps/unix/sysv/linux/alpha/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/alpha/sysdep.h
sysdeps/unix/sysv/linux/arc/sysdep.h
sysdeps/unix/sysv/linux/csky/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/csky/sysdep.h
sysdeps/unix/sysv/linux/hppa/sysdep.h
sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
sysdeps/unix/sysv/linux/i386/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/i386/sysdep.h
sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
sysdeps/unix/sysv/linux/ia64/__longjmp.S
sysdeps/unix/sysv/linux/ia64/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/ia64/setjmp.S
sysdeps/unix/sysv/linux/ia64/sysdep.h
sysdeps/unix/sysv/linux/loongarch/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/loongarch/sysdep.h
sysdeps/unix/sysv/linux/m68k/sysdep.h
sysdeps/unix/sysv/linux/microblaze/sysdep.h
sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
sysdeps/unix/sysv/linux/nios2/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/nios2/sysdep.h
sysdeps/unix/sysv/linux/or1k/sysdep.h
sysdeps/unix/sysv/linux/powerpc/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/powerpc/sysdep.h
sysdeps/unix/sysv/linux/riscv/sysdep.h
sysdeps/unix/sysv/linux/s390/s390-32/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
sysdeps/unix/sysv/linux/s390/s390-64/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
sysdeps/unix/sysv/linux/sh/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/sh/sysdep.h
sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
sysdeps/unix/sysv/linux/sparc/sparc32/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
sysdeps/unix/sysv/linux/sparc/sparc64/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
sysdeps/unix/sysv/linux/x86_64/pointer_guard.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/sysdep.h
sysdeps/x86_64/__longjmp.S
sysdeps/x86_64/jmpbuf-unwind.h
sysdeps/x86_64/setjmp.S
wcsmbs/btowc.c
wcsmbs/mbrtoc16.c
wcsmbs/mbrtoc8.c
wcsmbs/mbrtowc.c
wcsmbs/mbsnrtowcs.c
wcsmbs/mbsrtowcs_l.c
wcsmbs/wcrtomb.c
wcsmbs/wcsnrtombs.c
wcsmbs/wcsrtombs.c
wcsmbs/wctob.c

index de76cf2436d5514f1cf25f9e071e0dd79632596a..28213091e3e0b17c12e41501571f58c486dd8349 100644 (file)
@@ -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 *'
index 62d2b37bcdcfd464071682e8ed77e37c2bc5d063..dea9c80fee0ca8836f4a83958da62886362d3e54 100644 (file)
@@ -23,7 +23,7 @@
 #include <sys/param.h>
 
 #include <gconv_int.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 int
index c772856d1f8baf13b73c3f20cb12ad52d552870c..5dbf596b8df48b4450317ba319ece496dfcc095c 100644 (file)
@@ -28,6 +28,7 @@
 #include <gconv_int.h>
 #include <iconvconfig.h>
 #include <not-cancel.h>
+#include <pointer_guard.h>
 
 #include "../intl/hash-string.h"
 
index bf385ac7b1c336ff425ade83e5a5a60e05c9d252..90037fdf58d7da8235a85bb6e8e56fc2efd0f8e5 100644 (file)
@@ -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'
index 24c0bd1d39f2e9a89d32bc6adae8c0751bc8612a..c93c5dd3808071398be5fc083a19661034e00a73 100644 (file)
@@ -26,7 +26,7 @@
 #include <sys/param.h>
 
 #include <gconv_int.h>
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 #ifdef DEBUG
index 1ebbbfd51b14c59180fd236073321397351f0cee..0f4ce109963835e2067633341a91aba8933b46f9 100644 (file)
@@ -26,6 +26,7 @@
 #include <libc-lock.h>
 #include "gconv_int.h"
 #include "../locale/localeinfo.h"
+#include <pointer_guard.h>
 
 
 int
index 0356dbf92b7da1e6b761595bdad96ad084614233..42ee0b650875091daece66da4fb824847e253ed6 100644 (file)
 # include <dlfcn.h>
 #endif
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 #include <stdint.h>
 
 #ifndef DL_CALL_FCT
index 9c76681c6afd734af5fdfd5abda00b644bce6984..df5811fd6a190a611b877fe270a1784de396ab84 100644 (file)
@@ -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.  */
index e108ad219963045fa0f71bb9f350fddacc2cab3e..a7db4ef1c97432b050669d9665d6c46791f275a7 100644 (file)
@@ -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)
index 01616e06c75c2bea3ce5d59656c39a2952a9f0d5..1ce685f48a773177fc38f3e146867552eb8ce350 100644 (file)
@@ -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
index ba4fdbd200c2692d32fca55c992ca7155fb14718..dac3de73a138f0d46818d8053dea0b78785e1374 100644 (file)
@@ -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.  */
index 50acab7f216e59da3ec93f08c72fe40883b2c7ba..32459e4faca4c7d76580445b4f6f7972578c6557 100644 (file)
@@ -20,6 +20,7 @@
 #include <libioP.h>
 #include <stdio.h>
 #include <ldsodefs.h>
+#include <pointer_guard.h>
 
 #ifdef SHARED
 
index 9ae95612065d67fd076b09c627f4ae881fd6a9a8..45b7886b46d85a25a5b80d52f8f2e23d6a448c80 100644 (file)
@@ -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
index f00bbd9e1ad255538526778a8ae732c9d8c64320..9a8f3ddf949957c240185b2f9af9d528f4b6745f 100644 (file)
@@ -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
index 1412dacb07751c8dfc2fee8bdca51cff2d6b043d..adf89e93f52c9a0c90cd8c0dea1550168f18a550 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <libc-lock.h>
 #include "exit.h"
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #undef __cxa_atexit
 
index d4db2e1fe0e2ed93737864cb6bc15bd4aea15c70..f2479569a58d4ea02aae8193326cab82a1fe7c08 100644 (file)
@@ -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'
index 5cc8eb55dd8943a7f275d458ed4a483d8f1f9b44..faacab39907e865889cc0d0d203270a5410ce57d 100644 (file)
@@ -75,6 +75,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ldsodefs.h>
+#include <pointer_guard.h>
 
 typedef void (*dtor_func) (void *);
 
index bc46109f3e36260a3eb2e9bd2ceafa1f3f247931..e59156bbf602dee076b5aaf8b00067f37d282135 100644 (file)
@@ -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"
 
index 3e2d640d65ee9c1508d663442ee887c1c70e1508..fb59db20cab9cd6166acefbb1966cadae6ed2d42 100644 (file)
@@ -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
index 5f83f9f26454ecc67a5f5c7f3718848aef56349c..d934e00ec3deccc18def7b8bd282f35390e7beb6 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <stap-probe.h>
 
index 6256bda7a9622162db5e1946992238e0871719f5..78bdd4a5398f8491ec9b512a178a6dccf65bf06d 100644 (file)
@@ -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)
index 3860f4e0ec61dba10487c8c8917b565fccb993eb..2ed2feb4887cfb20543b82946ab5f74c092adf99 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 #include <stap-probe.h>
 
index ec7510bb5502073f9fcf07dd8aa78f530687bad4..aed7a17ed88a3e5d52fd28ed1abbd8de5f1297c0 100644 (file)
@@ -18,6 +18,7 @@
 #define __ASSEMBLY__
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 
index 13b27990b304f6a7977bdfb63ef51205d80e5be7..318b73b100aabbfa071e116f17565a3bccd2fc3b 100644 (file)
@@ -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.  */
index f86367ae08f924417be3bc63d2b9829efd7442ec..deb888c072f2ba7dc171e78cbd31e580839edbfe 100644 (file)
@@ -18,6 +18,7 @@
 #define __ASSEMBLY__
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
        .ent __sigsetjmp
index 5488707919a040cbaf275adf64b05d86c0d07db8..e5434a95dd13e9cc674e7644e1b7acaace27a365 100644 (file)
@@ -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.  */
index 5f1cf3643fcce19a7f6e83e21d969e8188c9cfb7..411055b9b35d208f0c6800cf63e61d29bff1aa2f 100644 (file)
@@ -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>
index e6b118f4d00348be0bdce21709240a5970bf2ac9..641444eaf39210b1f4d5b2b169b76a15a4d65b41 100644 (file)
@@ -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 (file)
index 0000000..6b90cec
--- /dev/null
@@ -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 */
index 1c26227437ae703c22b548d50e01fcf2e8408efc..271454d769df26b1643b0d73ea6036a7dffa68ab 100644 (file)
@@ -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>
index f19146b85f1c1902e5c1081a16b5627616f0b2e8..ffd848de88af40b48bb6193d307140599ceb5599 100644 (file)
 #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
index 762b2cb47f8cedfca3c8c86e79758467b29db2b9..bb7da548c20304983b8133908d0a34afa11f8299 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 ENTRY (__longjmp)
        mov     a2, a0
index 0acf197d02f7e905106c9b393ba15c8786a209eb..afef3ce390fc980234e9dd5536d934b6ad6c1047 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 
 ENTRY (setjmp)
        movi    a1, 1
index 358e912856fc9a27afed4f3d20fa097157c0122d..76fca431c63399b537940e08df34f60fb57d6031 100644 (file)
@@ -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 (file)
index 0000000..58a624e
--- /dev/null
@@ -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 */
index 93ee80f3f830a9439d39a30a1d9c43149460ebb4..a2076a23bfd4d188afbd9fcd36132a467a279b75 100644 (file)
@@ -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
index 508d370d5cb840bb0a3604dd44cdb64e02566257..b67781ceb75d0c7ca61841224499d4ba145f82fc 100644 (file)
@@ -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>
index 190e35b0c7c7f8796d3bb4ef7c8a980cee920f60..80399dba6e0841f516de8bcbd9a4427b5684177e 100644 (file)
@@ -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>
index 575ac96208554091ee8346e3d7a99e933e949071..b367bad85fe2cb361bf31ccd2e1c29b005d20bf7 100644 (file)
@@ -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>
index 416c816b450b0eabb56c0fcd99fad685074623d8..73d214fd31e4a3cd86b2ea57237168b698c0ac3c 100644 (file)
@@ -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.  */
index 217efbdf8a237b2abe7120fcff57fe03b88856d7..b528245806d73d083c6031d104f96c9dd436ec87 100644 (file)
@@ -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>
index d6a99fcbc8453e71650861ebee27b877e6cd29f4..4c40ffa1583ee6b7edc9a65be8c23ce66518127c 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <sys/asm.h>
 
 ENTRY (__longjmp)
index 6fa509151dc4fea6425c45c4acfad929fbed5945..458edec1353a7e35ed186dbd99d3adfc0f1316d9 100644 (file)
@@ -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.  */
index 9b1cdea48c7037d65eef97bd2d3f2f1e1e873578..e5f480d453b8b3929fef86df6280ea62885fab6c 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <sys/asm.h>
 
 ENTRY (_setjmp)
index 17e4b859ab348fda5ce604ba0cb81de50d0874f7..3ee46c050c0885df48679707e4abdf4bc43b60f9 100644 (file)
@@ -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.  */
index 1a019e2e2b9fe4623320034739ff7dd78c4e5c47..81d297de0c3d3d4eb9f2c5c0b177c1e81775af41 100644 (file)
@@ -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>
index 72fcc79f4bdfcdb6d59c52f51dc2c45334e2abcb..22915fb21ebc53274dcb350009e9a104794da1a5 100644 (file)
@@ -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>
index f8938bc6f4465ef1242d66951c317b5bba03a5d9..2577fbf3eefb06297d8b837249e8336dca7700ca 100644 (file)
@@ -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"
index f23c7581a72567e6d1478527012caefca662ae17..302e950ced4a48beb6c9f98627ca93f23040d59a 100644 (file)
@@ -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.  */
index 813c24f3b162bbba3903deea25294f8a41b98c07..28ecffedb0fd019fa77f3edd6d6cda185ba20974 100644 (file)
@@ -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.  */
index 214901d67d2a50cd42a0ea591d4237522f63bfec..13695e25a6c224e5c971b0050cbba7f0780bda43 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 /* __longjmp(jmpbuf, val) */
index a13aa76c165ffaa67438b4e0a2537d24461691f9..76fea64ffecafe898a2458a80304b0cfa618b120 100644 (file)
@@ -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)
index 0aa5b23d4f7639246edceacaa356fa7e6f87269e..ec75108b87049406321256778a4ef8335b6ea9ef 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
        .text
index 706ceda5d4203a7bd7d9ea77475c9df946940964..93573ce23850931af08a1a6050709ccbf8852977 100644 (file)
@@ -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.  */
index 13ded200e254d1c7265dbbb0d254ae6971006bdc..0e0361e4fda726ca957b916a702c2486c9dec702 100644 (file)
@@ -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__
index e3937222a7f5eaba760cd9ca3124181e9a85ff3a..de04a62be25d8a479d7be0daa40035ecf0e9b561 100644 (file)
@@ -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__
index f82196e6c2ac58593c8f60c59c6a82b6fee86cd1..1943ffd229bf9d40419f67f1cad1042767fb772e 100644 (file)
@@ -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__
index c632a3f8f225a1c255912f6d00831d9c7002a0de..281dd65f6a8108dc4498f5391af8e617ff9dfa36 100644 (file)
@@ -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__
index 5f629e1e0f2cf3a39dc9c3bfe880654685ee88cc..ff3e0beb2357571099698ee9424580a0fd4b191f 100644 (file)
@@ -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
index 19e76d59ee7a554c146584dc10855b05c71cb787..75389e4d266e83c19b984aab0129f67da4e3c4fe 100644 (file)
@@ -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__
index 28e73dda550729dfdc35aafb88bcb7b4de1e37df..b411a246d1923ca3cf4deca2b8800d0d17fd1117 100644 (file)
@@ -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.  */
index b4ff8da6e2468c28744f275e56940848ded42e5d..10b37f09c3f1396bc2eb27486ebb9eb5907a8af3 100644 (file)
@@ -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
index 09a3a2b8f85a3bff1383a5d1d20b9c07efa1ad76..83d42329a3935d5f2277e98d8e03f2e19d1bb6bc 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <setjmp.h>
 #include <bits/setjmp.h>
 #include <stdlib.h>
index c15c7bb99a596004f5ec9a976f4eef7db0ba6702..08704238f89226191ab3654c82ae8fe135b9f697 100644 (file)
@@ -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>
index 2ca96e1b1b28097351fd0ba1a65af05312bf6c6f..9fe4939e5ed018d956db3ffe326d5af6fa85c3ca 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <setjmp.h>
 #include <bits/setjmp.h>
 #include <stdlib.h>
index 6dcd77df1587b9b4e0c8da93f18b787218c7f85c..5c59f571a2a91aa79b79435a43c2dd163a174610 100644 (file)
@@ -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>
index c6672955aeaf6ab1bfd03f4ed53196eb7cdfe325..1957e5275d8d1e8d618b5c18dc5a1302f92e1f75 100644 (file)
@@ -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.  */
index 4228b5fef701b1d82198ec72e47fcb01d941684f..f10bed2afeb42450c92d975a1fe9bb95d2aba7d3 100644 (file)
@@ -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>
index 0dd0003efe8d94f8f236ef6ccca0146d94e1af1b..363e16fb1519e2e6fb1191477de17794f5418bc6 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 ENTRY (__sigsetjmp)
index 2013b717946c5b9baaf957631214d06365c6f0e0..bc179e4584660c6da4643f208cbff8d92191ea19 100644 (file)
@@ -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>
index b73aa3c18c11d70bcdf1da17ab5b8ec87e689589..f28ec42091d3364570d295e7124b56db1f172601 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <jmpbuf-offsets.h>
 
 ENTRY (__sigsetjmp)
index 5bed2440ac29bc221dbcd15825124fa28a7ab52b..68b3b15cb16cd4346f0b16c67c5aec5eded69544 100644 (file)
@@ -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)]
index 3ab5088555ae51227c21788bb2a8d8ee6f9054aa..8b697ed95bc9c94d0b4bd5d5e6f751e942138645 100644 (file)
@@ -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.  */
index 9c7531bc9535ef08be27f2ce0b8aab805d8ba7e5..c4e29c47b91caa3ed8c989d81d8d51d4855ca264 100644 (file)
@@ -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 (file)
index 0000000..b81c907
--- /dev/null
@@ -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 */
index f1853e012ffd2b6d023851a91e2960226ffaccfb..8ba50dab8f799f7610c53970cf975a105e70f041 100644 (file)
 
 #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 */
index 610f401d456fbcc71e475360a5fd3bbd4178a894..566a3b02113ab88380cf13c5aad9dd83eadad28b 100644 (file)
@@ -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 (file)
index 0000000..d4d513d
--- /dev/null
@@ -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 */
index 77ec2b540021ca175fffb8350e2a02067e1b80e0..0ddcb58b3086d796287c281364cacf18649d1103 100644 (file)
@@ -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  */
index d0c1a78381886f92972f5397c1b25b3075d1e565..512284a70571fa262a8983cdec13780449a9cc64 100644 (file)
@@ -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 (file)
index 0000000..ed68322
--- /dev/null
@@ -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 */
index 56c527fa8beff38df27ba40fc45425f0a64786c1..76b09f0cc665123c1cf77d07b616e69607e6af42 100644 (file)
@@ -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 */
index 2f339a4bd6e54430824108bd7080dce2f6b512d5..3aef8f536ab43def88a853ddce2bc972d28f2047 100644 (file)
@@ -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 */
index a1cf9a4b211a7e79e28c8c58e7469596b2c5cb5d..f409542a62f957229728218b5b43abb1d21af4f6 100644 (file)
@@ -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 (file)
index 0000000..a2d2a0c
--- /dev/null
@@ -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 */
index 7085f7e19ac5ae964191ed394081d3284aa79a0b..b8be668a4238be6dba4396dee13fb2e550a42a23 100644 (file)
@@ -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.  */
index 9511c159450c825be409a71d40d3b53541eabda6..4ef51296234b540195624a6be0abdcd849ea5aa4 100644 (file)
@@ -15,6 +15,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
+#include <pointer_guard.h>
 #include <features.h>
 
 LEAF(__ia64_flush_rbs)
index 793dc98cc185a1239bf8a94e3c0e0bda9cb41de6..da9653d8a7b8f88ee6000e7a7285a9ca4ff9cdb6 100644 (file)
@@ -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 (file)
index 0000000..8631f39
--- /dev/null
@@ -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 */
index c29a31f7a6c6d31cc88d63c3bb00866fb0b4bb7b..a978dd4360f1499f4cc6cb61b642f59cacafd180 100644 (file)
@@ -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: */
index 14adbdf4ff9d3865fbb7984bd2f69d60e2120568..b450c6c224915cd9f605f9a4c48b55762f5ca07b 100644 (file)
 
 #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 (file)
index 0000000..4b2ed46
--- /dev/null
@@ -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 */
index f4a1d23a97496147390aea424a01e541a89d6cc5..09f8243f252f749c43eabc00fe518b5b409ef565 100644 (file)
@@ -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 */
index d87892a377df2cb4cd64d91c46a4c87221544252..064240330a844b9ff3829c59bdd89517e69983e8 100644 (file)
@@ -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
index fda78f6467eab69895915aeaef723741026b5a4a..19805f6b5da593805965a36940b095244b53456d 100644 (file)
@@ -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
 
index a2a93bc84055664aec3230beb913abd65ad82a6d..0ef410c3c9394a663fa43887490e773417541499 100644 (file)
@@ -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 */
index 2c16a6758d373ab259a94ec41bf3fe6e8bbd6c18..e362f15300be9d7f3f7076da8936eba29259acc0 100644 (file)
@@ -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 (file)
index 0000000..da17809
--- /dev/null
@@ -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 */
index 5fe960c2a546eabd1cccb482b807c6cfd88a7d96..46667b9c19813ef3dfb1a8e0f1e2b98ffc9abd8f 100644 (file)
 
 #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 */
index 941c93455436519b718bcc5b3dec504fde0bef53..b1fdf2a80694f93a2e69ee06bdcef9d9198102c4 100644 (file)
@@ -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 (file)
index 0000000..5961793
--- /dev/null
@@ -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 */
index 4fb135aa8d4ce6b374ab9e424a915ba357f5a1bb..9e44818978619373b563321186803d5311c8634a 100644 (file)
 #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
index 9b03b105670b5222202d91e587b514d39e760123..c9af888132266d62adf345809451af5754176b17 100644 (file)
@@ -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 (file)
index 0000000..0e85d4c
--- /dev/null
@@ -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 */
index e41106b377d89e62fca179ad086883c6dfdcc8f3..a24fde7c6d7f828037a47f4dbe555be25cb9eaad 100644 (file)
 
 #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 (file)
index 0000000..5285456
--- /dev/null
@@ -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 */
index 150e33981ae6128b87931e9394fc82fdb4b1d90b..79bc0fa4a6e6c2ef78a3ad825fa194ab45cbb473 100644 (file)
 
 #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 */
index e821e158c4bdacffc37aa511ba71276ce6fd5c1a..cf69926316b64ebc14de25fc4423c068a5749618 100644 (file)
@@ -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 (file)
index 0000000..32a571d
--- /dev/null
@@ -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 */
index e9e13cd18461c8d2976bfd70b0977ef85b541a95..a2f43f68c3c4b6846781ed338e5f805b385c0423 100644 (file)
 
 #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 */
index 8e8cb4d751443d2ed95511ab07e91fa1c1ca42f3..ad23840bcdbae92fef88f519892cde154f92b3f8 100644 (file)
@@ -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 (file)
index 0000000..4063513
--- /dev/null
@@ -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 */
index 032608a4e05297c5b9ccf70549217e4da260e4d3..1783af8178968144fa5654313853722b437f0abb 100644 (file)
@@ -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 (file)
index 0000000..7865e87
--- /dev/null
@@ -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 */
index 4aaa2912ce3efcecc63ab8fe0b227c598197ecdd..4ae22ae25bac55d0ae6884c2a9c30f385bfecabe 100644 (file)
@@ -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 */
index ffdf4624bf98648e4bc423cbdf1ce9b46ebf5fd2..5ff275c436f2fee4998fabe45fd50780caca908b 100644 (file)
@@ -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 (file)
index 0000000..2df3912
--- /dev/null
@@ -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 */
index 740abefcfd3612928bdd42c605ebdcf341d76667..5e4d7827d7cb358e92a2d26ad8a336135fe6a7ba 100644 (file)
 
 #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
index b51d79168cff007aa4198cca48a8ce22116823db..6fdb4ccfbfaae87ff3e78ee5a801e27a241098a1 100644 (file)
@@ -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>
index 42ea37508e2747f5f8fdb1065e8e428162f5eda4..c92b2633bcd6f056ce7262b0df94e1be2c79dae0 100644 (file)
@@ -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.  */
index 1b77dcd4f995be6f538ec5748031d0cf64305059..3897e66dc442b99cf738ff140bb0e8c9af48d113 100644 (file)
@@ -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>
index 21e52a67f46360f9c7f35f3d7ce966366e9ccc03..7023ec99f15d3ce777ed12f0dfc40f760c540c04 100644 (file)
@@ -24,7 +24,7 @@
 #include <wcsmbsload.h>
 #include <limits.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 wint_t
index b23d9b0160a12cf67e1fe8f4588f0250414b82bb..f8b029b58a81e0c68d4b8ccb5ffa432a94519d0f 100644 (file)
@@ -22,7 +22,7 @@
 #include <uchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index dd80b5282df5403596a13048d3d5c3ad5be9140a..e745a49e096457604e9d682167f8b066f47d8ab7 100644 (file)
@@ -23,8 +23,6 @@
 #include <uchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
-
 #ifndef EILSEQ
 # define EILSEQ EINVAL
 #endif
index 78d9994f67462baf76764e9ccbc49ff48a7f691b..46a1cc38dfbcb2c27ac10d4f03c24169994fa8b9 100644 (file)
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index 58608224009ef47d550c28014a01bdc7ba8a6609..06a1f2d36f8a106e7c276231637392c12187aee7 100644 (file)
@@ -23,7 +23,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index 0ebc389fdbdc80506b43a509aadf0e4753a3e5c6..526b88e1dd37526fb0e09ecacd5221e404d487eb 100644 (file)
@@ -27,7 +27,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index c0cce3792fc98b15423d7885d5ec568403a9eb60..42690f2efdc05a15d802e55510f82bfdc3591635 100644 (file)
@@ -25,7 +25,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index 9707f6f4bc2a3fb3b1208564caaadd5439cd11a2..6ba180cdc2bbcae5caf664cbf13d1b28bcaa90de 100644 (file)
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index b1ac704b286f3958de6e7fef4a59a894876de363..7db2b181b399796f502250d5d4a55afe318c048f 100644 (file)
@@ -23,7 +23,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 #ifndef EILSEQ
 # define EILSEQ EINVAL
index 573c2c94485b3df966f4782ce4e0de9de7737ea6..5dfbd7ab7e4141c7e7d6a539dcca2785bb5b615b 100644 (file)
@@ -22,7 +22,7 @@
 #include <wchar.h>
 #include <wcsmbsload.h>
 
-#include <sysdep.h>
+#include <pointer_guard.h>
 
 
 int