]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
AArch64: Cleanup pointer mangling
authorWilco Dijkstra <wilco.dijkstra@arm.com>
Thu, 2 Jan 2025 17:31:39 +0000 (17:31 +0000)
committerWilco Dijkstra <wilco.dijkstra@arm.com>
Mon, 24 Feb 2025 14:17:57 +0000 (14:17 +0000)
Cleanup pointer mangling.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
sysdeps/aarch64/__longjmp.S
sysdeps/aarch64/setjmp.S
sysdeps/aarch64/sysdep.h
sysdeps/unix/sysv/linux/aarch64/pointer_guard.h

index b79a76b7ce0ec5cbcd0a6acbf64007b7645f227a..981bf808337e2947d294e47cc2d4f3cb0c8f1930 100644 (file)
@@ -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)
index 73e204c349d83e8bbdd67cc1df926cca6efb7354..d82d62c0a1c4f718982d9d8c4d4144ef94cac4e5 100644 (file)
@@ -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
index b4aa191dea39c219c2e0d6456111cfeef2e706e6..3ca0040f54fffc372508354a18de9bc6418b1276 100644 (file)
@@ -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.  */
index ca2b23f16b7a4d76108ab75fe575d0879c471490..fd4501ba3370be3033d4db7961ad8bd1bb69721e 100644 (file)
      || (!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;