Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <c1d4fffc-32a0-4b49-9fda-0592bde76d64@app.fastmail.com>
Date: Sat, 16 Aug 2025 19:37:35 +0200
From: Alex Rønne Petersen <alex@...xrp.com>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] configure: prevent gcc and clang from performing floating point
 contraction

On Fri, May 30, 2025, at 00:42, Alex Rønne Petersen wrote:
> The default setting for -ffp-contract is implementation-defined, so make
> -ffp-contract=off explicit. This matters on clang in particular where
> contraction is on by default even in standard C mode. Because of this, clang
> will turn these expressions into llvm.fmuladd.* intrinsic calls in the
> generated LLVM IR. This means we're completely at the mercy of the backend in
> regards to whether those intrinsics get lowered to an fma() call or simply
> fmul + fadd instructions. Similarly, optimization passes are allowed to perform
> transformations on those intrinsic calls that fmul + fadd would not permit.
>
> Older gcc versions had a similar issue and required -mno-fused-madd, hence set
> this as well.
>
> With zig cc -target arm-linux-musleabi, we've seen a case where clang turned
> a * b + c into an fma() library call in musl's fma() implementation itself,
> resulting in infinite recursion. This patch also fixes that.
> ---
>  configure | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/configure b/configure
> index bc9fbe48..aa890101 100755
> --- a/configure
> +++ b/configure
> @@ -355,6 +355,15 @@ tryflag CFLAGS_C99FSE -fexcess-precision=standard \
>  || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
>  tryflag CFLAGS_C99FSE -frounding-math
> 
> +#
> +# Explicitly disable floating point contraction because the default
> +# setting is implementation-defined, and clang is known to have it
> +# on by default even in standard C mode. The same was true in older
> +# gcc versions, hence -mno-fused-add as well.
> +#
> +tryflag CFLAGS_C99FSE -mno-fused-madd
> +tryflag CFLAGS_C99FSE -ffp-contract=off
> +
>  #
>  # Semantically we want to insist that our sources follow the
>  # C rules for type-based aliasing, but most if not all real-world
> -- 
> 2.48.1

Friendly ping.

Regards,
Alex

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.