![]() |
|
Message-ID: <20250529224200.921426-1-alex@alexrp.com> Date: Fri, 30 May 2025 00:42:00 +0200 From: Alex Rønne Petersen <alex@...xrp.com> To: musl@...ts.openwall.com Cc: Alex Rønne Petersen <alex@...xrp.com> Subject: [PATCH] configure: prevent gcc and clang from performing floating point contraction 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
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.