glibc is currently built with -fno-math-errno. This GCC option affects more than math functions, so it leads to build (strerror resetting errno when formatting an unknown error number is one known instance). We should backport this upstream commit: commit 2ef427168818ce04b03cecb7b739f9db0156e3e4 Author: Aurelien Jarno <aurelien> Date: Thu Jan 3 15:51:37 2019 +0100 Only build libm with -fno-math-errno (bug 24024) 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.
Verified with ./string/test-strerror-errno glibc test
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2019:3513