[1/3] setjmp: fix x86-64 longjmp argument adjustment

Submitted by Szabolcs Nagy on Aug. 12, 2020, 9:44 p.m.

Details

Message ID 20200812214405.GE879655@port70.net
State New
Series "Series without cover letter"
Headers show

Commit Message

Szabolcs Nagy Aug. 12, 2020, 9:44 p.m.
* Alexander Monakov <amonakov@ispras.ru> [2020-08-12 16:29:59 +0300]:
> By the way, you should check if other 64-bit ports in musl exhibit
> the same issue. The AArch64 port definitely does, for example.
> 
> Here's a standalone testcase, needs -O2 so test_lj passes its second
> argument unchanged:

yes it seems wrong, see attached patch (with that the test passes).
thanks.

> 
> #include <setjmp.h>
> 
> static void test_lj(jmp_buf jb, long lv)
> {
>         longjmp(jb, lv);
> }
> 
> int main()
> {
>         void (*volatile ptest)(jmp_buf, long) = 0;
>         jmp_buf jb;
> 
>         int v = setjmp(jb);
>         ptest = ptest ? 0 : test_lj;
>         if (ptest) ptest(jb, 1l<<32);
>         return !v;
> }
> 
> 
> Alexander

Patch hide | download patch | download mbox

From c1b4a33e7cb1f4df0cc5f8237930ff81786cfbde Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Wed, 12 Aug 2020 21:00:26 +0000
Subject: [PATCH] aarch64: fix setjmp return value

longjmp should set the return value of setjmp, but 64bit
registers were used for the 0 check while the type is int.

use the code that gcc generates for return val ? val : 1;
---
 src/setjmp/aarch64/longjmp.s | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/setjmp/aarch64/longjmp.s b/src/setjmp/aarch64/longjmp.s
index 7c4655fa..b22042a2 100644
--- a/src/setjmp/aarch64/longjmp.s
+++ b/src/setjmp/aarch64/longjmp.s
@@ -18,7 +18,6 @@  longjmp:
 	ldp d12, d13, [x0,#144]
 	ldp d14, d15, [x0,#160]
 
-	mov x0, x1
-	cbnz x1, 1f
-	mov x0, #1
+	cmp w1, 0
+	csinc w0, w1, wzr, ne
 1:	br x30
-- 
2.28.0