aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2023-07-13 07:22:44 +0100
committerYury Khrustalev <yury.khrustalev@arm.com>2025-01-20 09:31:47 +0000
commitb81ee54bc90521f10c2ea07f746859377653ec28 (patch)
tree1d6cd1fe3540171fb218f613f8b87fbfe47a92ba
parent9ad3d9267d1e0ddda264e54cd4176fa927e2e0ca (diff)
downloadglibc-b81ee54bc90521f10c2ea07f746859377653ec28.zip
glibc-b81ee54bc90521f10c2ea07f746859377653ec28.tar.gz
glibc-b81ee54bc90521f10c2ea07f746859377653ec28.tar.bz2
aarch64: Enable GCS in static linked exe
Use the ARCH_SETUP_TLS hook to enable GCS in the static linked case. The system call must be inlined and then GCS is enabled on a top level stack frame that does not return and has no exception handlers above it. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/libc-start.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.h b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
new file mode 100644
index 0000000..2ea61bf
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
@@ -0,0 +1,48 @@
+/* AArch64 definitions for libc main startup.
+ Copyright (C) 2024-2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC_START_H
+#define _LIBC_START_H
+
+#ifndef SHARED
+
+# ifndef PR_SET_SHADOW_STACK_STATUS
+# define PR_SET_SHADOW_STACK_STATUS 75
+# define PR_SHADOW_STACK_ENABLE (1UL << 0)
+# endif
+
+/* Must be on a top-level stack frame that does not return. */
+static inline void __attribute__((always_inline))
+aarch64_libc_setup_tls (void)
+{
+ __libc_setup_tls ();
+ if (GL(dl_aarch64_gcs) != 0)
+ {
+ int ret = INLINE_SYSCALL_CALL (prctl, PR_SET_SHADOW_STACK_STATUS,
+ PR_SHADOW_STACK_ENABLE, 0, 0, 0);
+ if (ret)
+ _dl_fatal_printf ("failed to enable GCS: %d\n", -ret);
+ }
+}
+
+# define ARCH_SETUP_IREL() apply_irel ()
+# define ARCH_SETUP_TLS() aarch64_libc_setup_tls ()
+# define ARCH_APPLY_IREL()
+#endif /* ! SHARED */
+
+#endif /* _LIBC_START_H */