[5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Message ID 20200804222224.3061225-6-keithp@keithp.com
State New
Headers show
Series
  • errno changes for libm
Related show

Commit Message

Eshan dhawan via Newlib Aug. 4, 2020, 10:22 p.m.
This removes the run-time configuration of errno support present in
portions of the math library and unifies all of the compile-time errno
configuration under a single parameter so that the whole library
is consistent.

The run-time support provided by _LIB_VERSION is no longer present in
the public API, although it is still used internally to disable errno
setting in some functions. Now that it is a constant, the compiler should
remove that code when errno is not supported.

This removes s_lib_ver.c as _LIB_VERSION is no longer variable.

Signed-off-by: Keith Packard <keithp@keithp.com>

---
 newlib/libc/include/math.h       | 16 ---------------
 newlib/libm/common/Makefile.am   |  2 +-
 newlib/libm/common/Makefile.in   | 11 ++--------
 newlib/libm/common/fdlibm.h      |  1 +
 newlib/libm/common/math_config.h |  5 +++++
 newlib/libm/common/s_lib_ver.c   | 35 --------------------------------
 6 files changed, 9 insertions(+), 61 deletions(-)
 delete mode 100644 newlib/libm/common/s_lib_ver.c

-- 
2.28.0

Comments

Eshan dhawan via Newlib Aug. 5, 2020, 7:41 a.m. | #1
On Aug  4 15:22, Keith Packard via Newlib wrote:
> This removes the run-time configuration of errno support present in

> portions of the math library and unifies all of the compile-time errno

> configuration under a single parameter so that the whole library

> is consistent.

> 

> The run-time support provided by _LIB_VERSION is no longer present in

> the public API, although it is still used internally to disable errno

> setting in some functions. Now that it is a constant, the compiler should

> remove that code when errno is not supported.

> 

> This removes s_lib_ver.c as _LIB_VERSION is no longer variable.


This math stuff is a bit over my head.  IIUC, the default is
NOT setting _IEEE_LIBM, which results in the defauklt behaviour
today.  That's what I care most about: Not introducing backward
incompatible settings into Cygwin.


Corinna

> 

> Signed-off-by: Keith Packard <keithp@keithp.com>

> ---

>  newlib/libc/include/math.h       | 16 ---------------

>  newlib/libm/common/Makefile.am   |  2 +-

>  newlib/libm/common/Makefile.in   | 11 ++--------

>  newlib/libm/common/fdlibm.h      |  1 +

>  newlib/libm/common/math_config.h |  5 +++++

>  newlib/libm/common/s_lib_ver.c   | 35 --------------------------------

>  6 files changed, 9 insertions(+), 61 deletions(-)

>  delete mode 100644 newlib/libm/common/s_lib_ver.c

> 

> diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h

> index 9fd82d9fa..5e6155cc4 100644

> --- a/newlib/libc/include/math.h

> +++ b/newlib/libc/include/math.h

> @@ -612,22 +612,6 @@ extern int *__signgam (void);

>  #define M_LOG2_E        _M_LN2

>  #define M_INVLN2        1.4426950408889633870E0  /* 1 / log(2) */

>  

> -/* Global control over fdlibm error handling.  */

> -

> -enum __fdlibm_version

> -{

> -  __fdlibm_ieee = -1,

> -  __fdlibm_posix

> -};

> -

> -#define _LIB_VERSION_TYPE enum __fdlibm_version

> -#define _LIB_VERSION __fdlib_version

> -

> -extern __IMPORT _LIB_VERSION_TYPE _LIB_VERSION;

> -

> -#define _IEEE_  __fdlibm_ieee

> -#define _POSIX_ __fdlibm_posix

> -

>  #endif /* __BSD_VISIBLE */

>  

>  _END_STD_C

> diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am

> index 1eef0236a..1d178da4d 100644

> --- a/newlib/libm/common/Makefile.am

> +++ b/newlib/libm/common/Makefile.am

> @@ -8,7 +8,7 @@ src = 	s_finite.c s_copysign.c s_modf.c s_scalbn.c \

>  	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \

>  	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \

>  	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \

> -	s_rint.c s_logb.c s_log2.c s_lib_ver.c \

> +	s_rint.c s_logb.c s_log2.c \

>  	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \

>  	s_lrint.c s_llrint.c \

>  	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \

> diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in

> index 2caf7dd6c..b1098565f 100644

> --- a/newlib/libm/common/Makefile.in

> +++ b/newlib/libm/common/Makefile.in

> @@ -85,7 +85,6 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \

>  	lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \

>  	lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \

>  	lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \

> -	lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \

>  	lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \

>  	lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \

>  	lib_a-s_lrint.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \

> @@ -163,7 +162,7 @@ am__objects_5 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \

>  	s_cbrt.lo s_exp10.lo s_expm1.lo s_ilogb.lo s_infinity.lo \

>  	s_isinf.lo s_isinfd.lo s_isnan.lo s_isnand.lo s_log1p.lo \

>  	s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo s_logb.lo \

> -	s_log2.lo s_lib_ver.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \

> +	s_log2.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \

>  	s_fpclassify.lo s_lrint.lo s_llrint.lo s_lround.lo \

>  	s_llround.lo s_nearbyint.lo s_remquo.lo s_round.lo \

>  	s_scalbln.lo s_signbit.lo s_trunc.lo exp.lo exp2.lo \

> @@ -354,7 +353,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \

>  	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \

>  	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \

>  	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \

> -	s_rint.c s_logb.c s_log2.c s_lib_ver.c \

> +	s_rint.c s_logb.c s_log2.c \

>  	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \

>  	s_lrint.c s_llrint.c \

>  	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \

> @@ -602,12 +601,6 @@ lib_a-s_log2.o: s_log2.c

>  lib_a-s_log2.obj: s_log2.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.obj `if test -f 's_log2.c'; then $(CYGPATH_W) 's_log2.c'; else $(CYGPATH_W) '$(srcdir)/s_log2.c'; fi`

>  

> -lib_a-s_lib_ver.o: s_lib_ver.c

> -	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.o `test -f 's_lib_ver.c' || echo '$(srcdir)/'`s_lib_ver.c

> -

> -lib_a-s_lib_ver.obj: s_lib_ver.c

> -	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.obj `if test -f 's_lib_ver.c'; then $(CYGPATH_W) 's_lib_ver.c'; else $(CYGPATH_W) '$(srcdir)/s_lib_ver.c'; fi`

> -

>  lib_a-s_fdim.o: s_fdim.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fdim.o `test -f 's_fdim.c' || echo '$(srcdir)/'`s_fdim.c

>  

> diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h

> index 8dfff243d..8dffc832d 100644

> --- a/newlib/libm/common/fdlibm.h

> +++ b/newlib/libm/common/fdlibm.h

> @@ -15,6 +15,7 @@

>  #include <math.h>

>  #include <sys/types.h>

>  #include <machine/ieeefp.h>

> +#include "math_config.h"

>  

>  /* Most routines need to check whether a float is finite, infinite, or not a

>     number, and many need to know whether the result of an operation will

> diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h

> index 3be7e6320..1089b0ec6 100644

> --- a/newlib/libm/common/math_config.h

> +++ b/newlib/libm/common/math_config.h

> @@ -38,15 +38,20 @@

>  #endif

>  #ifdef _IEEE_LIBM

>  # define WANT_ERRNO 0

> +# define _LIB_VERSION _IEEE_

>  #else

>  /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0.  */

>  # define WANT_ERRNO 1

> +# define _LIB_VERSION _POSIX_

>  #endif

>  #ifndef WANT_ERRNO_UFLOW

>  /* Set errno to ERANGE if result underflows to 0 (in all rounding modes).  */

>  # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)

>  #endif

>  

> +#define _IEEE_  -1

> +#define _POSIX_ 0

> +

>  /* Compiler can inline round as a single instruction.  */

>  #ifndef HAVE_FAST_ROUND

>  # if __aarch64__

> diff --git a/newlib/libm/common/s_lib_ver.c b/newlib/libm/common/s_lib_ver.c

> deleted file mode 100644

> index 8da03b79a..000000000

> --- a/newlib/libm/common/s_lib_ver.c

> +++ /dev/null

> @@ -1,35 +0,0 @@

> -

> -/* @(#)s_lib_ver.c 5.1 93/09/24 */

> -/*

> - * ====================================================

> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.

> - *

> - * Developed at SunPro, a Sun Microsystems, Inc. business.

> - * Permission to use, copy, modify, and distribute this

> - * software is freely granted, provided that this notice 

> - * is preserved.

> - * ====================================================

> - */

> -

> -/*

> - * MACRO for standards

> - */

> -

> -#include "fdlibm.h"

> -

> -/*

> - * define and initialize _LIB_VERSION

> - */

> -#ifdef _POSIX_MODE

> -_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;

> -#else

> -#ifdef _XOPEN_MODE

> -#error _XOPEN_MODE is unsupported

> -#else

> -#ifdef _SVID3_MODE

> -#error _SVID3_MODE is unsupported

> -#else					/* default _IEEE_MODE */

> -_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;

> -#endif

> -#endif

> -#endif

> -- 

> 2.28.0


-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Eshan dhawan via Newlib Aug. 5, 2020, 3:58 p.m. | #2
Corinna Vinschen via Newlib <newlib@sourceware.org> writes:

> This math stuff is a bit over my head.  IIUC, the default is

> NOT setting _IEEE_LIBM, which results in the defauklt behaviour

> today.  That's what I care most about: Not introducing backward

> incompatible settings into Cygwin.


TL;DR summary:

The only effect on Cygwin will be to enable errno reporting for the few
functions coming from libm/math.

Longer discussion:

There are a lot of inter-related standards and I feel like I'm
down the rabbit hole on a lot of this. I think this particular issue can
be understood at a fairly high level as one of identifying inconsistent
semantics across the math library and then trying to identify ways to
fix that.

The new math code (libm/common) has errno enabled unless you set
WANT_ERRNO=0 (which no included configuration does).

The old math code (libm/math) has the errno code compiled-in unless you
define _IEEE_LIBM (which no configuration does). When _IEEE_LIBM is
defined, most (but not all) of the errno-setting code is removed.
However, the errno code in libm/math is also controlled by a run-time
conditional, _LIB_VERSION, which blocks the errno behavior *unless* the
global variable _LIB_VERSION is set to _POSIX_, which is not the default
on anything other than the spu build.

So, the current Cygwin behavior has most functions always setting errno
(those from libm/common), but some functions (those from libm/math) only
setting errno if the application happens to know about _LIB_VERSION and
sets that to _POSIX_.

This patch tries to simplify things so that one single global
compile-time define, _IEEE_LIBM, controls whether errno is ever modified
by the math library, and removes the run-time behavior controlled by
_LIB_VERSION.

-- 
-keith
Eshan dhawan via Newlib Aug. 5, 2020, 8:43 p.m. | #3
Hi Keith,

On Aug  4 15:22, Keith Packard via Newlib wrote:
> This removes the run-time configuration of errno support present in

> portions of the math library and unifies all of the compile-time errno

> configuration under a single parameter so that the whole library

> is consistent.

> 

> The run-time support provided by _LIB_VERSION is no longer present in

> the public API, although it is still used internally to disable errno

> setting in some functions. Now that it is a constant, the compiler should

> remove that code when errno is not supported.

> 

> This removes s_lib_ver.c as _LIB_VERSION is no longer variable.

> 

> Signed-off-by: Keith Packard <keithp@keithp.com>

> ---

> [...]

> diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am

> index 1eef0236a..1d178da4d 100644

> --- a/newlib/libm/common/Makefile.am

> +++ b/newlib/libm/common/Makefile.am

> @@ -8,7 +8,7 @@ src = 	s_finite.c s_copysign.c s_modf.c s_scalbn.c \

>  	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \

>  	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \

>  	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \

> -	s_rint.c s_logb.c s_log2.c s_lib_ver.c \

> +	s_rint.c s_logb.c s_log2.c \

>  	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \

>  	s_lrint.c s_llrint.c \

>  	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \

> diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in

> index 2caf7dd6c..b1098565f 100644

> --- a/newlib/libm/common/Makefile.in

> +++ b/newlib/libm/common/Makefile.in

> @@ -85,7 +85,6 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \

>  	lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \

>  	lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \

>  	lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \

> -	lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \


This accidentally removes lib_a-s_fdim.o, so building Cygwin fails.
Not much of a problem, though.  I pushed the series with regen'ed
newlib/libm/common/Makefile.in file.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Eshan dhawan via Newlib Aug. 5, 2020, 9:13 p.m. | #4
Corinna Vinschen via Newlib <newlib@sourceware.org> writes:

> This accidentally removes lib_a-s_fdim.o, so building Cygwin fails.

> Not much of a problem, though.  I pushed the series with regen'ed

> newlib/libm/common/Makefile.in file.


Thanks, I cannot generate the Makefile.in files so I edit them by hand.

-- 
-keith

Patch

diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index 9fd82d9fa..5e6155cc4 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -612,22 +612,6 @@  extern int *__signgam (void);
 #define M_LOG2_E        _M_LN2
 #define M_INVLN2        1.4426950408889633870E0  /* 1 / log(2) */
 
-/* Global control over fdlibm error handling.  */
-
-enum __fdlibm_version
-{
-  __fdlibm_ieee = -1,
-  __fdlibm_posix
-};
-
-#define _LIB_VERSION_TYPE enum __fdlibm_version
-#define _LIB_VERSION __fdlib_version
-
-extern __IMPORT _LIB_VERSION_TYPE _LIB_VERSION;
-
-#define _IEEE_  __fdlibm_ieee
-#define _POSIX_ __fdlibm_posix
-
 #endif /* __BSD_VISIBLE */
 
 _END_STD_C
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
index 1eef0236a..1d178da4d 100644
--- a/newlib/libm/common/Makefile.am
+++ b/newlib/libm/common/Makefile.am
@@ -8,7 +8,7 @@  src = 	s_finite.c s_copysign.c s_modf.c s_scalbn.c \
 	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
 	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
 	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
-	s_rint.c s_logb.c s_log2.c s_lib_ver.c \
+	s_rint.c s_logb.c s_log2.c \
 	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
 	s_lrint.c s_llrint.c \
 	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in
index 2caf7dd6c..b1098565f 100644
--- a/newlib/libm/common/Makefile.in
+++ b/newlib/libm/common/Makefile.in
@@ -85,7 +85,6 @@  am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
 	lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \
 	lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \
 	lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \
-	lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
 	lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
 	lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
 	lib_a-s_lrint.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
@@ -163,7 +162,7 @@  am__objects_5 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \
 	s_cbrt.lo s_exp10.lo s_expm1.lo s_ilogb.lo s_infinity.lo \
 	s_isinf.lo s_isinfd.lo s_isnan.lo s_isnand.lo s_log1p.lo \
 	s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo s_logb.lo \
-	s_log2.lo s_lib_ver.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
+	s_log2.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
 	s_fpclassify.lo s_lrint.lo s_llrint.lo s_lround.lo \
 	s_llround.lo s_nearbyint.lo s_remquo.lo s_round.lo \
 	s_scalbln.lo s_signbit.lo s_trunc.lo exp.lo exp2.lo \
@@ -354,7 +353,7 @@  src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
 	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
 	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
 	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
-	s_rint.c s_logb.c s_log2.c s_lib_ver.c \
+	s_rint.c s_logb.c s_log2.c \
 	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
 	s_lrint.c s_llrint.c \
 	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
@@ -602,12 +601,6 @@  lib_a-s_log2.o: s_log2.c
 lib_a-s_log2.obj: s_log2.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.obj `if test -f 's_log2.c'; then $(CYGPATH_W) 's_log2.c'; else $(CYGPATH_W) '$(srcdir)/s_log2.c'; fi`
 
-lib_a-s_lib_ver.o: s_lib_ver.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.o `test -f 's_lib_ver.c' || echo '$(srcdir)/'`s_lib_ver.c
-
-lib_a-s_lib_ver.obj: s_lib_ver.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.obj `if test -f 's_lib_ver.c'; then $(CYGPATH_W) 's_lib_ver.c'; else $(CYGPATH_W) '$(srcdir)/s_lib_ver.c'; fi`
-
 lib_a-s_fdim.o: s_fdim.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fdim.o `test -f 's_fdim.c' || echo '$(srcdir)/'`s_fdim.c
 
diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
index 8dfff243d..8dffc832d 100644
--- a/newlib/libm/common/fdlibm.h
+++ b/newlib/libm/common/fdlibm.h
@@ -15,6 +15,7 @@ 
 #include <math.h>
 #include <sys/types.h>
 #include <machine/ieeefp.h>
+#include "math_config.h"
 
 /* Most routines need to check whether a float is finite, infinite, or not a
    number, and many need to know whether the result of an operation will
diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h
index 3be7e6320..1089b0ec6 100644
--- a/newlib/libm/common/math_config.h
+++ b/newlib/libm/common/math_config.h
@@ -38,15 +38,20 @@ 
 #endif
 #ifdef _IEEE_LIBM
 # define WANT_ERRNO 0
+# define _LIB_VERSION _IEEE_
 #else
 /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0.  */
 # define WANT_ERRNO 1
+# define _LIB_VERSION _POSIX_
 #endif
 #ifndef WANT_ERRNO_UFLOW
 /* Set errno to ERANGE if result underflows to 0 (in all rounding modes).  */
 # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
 #endif
 
+#define _IEEE_  -1
+#define _POSIX_ 0
+
 /* Compiler can inline round as a single instruction.  */
 #ifndef HAVE_FAST_ROUND
 # if __aarch64__
diff --git a/newlib/libm/common/s_lib_ver.c b/newlib/libm/common/s_lib_ver.c
deleted file mode 100644
index 8da03b79a..000000000
--- a/newlib/libm/common/s_lib_ver.c
+++ /dev/null
@@ -1,35 +0,0 @@ 
-
-/* @(#)s_lib_ver.c 5.1 93/09/24 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/*
- * MACRO for standards
- */
-
-#include "fdlibm.h"
-
-/*
- * define and initialize _LIB_VERSION
- */
-#ifdef _POSIX_MODE
-_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
-#else
-#ifdef _XOPEN_MODE
-#error _XOPEN_MODE is unsupported
-#else
-#ifdef _SVID3_MODE
-#error _SVID3_MODE is unsupported
-#else					/* default _IEEE_MODE */
-_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
-#endif
-#endif
-#endif