|
|
Message-ID: <20251208174940.949856-11-bill.roberts@arm.com>
Date: Mon, 8 Dec 2025 11:44:53 -0600
From: Bill Roberts <bill.roberts@....com>
To: musl@...ts.openwall.com
Cc: Bill Roberts <bill.roberts@....com>
Subject: [RFC 10/14] aarch64: rewrite setjmp routines in C using inline asm
Rewrite the AArch64 __setjmp, _setjmp and setjmp routines from assembly into
implementations using inline assembly.
This change eliminates the need for handwritten function prologues and
epilogues in setjmp.s, which simplifies maintenance and allows the compiler
to automatically insert architecture features such as BTI landing pads and
pointer authentication (PAC) sequences where applicable.
Moving to C also enables the compiler to manage register allocation,
stack usage, and ABI compliance automatically while keeping the low-level
behavior (bitmasks and register accesses) explicit and verifiable.
No functional changes intended.
Signed-off-by: Bill Roberts <bill.roberts@....com>
---
src/setjmp/aarch64/setjmp.c | 34 ++++++++++++++++++++++++++++++++++
src/setjmp/aarch64/setjmp.s | 24 ------------------------
2 files changed, 34 insertions(+), 24 deletions(-)
create mode 100644 src/setjmp/aarch64/setjmp.c
delete mode 100644 src/setjmp/aarch64/setjmp.s
diff --git a/src/setjmp/aarch64/setjmp.c b/src/setjmp/aarch64/setjmp.c
new file mode 100644
index 00000000..2eb3dc68
--- /dev/null
+++ b/src/setjmp/aarch64/setjmp.c
@@ -0,0 +1,34 @@
+#include <setjmp.h>
+
+__attribute__((returns_twice))
+int setjmp(jmp_buf env)
+{
+ __asm__ __volatile__(
+ /* Save integer callee-saved registers x19..x30 */
+ "stp x19, x20, [x0, #0]\n\t"
+ "stp x21, x22, [x0, #16]\n\t"
+ "stp x23, x24, [x0, #32]\n\t"
+ "stp x25, x26, [x0, #48]\n\t"
+ "stp x27, x28, [x0, #64]\n\t"
+ "stp x29, x30, [x0, #80]\n\t"
+
+ /* Save SP at offset 104 */
+ "mov x2, sp\n\t"
+ "str x2, [x0, #104]\n\t"
+
+ /* Save FP/SIMD callee-saved d8..d15 */
+ "stp d8, d9, [x0, #112]\n\t"
+ "stp d10, d11, [x0, #128]\n\t"
+ "stp d12, d13, [x0, #144]\n\t"
+ "stp d14, d15, [x0, #160]\n\t"
+ :
+ :
+ : "x2", "memory"
+ );
+
+ return 0;
+}
+
+/* Make _setjmp and __setjmp the same symbol as setjmp in this TU. */
+__attribute__((alias("setjmp"))) int _setjmp(jmp_buf);
+__attribute__((alias("setjmp"))) int __setjmp(jmp_buf);
diff --git a/src/setjmp/aarch64/setjmp.s b/src/setjmp/aarch64/setjmp.s
deleted file mode 100644
index f49288aa..00000000
--- a/src/setjmp/aarch64/setjmp.s
+++ /dev/null
@@ -1,24 +0,0 @@
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,@function
-.type _setjmp,@function
-.type setjmp,@function
-__setjmp:
-_setjmp:
-setjmp:
- // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
- stp x19, x20, [x0,#0]
- stp x21, x22, [x0,#16]
- stp x23, x24, [x0,#32]
- stp x25, x26, [x0,#48]
- stp x27, x28, [x0,#64]
- stp x29, x30, [x0,#80]
- mov x2, sp
- str x2, [x0,#104]
- stp d8, d9, [x0,#112]
- stp d10, d11, [x0,#128]
- stp d12, d13, [x0,#144]
- stp d14, d15, [x0,#160]
- mov x0, #0
- ret
--
2.51.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.