diff mbox series

[v2] Only build libm with -fno-math-errno

Message ID 20181222204809.1883-1-aurelien@aurel32.net
State New
Headers show
Series [v2] Only build libm with -fno-math-errno | expand

Commit Message

Aurelien Jarno Dec. 22, 2018, 8:48 p.m. UTC
Commit 1294b1892e ("Add support for sqrt asm redirects") added the
-fno-math-errno flag to build most of the glibc in order to enable GCC
to inline math functions. Due to GCC bug #88576, saving and restoring
errno around calls to malloc are optimized-out. In turn this causes
strerror to set errno to ENOMEM if it get passed an invalid error number
and if malloc sets errno to ENOMEM (which might happen even if it
succeeds). This is not allowed by POSIX.

This patch changes the build flags, building only libm with
-fno-math-errno and all the remaining code with -fno-math-errno. This
should be safe as libm doesn't contain any code saving and restoring
errno around malloc. This patch can probably be reverted once the GCC
bug is fixed and available in stable releases.

Tested on x86-64, no regression in the testsuite.

Changelog:
	* Makeconfig: Build libm with -fno-math-errno but build the remaining
	code with -fmath-errno.
---
 ChangeLog  | 6 ++++++
 Makeconfig | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

v1 -> v2: improved the commit message with a better description of the
          issue and the GCC bug number. No code change.

Comments

Joseph Myers Dec. 31, 2018, 5:26 p.m. UTC | #1
On Sat, 22 Dec 2018, Aurelien Jarno wrote:

> v1 -> v2: improved the commit message with a better description of the
>           issue and the GCC bug number. No code change.

I think the comment, not just the commit message should explain the issue 
(i.e., that only libnldbl nonlib testsuite should logically be using 
-fmath-errno, but everything apart from libm is currently using 
-fmath-errno because of that GCC bug).

(I would say that the comment should give the GCC version in which the bug 
is fixed to make it obvious when we can change the code back, but that 
doesn't work when the GCC bug isn't yet fixed.)

Could you add a testcase to the testsuite (that appropriately interposes 
malloc to demonstrate the bug as in the one attached to the bug, thus 
failing before the Makeconfig fix and passing after it)?
diff mbox series

Patch

diff --git a/ChangeLog b/ChangeLog
index 881808dead..a64ce96bea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-12-22  Aurelien Jarno  <aurelien@aurel32.net>
+
+	[BZ #24024]
+	* Makeconfig: Build libm with -fno-math-errno but build the remaining
+	code with -fmath-errno.
+
 2018-12-21  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #24023]
diff --git a/Makeconfig b/Makeconfig
index fbcf69e7c2..debdd3b357 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -831,8 +831,8 @@  endif
 # disable any optimization that assume default rounding mode.
 +math-flags = -frounding-math
 
-# Build libc/libm using -fno-math-errno, but run testsuite with -fmath-errno.
-+extra-math-flags = $(if $(filter libnldbl nonlib testsuite,$(in-module)),-fmath-errno,-fno-math-errno)
+# Build libm using -fno-math-errno
++extra-math-flags = $(if $(filter libm,$(in-module)),-fno-math-errno,-fmath-errno)
 
 # We might want to compile with some stack-protection flag.
 ifneq ($(stack-protector),)