diff mbox series

Only build libm with -fno-math-errno

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

Commit Message

Aurelien Jarno Dec. 22, 2018, 5:16 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 function. This allows GCC to optimize-out saving and
restoring errno around function calls. In turn this causes strerror to
set errno value to ENOMEM in case of an invalid error number and memory
allocation error, which 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.

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(-)

Comments

Zack Weinberg Dec. 22, 2018, 7:37 p.m. UTC | #1
On Sat, Dec 22, 2018 at 12:16 PM Aurelien Jarno <aurelien@aurel32.net> wrote:
>
> 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 function. This allows GCC to optimize-out saving and
> restoring errno around function calls. In turn this causes strerror to
> set errno value to ENOMEM in case of an invalid error number and memory
> allocation error, which is not allowed by POSIX.

LGTM, except please mention GCC bug #88576 in the commit message.
Hopefully we'll be able to turn -fno-math-errno back on for libc when
that's fixed.

zw
Aurelien Jarno Dec. 22, 2018, 8:24 p.m. UTC | #2
On 2018-12-22 14:37, Zack Weinberg wrote:
> On Sat, Dec 22, 2018 at 12:16 PM Aurelien Jarno <aurelien@aurel32.net> wrote:
> >
> > 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 function. This allows GCC to optimize-out saving and
> > restoring errno around function calls. In turn this causes strerror to
> > set errno value to ENOMEM in case of an invalid error number and memory
> > allocation error, which is not allowed by POSIX.
> 
> LGTM, except please mention GCC bug #88576 in the commit message.
> Hopefully we'll be able to turn -fno-math-errno back on for libc when
> that's fixed.

Thanks for the review. Now that we know it's a GCC bug, the commit
message clearly needs to be reworked.
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),)