glibc/glibc-upstream-2.39-270.patch
2026-05-19 15:08:01 -04:00

138 lines
3.9 KiB
Diff

commit dbe1904b7c0da4a2e9a548a8826a46d277ff8cca
Author: Yury Khrustalev <yury.khrustalev@arm.com>
Date: Tue Oct 21 13:48:34 2025 +0100
aarch64: define macro for calling __libc_arm_za_disable
A common sequence of instructions is used in several places
in assembly files, so define it in one place as an assembly
macro.
Note that PAC instructions are not included in the new macro
because they are redundant given how we call the arm_za_disable
function (return address is not saved on stack, so no need to
sign it).
(based on commits 6de12fc9ad56bc19fa6fcbd8ee502f29b5170d47
and c0f0db2d59e0908057205b22b21dd9d626d780c1)
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 1a0ee267147d002d66af29bcf3f5002d19b3c75a)
(cherry picked from commit 7af8db46d2493521cb8e0c13907f601a61236ebf)
diff --git a/sysdeps/aarch64/__longjmp.S b/sysdeps/aarch64/__longjmp.S
index 30b36cb25d921795..312651c9bc3bed41 100644
--- a/sysdeps/aarch64/__longjmp.S
+++ b/sysdeps/aarch64/__longjmp.S
@@ -27,24 +27,7 @@ ENTRY (__longjmp)
#if IS_IN(libc)
/* Disable ZA state of SME in libc.a and libc.so, but not in ld.so. */
-# if HAVE_AARCH64_PAC_RET
- PACIASP
- cfi_window_save
-# endif
- stp x29, x30, [sp, -16]!
- cfi_adjust_cfa_offset (16)
- cfi_rel_offset (x29, 0)
- cfi_rel_offset (x30, 8)
- mov x29, sp
- bl __libc_arm_za_disable
- ldp x29, x30, [sp], 16
- cfi_adjust_cfa_offset (-16)
- cfi_restore (x29)
- cfi_restore (x30)
-# if HAVE_AARCH64_PAC_RET
- AUTIASP
- cfi_window_save
-# endif
+ CALL_LIBC_ARM_ZA_DISABLE
#endif
cfi_def_cfa (x0, 0)
diff --git a/sysdeps/aarch64/setjmp.S b/sysdeps/aarch64/setjmp.S
index b2addd44ed7604b7..7d069e91efa00563 100644
--- a/sysdeps/aarch64/setjmp.S
+++ b/sysdeps/aarch64/setjmp.S
@@ -38,24 +38,7 @@ ENTRY (__sigsetjmp)
#if IS_IN(libc)
/* Disable ZA state of SME in libc.a and libc.so, but not in ld.so. */
-# if HAVE_AARCH64_PAC_RET
- PACIASP
- cfi_window_save
-# endif
- stp x29, x30, [sp, -16]!
- cfi_adjust_cfa_offset (16)
- cfi_rel_offset (x29, 0)
- cfi_rel_offset (x30, 8)
- mov x29, sp
- bl __libc_arm_za_disable
- ldp x29, x30, [sp], 16
- cfi_adjust_cfa_offset (-16)
- cfi_restore (x29)
- cfi_restore (x30)
-# if HAVE_AARCH64_PAC_RET
- AUTIASP
- cfi_window_save
-# endif
+ CALL_LIBC_ARM_ZA_DISABLE
#endif
stp x19, x20, [x0, #JB_X19<<3]
diff --git a/sysdeps/unix/sysv/linux/aarch64/setcontext.S b/sysdeps/unix/sysv/linux/aarch64/setcontext.S
index 8c072781cdf98c2b..81ed2b92423a52d0 100644
--- a/sysdeps/unix/sysv/linux/aarch64/setcontext.S
+++ b/sysdeps/unix/sysv/linux/aarch64/setcontext.S
@@ -48,25 +48,8 @@ ENTRY (__setcontext)
cbz x0, 1f
b C_SYMBOL_NAME (__syscall_error)
1:
- /* Disable ZA of SME. */
-#if HAVE_AARCH64_PAC_RET
- PACIASP
- cfi_window_save
-#endif
- stp x29, x30, [sp, -16]!
- cfi_adjust_cfa_offset (16)
- cfi_rel_offset (x29, 0)
- cfi_rel_offset (x30, 8)
- mov x29, sp
- bl __libc_arm_za_disable
- ldp x29, x30, [sp], 16
- cfi_adjust_cfa_offset (-16)
- cfi_restore (x29)
- cfi_restore (x30)
-#if HAVE_AARCH64_PAC_RET
- AUTIASP
- cfi_window_save
-#endif
+ /* Clear ZA state of SME. */
+ CALL_LIBC_ARM_ZA_DISABLE
/* Restore the general purpose registers. */
mov x0, x9
cfi_def_cfa (x0, 0)
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 974b503b2f93511d..2f039015190d7b24 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -150,6 +150,18 @@
mov x8, SYS_ify (syscall_name); \
svc 0
+/* Clear ZA state of SME (ASM version). */
+/* The __libc_arm_za_disable function has special calling convention
+ that allows to call it without stack manipulation and preserving
+ most of the registers. */
+ .macro CALL_LIBC_ARM_ZA_DISABLE
+ mov x13, x30
+ .cfi_register x30, x13
+ bl __libc_arm_za_disable
+ mov x30, x13
+ .cfi_register x13, x30
+ .endm
+
#else /* not __ASSEMBLER__ */
# ifdef __LP64__