Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261028051501.2973694-1-khem.raj@oss.qualcomm.com>
Date: Tue, 27 Oct 2026 22:15:01 -0700
From: Khem Raj <raj.khem@...il.com>
To: musl@...ts.openwall.com
Cc: Khem Raj <khem.raj@....qualcomm.com>
Subject: [PATCH] configure: use -ffp-exception-behavior=maytrap when supported

The math library relies on floating point exception flags being raised
exactly as the C code would raise them. GCC keeps that by default
(-ftrapping-math), but clang assumes floating point exceptions are never
inspected unless told otherwise, and may then evaluate both paths of a
branch and select the result.

Building with clang 23 for aarch64, expm1()
computes both y*2.0*0x1p1023 and y*twopk for the k < 0 || k > 56 case
and picks one with fcsel, so the unused multiply raises a spurious
OVERFLOW. libc-test's math/expm1, expm1f, hypot, hypotf and sinh fail
because of that.

-ffp-exception-behavior=maytrap tells clang to avoid transformations
that raise exceptions the original code would not raise. GCC does not
accept the option, so tryflag leaves GCC builds unchanged.
---
 configure | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/configure b/configure
index 81a7315a..50edc969 100755
--- a/configure
+++ b/configure
@@ -355,6 +355,16 @@ tryflag CFLAGS_C99FSE -fexcess-precision=standard \
 || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
 tryflag CFLAGS_C99FSE -frounding-math
 
+#
+# The math library relies on floating point exception flags being
+# raised exactly as the C code would raise them. GCC does not move
+# floating point operations that may trap across branches by default
+# (-ftrapping-math), but clang assumes exceptions are never inspected
+# unless told otherwise, and may then evaluate both sides of a branch,
+# raising spurious exceptions (e.g. OVERFLOW from expm1, hypot, sinh).
+#
+tryflag CFLAGS_C99FSE -ffp-exception-behavior=maytrap
+
 #
 # Semantically we want to insist that our sources follow the
 # C rules for type-based aliasing, but most if not all real-world

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.