[klibc] [PATCH] fix trashing of callee-saved registers in thumb setjmp()

Thorsten Glaser tg at mirbsd.org
Sat Sep 29 12:20:37 PDT 2012


fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634890
(although dynamically-linked binaries seem to have another bug)

Signed-off-by: Thorsten Glaser <tg at mirbsd.org>
---
 usr/klibc/arch/arm/setjmp.S |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/usr/klibc/arch/arm/setjmp.S b/usr/klibc/arch/arm/setjmp.S
index d351e0e..92ffc43 100644
--- a/usr/klibc/arch/arm/setjmp.S
+++ b/usr/klibc/arch/arm/setjmp.S
@@ -70,6 +70,7 @@ longjmp:
 	.type setjmp, #function
 	.thumb_func
 setjmp:
+	mov	r2, r0
 	mov	r3, lr
 	stmia	r0!, {r3, r4, r5, r6, r7}
 	mov	r3, r8
@@ -78,6 +79,8 @@ setjmp:
 	mov	r6, fp
 	mov	r7, sp
 	stmia	r0!, {r3, r4, r5, r6, r7}
+	/* Do not trash r4 .. r7 */
+	ldmia	r2!, {r3, r4, r5, r6, r7}
 	mov	r0, #0
 	BX(lr)
 	.size setjmp,.-setjmp
-- 
1.7.10.4



More information about the klibc mailing list