[PATCH] LoongArch: Add LA32 pointer guard support
魏祎晗
aqwyh@buaa.edu.cn
Sat Aug 22 19:48:44 GMT 2026
From f493e834ec4affef287e0e7352426f11fec83bc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=AD=8F=E7=A5=8E=E6=99=97?= <aqwyh@buaa.edu.cn>
Date: Sun, 23 Aug 2026 03:40:42 +0800
Subject: [PATCH] LoongArch: Add LA32 pointer guard support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The pointer guard assembly only implemented the 64-bit path using rotri.d. LA32 lacks rotri.w, so implement the 32-bit branch using srli.w/slli.w/or to perform the rotation.
Signed-off-by: 魏祎晗 <aqwyh@buaa.edu.cn>
---
.../unix/sysv/linux/loongarch/pointer_guard-asm.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sysdeps/unix/sysv/linux/loongarch/pointer_guard-asm.h b/sysdeps/unix/sysv/linux/loongarch/pointer_guard-asm.h
index 24e27e4092..8fe71b5aee 100644
--- a/sysdeps/unix/sysv/linux/loongarch/pointer_guard-asm.h
+++ b/sysdeps/unix/sysv/linux/loongarch/pointer_guard-asm.h
@@ -36,12 +36,25 @@
PTR_MANGLE_LOAD (guard); \
PTR_DEMANGLE2 (dst, src, guard);
/* Use PTR_MANGLE2 for efficiency if guard is already loaded. */
+# if __loongarch_grlen == 64
# define PTR_MANGLE2(dst, src, guard) \
xor dst, src, guard; \
rotri.d dst, dst, 47;
# define PTR_DEMANGLE2(dst, src, guard) \
rotri.d src, src, 17; \
xor dst, src, guard;
+# else
+# define PTR_MANGLE2(dst, src, guard) \
+ xor dst, src, guard; \
+ srli.w t2, dst, 23; \
+ slli.w dst, dst, 9; \
+ or dst, dst, t2;
+# define PTR_DEMANGLE2(dst, src, guard) \
+ srli.w t2, src, 9; \
+ slli.w src, src, 23; \
+ or src, src, t2; \
+ xor dst, src, guard;
+# endif
#endif
#endif /* POINTER_GUARD_ASM_H */
--
2.55.0
More information about the Libc-alpha
mailing list