Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20261028103948.GL23438@brightrain.aerifal.cx>
Date: Wed, 28 Oct 2026 06:39:48 -0400
From: Rich Felker <dalias@...c.org>
To: Khem Raj <raj.khem@...il.com>
Cc: musl@...ts.openwall.com, Khem Raj <khem.raj@....qualcomm.com>
Subject: Re: [PATCH] configure: use -ffp-exception-behavior=maytrap
 when supported

On Tue, Oct 27, 2026 at 10:15:01PM -0700, Khem Raj wrote:
> 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

If this is needed, the correct value is almost surely "strict" not
"maytrap".

But I think -ffp-model=strict would be better. It implies
-ffp-exception-behavior=strict and also fixes other things clang does
wrong by default (fma contraction).

But I wonder: is the problem just that the source file is missing
#pragma STDC FENV_ACCESS ON ? If so, that should be fixed.

Rich

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.