From patchwork Mon Oct 23 21:36:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 737303 Delivered-To: patch@linaro.org Received: by 2002:adf:dd81:0:b0:32d:baff:b0ca with SMTP id x1csp1735544wrl; Mon, 23 Oct 2023 14:37:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7z+b4eLRTGyv1vRQFgOWPC399506qRTcTBcTIptOGzNk8J+kGow7oAS67rfho936BoDIO X-Received: by 2002:a05:6808:2ca:b0:3af:585:400b with SMTP id a10-20020a05680802ca00b003af0585400bmr10656177oid.58.1698097034985; Mon, 23 Oct 2023 14:37:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698097034; cv=pass; d=google.com; s=arc-20160816; b=G+x7HSLvPl7KvD9+7NXJ4BXpxpjyvnSCueSstOkwzuzbz3ArLZQknlSeDJ/25CfkcQ qOURLjdf9PTs7HL1DCTxJweUVNH7OWUXHfb7/4WLmOAlizumAcoIT2dUpvVhqdqt/xOf v70ArcjQuCEc8yPVPx9ih9BpTwGXgMS7DZp2UJzKymmyLLqD1vlRUo83THE/Nvd+NPu4 es66Wo2qvMj+7/OUb+f/Hg+ViabvWGd+SN75Flcby1AWiccpj1+QtB135DDSZQeQzy57 HVxQk5ouJ+W9GElxRV5FpZgIJiHfEgUqFnX+qbOQzD+ZgDKE4cLzZgo5PKvufZIPVu3r 18TA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; fh=Rk9vnpDApgYog/EhmGDFyutcQpHXbdLZmc0l8HNU7lw=; b=Sx3QEzT/G05ABtykniwK7YN/dXF4TlHpvyjUtBBGOrnlb8vNA5MzS1RWhi4PljZ4dE TN5aNuZkVZQPK1huYWmtDKpt0k2UANAZ8+t1VEEbwFR38GqBAmyXmKubtuL2Lz76ATvx gFx5QY2woC8bjRUJq83lEipP9SMQxjdJiZiz2PzaiE9RVFFdLLJCNg6uQUAVrdF8qd28 qqwbFXiFMGF2Kf1xr4VGwdd8yj7t5gNwuZ5DWeWTeZRDAAd1aIl777o0Wyi2MQBCatSE GX81h3xCxEvTsLYMyYNibuq2hTbyhvR7fcIrVP9wSUJRwcGH/xi1pzsg767MAsdzbvQl nydw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x87WUIAd; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id if12-20020a0562141c4c00b0066cee07e205si6538990qvb.175.2023.10.23.14.37.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:37:14 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x87WUIAd; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A25E2385802F for ; Mon, 23 Oct 2023 21:37:14 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 03E083858C2C for ; Mon, 23 Oct 2023 21:37:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03E083858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 03E083858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698097028; cv=none; b=sM63r0TmI7hP25ti2bGec/eO8EXab9zXoK4DM/bnUlQMZF3leS1xMILWvWXPP6SAVTCZCL2JEj5/++yGDwow6vst/KG7I+gohoVrftIE7iEvav67Gu6D/9mZQHcNJ4mbUols8Er+Q2SmtqKEZ1b5uWB/axK3NkxWYyrZ8YN09gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698097028; c=relaxed/simple; bh=BoHvN498rhA/tBAAwfSg43+0rL0NtgPiLxrEzE2+mgk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=iEmYQZP3mOxzsHCtkYDW7TNx5UCTh1Z63coF2UBPf0ZYIxu9AErmxBjkYykrhL9vd8+ekEe/ARxfMmitZjEYZCOKXOtUknYt/zUe78J4ZZJUZA1O9gLhCxnkrl8hWdroFpUWV6lmdVsaAMcaNtmpMK2kUIl/pMFXDvmnEME23rU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6b7f0170d7bso3617342b3a.2 for ; Mon, 23 Oct 2023 14:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698097025; x=1698701825; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=x87WUIAdu3j9yu5UBOOW+mk1ZMGRe2zggm81AsQqD6aUeIRZLQ7dHicDIevxKzbhu6 ZwyM9CiK/UMJgj9zQwfQPzJxoZVXhlQDFHUu2suoQMx6NuVD3yAp3fTRck6hlFLNl/zo aiFCFjRx+Fo171kAVnVFTF4EhV8YbdGsuEd1BLjnubZwQmRtFPSVr0hyS3wNbaDdNhyq 43H++piDWKtqRHgKxTLipbXIe6FGexmQfMy6LrNtqTdrv3VY5utm+LGGXe5oUO0aZ8mY msiWcwZXuxN2Zi+99iUGdmh7+ZlWS2s4tGNg9oEznf6glOzSmrQhf1EHrUWVBue+R+UW x4fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698097025; x=1698701825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=IfGxjv32ydi9ZVIHQR+79ju2+RTWrdslyDJtbP9cJOdvMaSTKfJfJ8SfUgU7SZ4Obo foSlEwaR7lo4m5MPOF5hqIEK93H9wsMf68WSl2BbSyqpcsCVnrpnvPMVLgAezBHm12s3 brG+ALVNHcivqyYrE/+FxW/A0u8D2Q1OXiRtTKa0ZEjOwEzL/FMEXhBERttsOmRuZvOf fQfc8BVdaa0J6my/ExA8lOx3Gl3geJkBIi3Q2Ud9SAIHdSo61FgzmgNjJHuB3YyDe3Po VBW5bUPIEx2dcU9Q98JXTDnKEDrIhTlb/66pr527CUhRJSUkaOAMsrQc8EtBl+KNWmdy CmEQ== X-Gm-Message-State: AOJu0YyTplnrVdJ3RwBh51ng2E25Ago7n53cVSC4LL8U/PzyXlRO86xb EYRAWiRItuzh/jhkmnfTgu/zZOUwDzXTTbukOzNd2A== X-Received: by 2002:a05:6a21:193:b0:17e:1f9a:91f5 with SMTP id le19-20020a056a21019300b0017e1f9a91f5mr1015543pzb.44.1698097025499; Mon, 23 Oct 2023 14:37:05 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:a647:232:4b54:1e33:3494]) by smtp.gmail.com with ESMTPSA id fe12-20020a056a002f0c00b0066a4e561beesm6819443pfb.173.2023.10.23.14.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:37:04 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Bruno Haible Subject: [PATCH 1/3] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) Date: Mon, 23 Oct 2023 18:36:57 -0300 Message-Id: <20231023213659.3236496-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023213659.3236496-1-adhemerval.zanella@linaro.org> References: <20231023213659.3236496-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org According to ISO C23 (7.6.4.4), fesetexcept is supposed to set floating-point exception flags without raising a trap (unlike feraiseexcept, which is supposed to raise a trap if feenableexcept was called with the appropriate argument). This is a side-effect of how we implement the GNU extension feenableexcept, where feenableexcept/fesetenv/fesetmode/feupdateenv might issue prctl (PR_SET_FPEXC, PR_FP_EXC_PRECISE) depending of the argument. And on PR_FP_EXC_PRECISE, setting a floating-point exception flag triggers a trap. To make the both functions follow the C23, fesetexcept and fesetexceptflag now fail if the argument may trigger a trap. The math tests now check for an value different than 0, instead of bail out as unsupported for EXCEPTION_SET_FORCES_TRAP. Checked on powerpc64le-linux-gnu. --- math/test-fesetexcept-traps.c | 11 ++++------- math/test-fexcept-traps.c | 11 ++++------- sysdeps/powerpc/fpu/fesetexcept.c | 5 +++++ sysdeps/powerpc/fpu/fsetexcptflg.c | 9 ++++++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/math/test-fesetexcept-traps.c b/math/test-fesetexcept-traps.c index 71b6e45b33..96f6c4752f 100644 --- a/math/test-fesetexcept-traps.c +++ b/math/test-fesetexcept-traps.c @@ -39,16 +39,13 @@ do_test (void) return result; } - if (EXCEPTION_SET_FORCES_TRAP) - { - puts ("setting exceptions traps, cannot test on this architecture"); - return 77; - } - /* Verify fesetexcept does not cause exception traps. */ + /* Verify fesetexcept does not cause exception traps. For architectures + where setting the exception might result in traps the function should + return a nonzero value. */ ret = fesetexcept (FE_ALL_EXCEPT); if (ret == 0) puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); - else + else if (!EXCEPTION_SET_FORCES_TRAP) { puts ("fesetexcept (FE_ALL_EXCEPT) failed"); if (EXCEPTION_TESTS (float)) diff --git a/math/test-fexcept-traps.c b/math/test-fexcept-traps.c index 9701c3c320..9b8f583ae6 100644 --- a/math/test-fexcept-traps.c +++ b/math/test-fexcept-traps.c @@ -63,14 +63,11 @@ do_test (void) result = 1; } - if (EXCEPTION_SET_FORCES_TRAP) - { - puts ("setting exceptions traps, cannot test on this architecture"); - return 77; - } - /* The test is that this does not cause exception traps. */ + /* The test is that this does not cause exception traps. For architectures + where setting the exception might result in traps the function should + return a nonzero value. */ ret = fesetexceptflag (&saved, FE_ALL_EXCEPT); - if (ret != 0) + if (ret != 0 && !EXCEPTION_SET_FORCES_TRAP) { puts ("fesetexceptflag failed"); result = 1; diff --git a/sysdeps/powerpc/fpu/fesetexcept.c b/sysdeps/powerpc/fpu/fesetexcept.c index 609a148a95..2850156d3a 100644 --- a/sysdeps/powerpc/fpu/fesetexcept.c +++ b/sysdeps/powerpc/fpu/fesetexcept.c @@ -31,6 +31,11 @@ fesetexcept (int excepts) & FE_INVALID_SOFTWARE)); if (n.l != u.l) { + if (n.l & fenv_exceptions_to_reg (excepts)) + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 + does not allow it. */ + return -1; + fesetenv_register (n.fenv); /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ diff --git a/sysdeps/powerpc/fpu/fsetexcptflg.c b/sysdeps/powerpc/fpu/fsetexcptflg.c index 2b22f913c0..6517e8ea03 100644 --- a/sysdeps/powerpc/fpu/fsetexcptflg.c +++ b/sysdeps/powerpc/fpu/fsetexcptflg.c @@ -44,7 +44,14 @@ __fesetexceptflag (const fexcept_t *flagp, int excepts) This may cause floating-point exceptions if the restored state requests it. */ if (n.l != u.l) - fesetenv_register (n.fenv); + { + if (n.l & fenv_exceptions_to_reg (excepts)) + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 + does not allow it. */ + return -1; + + fesetenv_register (n.fenv); + } /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ if (flag & FE_INVALID)