Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [day] [month] [year] [list]
Date: Sun, 9 Feb 2020 12:02:01 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Excess precision hell

Recent finds in GCC bug tracker and experimentation with GCC and clang
have me rather concerned about the safety of code built for i386. Some
background references:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85957
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

At one point I'd almost thought we should remove -ffloat-store as a
fallback for -fexcess-precision=standard on old GCCs, but it turns out
that's a really bad idea. GCC (perhaps wrongly? this isn't clear from
psABI) assumes that function call results don't have excess precision,
so generating a libc.a/libc.so where they can return excess precision
is dangerous (lies to the optimizer, leading to things like 85957
above). Using -ffloat-store produces results that are numerically
wrong (not to mention slow), but at least consistent and
deterministic.

Unfortunately clang does not support either -ffloat-store or
-fexcess-precision=standard, so **all** versions of musl build for
i386 by clang are seriously broken in this regard. The only way I've
found to make clang drop excess precision is by casting/coercing (by
return statement) down from long double to double or float. (And note
that a simple gratuitous cast up/down doesn't help; there actually
needs to be a floating point operation that's been evaluated in the
higher precision.)

So, our code that's using float_t/double_t internally is presumably
clang-safe, but there's a lot that's not doing that yet -- single
precision hyperbolic functions and special functions, all complex
math, maybe other things too.

We probably should deprecate or disallow building of i386 musl with
clang (unless -march is such that sse2 math is available and can be
used, in which case there's no excess precision and everything is
fine) unless/until everything is converted to use of float_t/double_t,
or conditional on a test for a fix in clang. (For example we could
write a configure test that disallows use of clang if x+y generates
fadd but not fst[p]l in the asm.) Does this sound reasonable?

One thing I just found, but I don't know if it's reliable: it seems
clang's -O0 gives the equivalent of -ffloat-store. So perhaps we could
just force -O0 (just for src/math and src/complex?) if clang is
detected as having this bug.

Rich

Powered by blists - more mailing lists

Your e-mail address:

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