aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2025-01-02 17:31:39 +0000
committerWilco Dijkstra <wilco.dijkstra@arm.com>2025-02-24 14:17:57 +0000
commiteb7ac024d9e5ac71f6c9695703c3db6b05744b86 (patch)
treeb2b2c847dd801f603a01aec611f82568016da2b4
parent19860fd42e39cfa03ba3c3c8becf27229eabc597 (diff)
downloadglibc-eb7ac024d9e5ac71f6c9695703c3db6b05744b86.zip
glibc-eb7ac024d9e5ac71f6c9695703c3db6b05744b86.tar.gz
glibc-eb7ac024d9e5ac71f6c9695703c3db6b05744b86.tar.bz2
AArch64: Cleanup pointer mangling
Cleanup pointer mangling. Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
-rw-r--r--sysdeps/aarch64/__longjmp.S22
-rw-r--r--sysdeps/aarch64/setjmp.S15
-rw-r--r--sysdeps/aarch64/sysdep.h13
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/pointer_guard.h35
4 files changed, 27 insertions, 58 deletions
diff --git a/sysdeps/aarch64/__longjmp.S b/sysdeps/aarch64/__longjmp.S
index b79a76b..981bf80 100644
--- a/sysdeps/aarch64/__longjmp.S
+++ b/sysdeps/aarch64/__longjmp.S
@@ -74,11 +74,9 @@ ENTRY (__longjmp)
ldp x23, x24, [x0, #JB_X23<<3]
ldp x25, x26, [x0, #JB_X25<<3]
ldp x27, x28, [x0, #JB_X27<<3]
-#ifdef PTR_DEMANGLE
- ldp x29, x4, [x0, #JB_X29<<3]
- PTR_DEMANGLE (30, 4, 3, 2)
-#else
ldp x29, x30, [x0, #JB_X29<<3]
+#ifdef PTR_DEMANGLE
+ PTR_DEMANGLE (x30, x30, x3)
#endif
/* longjmp probe takes 3 arguments, address of jump buffer as
first argument (8@x0), return value as second argument (-4@x1),
@@ -149,21 +147,21 @@ L(gcs_done):
cfi_same_value(d13)
cfi_same_value(d14)
cfi_same_value(d15)
-#ifdef PTR_DEMANGLE
+
ldr x4, [x0, #JB_SP<<3]
- PTR_DEMANGLE (5, 4, 3, 2)
-#else
- ldr x5, [x0, #JB_SP<<3]
+#ifdef PTR_DEMANGLE
+ PTR_DEMANGLE (x4, x4, x3)
#endif
- mov sp, x5
+ mov sp, x4
/* longjmp_target probe takes 3 arguments, address of jump buffer
as first argument (8@x0), return value as second argument (-4@x1),
and target address (8@x30), respectively. */
LIBC_PROBE (longjmp_target, 3, 8@x0, -4@x1, 8@x30)
- cmp x1, #0
- mov x0, #1
- csel x0, x1, x0, ne
+
+ cmp x1, 0
+ cinc x0, x1, eq
+
/* Use br instead of ret because ret is guaranteed to mispredict */
br x30
END (__longjmp)
diff --git a/sysdeps/aarch64/setjmp.S b/sysdeps/aarch64/setjmp.S
index 73e204c..d82d62c 100644
--- a/sysdeps/aarch64/setjmp.S
+++ b/sysdeps/aarch64/setjmp.S
@@ -27,13 +27,13 @@ ENTRY (setjmp)
b 1f
END (setjmp)
-ENTRY (_setjmp)
+ENTRY_ALIGN (_setjmp, 2)
mov x1, #0
b 1f
END (_setjmp)
libc_hidden_def (_setjmp)
-ENTRY (__sigsetjmp)
+ENTRY_ALIGN (__sigsetjmp, 2)
1:
stp x19, x20, [x0, #JB_X19<<3]
stp x21, x22, [x0, #JB_X21<<3]
@@ -42,7 +42,7 @@ ENTRY (__sigsetjmp)
stp x27, x28, [x0, #JB_X27<<3]
#ifdef PTR_MANGLE
- PTR_MANGLE (4, 30, 3, 2)
+ PTR_MANGLE (x4, x30, x3)
stp x29, x4, [x0, #JB_X29<<3]
#else
stp x29, x30, [x0, #JB_X29<<3]
@@ -65,14 +65,11 @@ ENTRY (__sigsetjmp)
str x2, [x0, #JB_GCSPR]
L(gcs_done):
+ mov x2, sp
#ifdef PTR_MANGLE
- mov x4, sp
- PTR_MANGLE (5, 4, 3, 2)
- str x5, [x0, #JB_SP<<3]
-#else
- mov x2, sp
- str x2, [x0, #JB_SP<<3]
+ PTR_MANGLE (x2, x2, x3)
#endif
+ str x2, [x0, #JB_SP<<3]
#if IS_IN (rtld)
/* In ld.so we never save the signal mask */
mov w0, #0
diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index b4aa191..3ca0040 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -181,19 +181,6 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS)
# define L(name) .L##name
#endif
-/* Load or store to/from a pc-relative EXPR into/from R, using T.
- Note R and T are register numbers and not register names. */
-#define LDST_PCREL(OP, R, T, EXPR) \
- adrp x##T, EXPR; \
- OP x##R, [x##T, #:lo12:EXPR]; \
-
-/* Load or store to/from a got-relative EXPR into/from R, using T.
- Note R and T are register numbers and not register names. */
-#define LDST_GLOBAL(OP, R, T, EXPR) \
- adrp x##T, :got:EXPR; \
- ldr x##T, [x##T, #:got_lo12:EXPR]; \
- OP x##R, [x##T];
-
/* Since C identifiers are not normally prefixed with an underscore
on this system, the asm identifier `syscall_error' intrudes on the
C name space. Make sure we use an innocuous name. */
diff --git a/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
index ca2b23f..fd4501b 100644
--- a/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
+++ b/sysdeps/unix/sysv/linux/aarch64/pointer_guard.h
@@ -24,18 +24,11 @@
|| (!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)
+# define PTR_MANGLE(dst, src, tmp) \
+ adrp tmp, C_SYMBOL_NAME(__pointer_chk_guard_local); \
+ ldr tmp, [tmp, :lo12:C_SYMBOL_NAME(__pointer_chk_guard_local)]; \
+ eor dst, src, tmp
+# define PTR_DEMANGLE(dst, src, tmp) PTR_MANGLE (dst, src, tmp)
# else
extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
# define PTR_MANGLE(var) \
@@ -44,18 +37,12 @@ extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
# 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)
+# define PTR_MANGLE(dst, src, tmp) \
+ adrp tmp, :got:C_SYMBOL_NAME(__pointer_chk_guard); \
+ ldr tmp, [tmp, :got_lo12:C_SYMBOL_NAME(__pointer_chk_guard)]; \
+ ldr tmp, [tmp]; \
+ eor dst, src, tmp;
+# define PTR_DEMANGLE(dst, src, tmp) PTR_MANGLE (dst, src, tmp)
# else
# include <stdint.h>
extern uintptr_t __pointer_chk_guard attribute_relro;