[PATCH v7 20/23] aarch64: Process gnu properties in static exe
Yury Khrustalev
yury.khrustalev@arm.com
Fri Jan 3 15:41:38 GMT 2025
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Unlike for BTI, the kernel does not process GCS properties so update
GL(dl_aarch64_gcs) before the GCS status is set.
Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com>
---
csu/libc-start.c | 12 ++++++++++++
sysdeps/generic/libc-start.h | 1 +
sysdeps/unix/sysv/linux/aarch64/libc-start.h | 19 +++++++++++++++++++
3 files changed, 32 insertions(+)
diff --git a/csu/libc-start.c b/csu/libc-start.c
index 6f3d52e223..325ef010d4 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -206,6 +206,10 @@ call_fini (void *unused)
#include <libc-start.h>
+#ifndef ARCH_PROCESS_NOTES
+# define ARCH_PROCESS_NOTES()
+#endif
+
STATIC int LIBC_START_MAIN (int (*main) (int, char **, char **
MAIN_AUXVEC_DECL),
int argc,
@@ -219,6 +223,11 @@ STATIC int LIBC_START_MAIN (int (*main) (int, char **, char **
void *stack_end)
__attribute__ ((noreturn));
+void
+__libc_process_notes (void)
+{
+
+}
/* Note: The init and fini parameters are no longer used. fini is
completely unused, init is still called if not NULL, but the
@@ -276,6 +285,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Perform IREL{,A} relocations. */
ARCH_SETUP_IREL ();
+ /* Process notes: PT_NOTE / PT_GNU_PROPERTY. */
+ ARCH_PROCESS_NOTES ();
+
/* The stack guard goes into the TCB, so initialize it early. */
ARCH_SETUP_TLS ();
diff --git a/sysdeps/generic/libc-start.h b/sysdeps/generic/libc-start.h
index 0b107cf2a1..1a421626b5 100644
--- a/sysdeps/generic/libc-start.h
+++ b/sysdeps/generic/libc-start.h
@@ -24,6 +24,7 @@
initialization, and this means you cannot, without machine
knowledge, access TLS from an IFUNC resolver. */
#define ARCH_SETUP_IREL() apply_irel ()
+#define ARCH_PROCESS_NOTES() __libc_process_notes ()
#define ARCH_SETUP_TLS() __libc_setup_tls ()
#define ARCH_APPLY_IREL()
#endif /* ! SHARED */
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.h b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
index 735076c086..0f80a8abe9 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc-start.h
+++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
@@ -21,6 +21,24 @@
#ifndef SHARED
+# include <dl-prop.h>
+
+/* Must be on a top-level stack frame that does not return. */
+static inline void __attribute__((always_inline))
+aarch64_libc_process_notes (void)
+{
+ struct link_map *main_map = _dl_get_dl_main_map ();
+ const ElfW(Phdr) *phdr = GL(dl_phdr);
+ const ElfW(Phdr) *ph;
+ for (ph = phdr; ph < phdr + GL(dl_phnum); ph++)
+ if (ph->p_type == PT_GNU_PROPERTY)
+ {
+ _dl_process_pt_gnu_property (main_map, -1, ph);
+ _rtld_main_check (main_map, _dl_argv[0]);
+ break;
+ }
+}
+
# ifndef PR_SET_SHADOW_STACK_STATUS
# define PR_SET_SHADOW_STACK_STATUS 75
# define PR_SHADOW_STACK_ENABLE (1UL << 0)
@@ -39,6 +57,7 @@ aarch64_libc_setup_tls (void)
}
# define ARCH_SETUP_IREL() apply_irel ()
+# define ARCH_PROCESS_NOTES() aarch64_libc_process_notes ()
# define ARCH_SETUP_TLS() aarch64_libc_setup_tls ()
# define ARCH_APPLY_IREL()
#endif /* ! SHARED */
--
2.39.5
More information about the Libc-alpha
mailing list