From nobody Sat Dec 31 19:38:25 2022 X-Original-To: riscv@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Nksqj5Xyyz2l9VW for ; Sat, 31 Dec 2022 19:38:25 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Nksqj0nMCz3mGV for ; Sat, 31 Dec 2022 19:38:25 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672515505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jiYAaEhrCXSkBc4ueSKpKB+INhja3eTwuVnO9sPd0qw=; b=AspvHtLi/6PgCcPLq6Q1MI0HFtLImav3Twfqd/FIEVA0vw5kVMIo5P7b5DNVrBdptX8VAW C92QPvDlBBeB1oGnsn0VvowqyW4w+RSJuUOmUScaObVnoWmxj0ewDkWKap2NfZrxx1Btua fBuBLcbHZJ3xq0EFQcJrs6QpeG6a5vwcS+cDqhIvxc0aEgeQK8LvYA1pSkYAi5UxeymXGv 602sw6uQdTnNRrIzR6ozsmk8+f+k5ZuYvHNpB0BLZA7pM7HGR3tD9w/zTGYElK6Mi/fkNB 1BEnGtL4KQaaxxgQ66QJ6jBin7pZxawLp9y8jn+lY5gASseQt6y9kAQbr9Dg8w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672515505; a=rsa-sha256; cv=none; b=K3HSsubOG9i93wWueeJdLyh97GjwvzgaTWUTbIu9No/kD8sx8MOIg7V9NFsW+cZ1z8F7B4 aUDQtyCpufpxCts6ye3/6SxPpD/NmWFpnZhkWTt/v/xwUWkuGZQy4BLf6iMWoXBpAll/zG RDfv2vAllkwcA0gZ2MAezaoKXDVGbHVnrhLhsiyL9BgrIT7i6F8skRp9CErqGxNWyHN6NH L6xmksBwg2hUp8u6t58ygo/z2h6WSJGvOWS+Ge91o6yGkHjfD0i6vY6BqutLlf2L/hwVP9 jnQYbuE2oiiq/gMfcXFJTsusFVgb1X5v0r4+FISmFQ4Hi97/aUITKmeUS7xMGw== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Nksqh6pjrz10PB for ; Sat, 31 Dec 2022 19:38:24 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 2BVJcOsc025135 for ; Sat, 31 Dec 2022 19:38:24 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 2BVJcOAt025134 for riscv@FreeBSD.org; Sat, 31 Dec 2022 19:38:24 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: riscv@FreeBSD.org Subject: [Bug 268684] [PATCH] riscv libc: fix longjmp with 0 value Date: Sat, 31 Dec 2022 19:38:25 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: riscv X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: alois+freebsd@aloisklink.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: riscv@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: FreeBSD on the RISC-V instruction set architecture List-Archive: https://lists.freebsd.org/archives/freebsd-riscv List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-riscv@freebsd.org X-BeenThere: freebsd-riscv@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268684 Bug ID: 268684 Summary: [PATCH] riscv libc: fix longjmp with 0 value Product: Base System Version: CURRENT Hardware: riscv OS: Any Status: New Severity: Affects Many People Priority: --- Component: riscv Assignee: riscv@FreeBSD.org Reporter: alois+freebsd@aloisklink.com Created attachment 239166 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D239166&action= =3Dedit `git format-patch` patch file On RISC-V, calling `longjmp(x, 0);` makes `setjmp(x)` return 0, which norma= lly causes an infinite loop, and is against the ISO C standard for setjmp/longj= mp.=20 Instead, using a value of 0 should make `setjmp` return 1: > The `longjmp` function cannot cause the `setjmp` macro to return the > value 0; if `val` is 0, the `setjmp` macro returns the value 1. > > _Taken from =C2=A77.13.2.1.4 of the C99 spec_ See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268521 for my simil= ar patch for arm64 libc. That patch also has a test-case that I used to test t= his RISC-V implementation. --- I think I've actually managed to beat the compiler in this patch. Both GCC and Clang do something like the following at `-Os`: ```Assembly mv a0,a1 bne a1,zero,.L2 li a0,1 .L2: ret ``` It took a while of scouring the RISC-V ISA spec (it's my first time using RISC-V assembly), but I found a method that doesn't use branching and has l= ess one less instruction! --=20 You are receiving this mail because: You are the assignee for the bug.=