[PATCH v2 5/8] Remove the jmp_buf stack pointer demangle on ABIs that do not mangle it
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri Jun 12 16:10:13 GMT 2026
arc, m68k, microblaze, mips, and riscv store the raw stack pointer in
setjmp, while their jmpbuf-unwind.h applies PTR_DEMANGLE to it in
_jmpbuf_sp. This is currently harmless because these ABIs use the
generic pointer_guard.h, where the C PTR_DEMANGLE is a no-op.
No functional change.
---
sysdeps/arc/jmpbuf-unwind.h | 7 +++----
sysdeps/m68k/jmpbuf-unwind.h | 7 +++----
sysdeps/microblaze/jmpbuf-unwind.h | 7 +++----
sysdeps/mips/jmpbuf-unwind.h | 7 +++----
sysdeps/riscv/jmpbuf-unwind.h | 7 +++----
5 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/sysdeps/arc/jmpbuf-unwind.h b/sysdeps/arc/jmpbuf-unwind.h
index d007c785649..48a9f9a7c53 100644
--- a/sysdeps/arc/jmpbuf-unwind.h
+++ b/sysdeps/arc/jmpbuf-unwind.h
@@ -20,7 +20,6 @@
#include <jmpbuf-offsets.h>
#include <stdint.h>
#include <unwind.h>
-#include <pointer_guard.h>
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
@@ -31,12 +30,12 @@
#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
_JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+/* setjmp does not mangle the stack pointer on this ABI, so the saved
+ value is used as-is. */
static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf jmpbuf)
{
- uintptr_t sp = jmpbuf[JB_SP];
- PTR_DEMANGLE (sp);
- return sp;
+ return jmpbuf[JB_SP];
}
#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
diff --git a/sysdeps/m68k/jmpbuf-unwind.h b/sysdeps/m68k/jmpbuf-unwind.h
index 9c5206fb69f..2f4bc71d5bc 100644
--- a/sysdeps/m68k/jmpbuf-unwind.h
+++ b/sysdeps/m68k/jmpbuf-unwind.h
@@ -19,7 +19,6 @@
#include <setjmp.h>
#include <stdint.h>
#include <unwind.h>
-#include <pointer_guard.h>
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
@@ -29,12 +28,12 @@
#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
_JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+/* setjmp does not mangle the stack pointer on this ABI, so the saved
+ value is used as-is. */
static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf regs)
{
- uintptr_t sp = (uintptr_t) regs[0].__sp;
- PTR_DEMANGLE (sp);
- return sp;
+ return (uintptr_t) regs[0].__sp;
}
#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
diff --git a/sysdeps/microblaze/jmpbuf-unwind.h b/sysdeps/microblaze/jmpbuf-unwind.h
index cb28dd83ec4..9584203257a 100644
--- a/sysdeps/microblaze/jmpbuf-unwind.h
+++ b/sysdeps/microblaze/jmpbuf-unwind.h
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <unwind.h>
#include <sysdep.h>
-#include <pointer_guard.h>
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
@@ -30,12 +29,12 @@
#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
_JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+/* setjmp does not mangle the stack pointer on this ABI, so the saved
+ value is used as-is. */
static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf regs)
{
- void *sp = (void *) regs[0].__sp;
- PTR_DEMANGLE (sp);
- return (uintptr_t) sp;
+ return (uintptr_t) regs[0].__sp;
}
#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
diff --git a/sysdeps/mips/jmpbuf-unwind.h b/sysdeps/mips/jmpbuf-unwind.h
index c213c0a97f6..039cad5de80 100644
--- a/sysdeps/mips/jmpbuf-unwind.h
+++ b/sysdeps/mips/jmpbuf-unwind.h
@@ -19,7 +19,6 @@
#include <stdint.h>
#include <unwind.h>
#include <sysdep.h>
-#include <pointer_guard.h>
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
@@ -31,12 +30,12 @@
(void *) (_Unwind_Ptr) _Unwind_GetCFA (_context), \
_adj)
+/* setjmp does not mangle the stack pointer on this ABI, so the saved
+ value is used as-is. */
static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf regs)
{
- uintptr_t sp = (uintptr_t) regs[0].__sp;
- PTR_DEMANGLE (sp);
- return sp;
+ return (uintptr_t) regs[0].__sp;
}
#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
diff --git a/sysdeps/riscv/jmpbuf-unwind.h b/sysdeps/riscv/jmpbuf-unwind.h
index 1a4de568d2a..9676723b57a 100644
--- a/sysdeps/riscv/jmpbuf-unwind.h
+++ b/sysdeps/riscv/jmpbuf-unwind.h
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <unwind.h>
#include <sysdep.h>
-#include <pointer_guard.h>
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
@@ -30,12 +29,12 @@
#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
_JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+/* setjmp does not mangle the stack pointer on this ABI, so the saved
+ value is used as-is. */
static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf regs)
{
- uintptr_t sp = regs[0].__sp;
- PTR_DEMANGLE (sp);
- return sp;
+ return regs[0].__sp;
}
#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
--
2.43.0
More information about the Libc-alpha
mailing list