diff mbox series

[V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.

Message ID 20210304210135.GA32076@ibm-toto.the-meissners.org
State New
Headers show
Series [V3] Require GLIBC 2.32 for Decimal/_Float128 conversions. | expand

Commit Message

Michael Meissner March 4, 2021, 9:01 p.m. UTC
[PATCH V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.

In the patch that I applied on March 2nd, I had code to provide support for
Decimal/_Float128 conversions if the user did not use at least GLIBC 2.32.  It
did this by using __ibm128 as an intermediate type.  The trouble is __ibm128
cannot represent all of the numbers that _Float128 can, and you lose if you do
this conversion.

This patch removes this support.  The dfp-bit.c functions now call the the
__sprintfieee128 and __strtoieee128 functions to do the conversion.  If the
user does not have GLIBC, they will get a linker error that these functions do
not exist.

The float128 support functions are only built into the static libgcc, so there
isn't an issue with having references to __strtoieee128 and __sprintfieee128
with older GLIBC libraries.

As an added bonus, this patch eliminates the __sprintfkf function which
included stdio.h to get a definition for the sprintf library function.  This
allows for building cross compilers without having to have a target stdio.h
available.

I have built bootstrap compilers for power9 little endian systems with the
three different long double formats (IBM 128-bit, IEEE 128-bit, and 64-bit) and
there were no regressions from previous runs.  I have also build bootstrap
compilers on a big endian power8 and there was no regression there either.

Can I check this patch into the master branch?

libgcc/
2021-03-04  Michael Meissner  <meissner@linux.ibm.com>

	* config/rs6000/t-float128 (fp128_decstr_funcs): Delete.
	(fp128_ppc_funcs): Do not add $(fp128_decstr_funcs).
	(fp128_decstr_objs): Delete.
	* dfp-bit.h: Call __sprintfieee128 to do conversions from
	_Float128 to a Decimal type.  Call __strtoieee128 to do
	conversions from a Decimal type to _Float128.
	* config/rs6000/_sprintfkf.c: Delete file.
	* config/rs6000/_sprintfkf.h: Delete file.
	* config/rs6000/_strtokf.c: Delete file.
	* config/rs6000/_strtokf.h: Delete file.
---
 libgcc/config/rs6000/_sprintfkf.c | 58 -------------------------------
 libgcc/config/rs6000/_sprintfkf.h | 27 --------------
 libgcc/config/rs6000/_strtokf.c   | 53 ----------------------------
 libgcc/config/rs6000/_strtokf.h   | 27 --------------
 libgcc/config/rs6000/t-float128   | 13 +------
 libgcc/dfp-bit.h                  |  8 ++---
 6 files changed, 5 insertions(+), 181 deletions(-)
 delete mode 100644 libgcc/config/rs6000/_sprintfkf.c
 delete mode 100644 libgcc/config/rs6000/_sprintfkf.h
 delete mode 100644 libgcc/config/rs6000/_strtokf.c
 delete mode 100644 libgcc/config/rs6000/_strtokf.h

Comments

Michael Meissner March 10, 2021, 4:46 p.m. UTC | #1
Ping patch.

| Subject: [PATCH, V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.
| Message-ID: <20210304210135.GA32076@ibm-toto.the-meissners.org>
Matheus Castanho March 22, 2021, 5:06 p.m. UTC | #2
Ping.

Cross builds on Advance Toolchain have been broken since GCC commit
'781183595ac Add conversions between _Float128 and Decimal' [0]. We've
been waiting for this patch for a while, as I believe either this and/or
the other patch [1] in this patchset could fix the issue.

Could this patch be reviewed?

Thanks!

[0] https://github.com/advancetoolchain/advance-toolchain/issues/2017
[1] https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566314.html

--
Matheus Castanho
Segher Boessenkool March 25, 2021, 1:05 p.m. UTC | #3
Hi!

On Mon, Mar 22, 2021 at 02:06:27PM -0300, Matheus Castanho wrote:
> 
> Cross builds on Advance Toolchain have been broken since GCC commit
> '781183595ac Add conversions between _Float128 and Decimal' [0].

This is a problem in AT's build system.  See
  https://gcc.gnu.org/install/prerequisites.html
(second item):
  In order to build GCC, the C standard library and headers must be
  present [...]

You usually just provide a sysroot of an older (but new enough) install,
if you want to rebuild libc.  Sometimes that requires to build GCC again
after you installed the new libc (but usually not).  This is normal.


Segher
Segher Boessenkool March 25, 2021, 2:07 p.m. UTC | #4
Hi Mike,

On Thu, Mar 04, 2021 at 04:01:35PM -0500, Michael Meissner wrote:
> [PATCH V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.
> 
> In the patch that I applied on March 2nd, I had code to provide support for
> Decimal/_Float128 conversions if the user did not use at least GLIBC 2.32.  It
> did this by using __ibm128 as an intermediate type.  The trouble is __ibm128
> cannot represent all of the numbers that _Float128 can, and you lose if you do
> this conversion.
> 
> This patch removes this support.  The dfp-bit.c functions now call the the
> __sprintfieee128 and __strtoieee128 functions to do the conversion.  If the
> user does not have GLIBC, they will get a linker error that these functions do
> not exist.
> 
> The float128 support functions are only built into the static libgcc, so there
> isn't an issue with having references to __strtoieee128 and __sprintfieee128
> with older GLIBC libraries.

It still is a reverse dependency.

> As an added bonus, this patch eliminates the __sprintfkf function which
> included stdio.h to get a definition for the sprintf library function.  This
> allows for building cross compilers without having to have a target stdio.h
> available.

Which is required *anyway*.  See my reply to Matheus.

> --- a/libgcc/dfp-bit.h
> +++ b/libgcc/dfp-bit.h
> @@ -298,8 +298,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  #define BFP_TYPE _Float128
>  #define BFP_FMT "%.36Le"
>  #define BFP_VIA_TYPE _Float128
> -#define STR_TO_BFP __strtokf
> -#include <_strtokf.h>
> +#define STR_TO_BFP __strtoieee128
> +extern _Float128 __strtoieee128 (const char *, char **);

It is better to include a header for this.

I tried to check this against the implementation, but I cannot find that
function in glibc.  Some macro magic in the name?  Where is it?

> @@ -647,8 +647,8 @@ extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
>  
>  #elif defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
>  extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
> -#include <_sprintfkf.h>
> -#define BFP_SPRINTF __sprintfkf
> +extern int __sprintfieee128 (char *restrict, const char *restrict, ...);
> +#define BFP_SPRINTF __sprintfieee128

The GCC headers use
  typeof (sprintf) __sprintfieee128;
(well, an alias).  But you cannot, because of the dependency inversion
you have.  But independent declarations like this are the source of many
bugs :-(


Hrm.  This patch won't make things worse than they are, so, okay for
trunk.  Thanks!


Segher
diff mbox series

Patch

diff --git a/libgcc/config/rs6000/_sprintfkf.c b/libgcc/config/rs6000/_sprintfkf.c
deleted file mode 100644
index 2d624f14e25..00000000000
--- a/libgcc/config/rs6000/_sprintfkf.c
+++ /dev/null
@@ -1,58 +0,0 @@ 
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-<http://www.gnu.org/licenses/>.  */
-
-/* Conversion to IEEE 128-bit floating point from string using snprintf.  */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <soft-fp.h>
-#include <quad-float128.h>
-#include <stdio.h>
-#include <_sprintfkf.h>
-
-/* This function must be built with IBM 128-bit as long double, so that we can
-   access the strfroml function if do not have an IEEE 128-bit version, and if
-   that is not available, use sprintf.  */
-#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IBM128__)
-#error "Long double is not IBM 128-bit"
-#endif
-
-/* If the user is using GLIBC 2.32, we can use the __snprintfieee128 function.
-
-   If we are linked against an earlier library, we will have fake it by
-   converting the value to long double, and using sprintf to do the conversion.
-   This isn't ideal, as IEEE 128-bit has more exponent range than IBM
-   128-bit.  */
-
-extern int __sprintfieee128 (char *restrict, const char *restrict, ...)
-  __attribute__ ((__weak__));
-
-int __sprintfkf (char *restrict string,
-		 const char *restrict format,
-		 _Float128 number)
-{
-  if (__sprintfieee128)
-    return __sprintfieee128 (string, format, number);
-
-  return sprintf (string, format, (long double) number);
-}
diff --git a/libgcc/config/rs6000/_sprintfkf.h b/libgcc/config/rs6000/_sprintfkf.h
deleted file mode 100644
index de9d7137f69..00000000000
--- a/libgcc/config/rs6000/_sprintfkf.h
+++ /dev/null
@@ -1,27 +0,0 @@ 
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-<http://www.gnu.org/licenses/>.  */
-
-/* Declaration of the conversion function to IEEE 128-bit floating point from
-   string using snprintf.  */
-
-extern int __sprintfkf (char *restrict, const char *restrict, _Float128);
diff --git a/libgcc/config/rs6000/_strtokf.c b/libgcc/config/rs6000/_strtokf.c
deleted file mode 100644
index dc13534cdc2..00000000000
--- a/libgcc/config/rs6000/_strtokf.c
+++ /dev/null
@@ -1,53 +0,0 @@ 
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-<http://www.gnu.org/licenses/>.  */
-
-/* Conversion to IEEE 128-bit floating point from string.  */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <soft-fp.h>
-#include <quad-float128.h>
-
-/* This function must be built with IBM 128-bit as long double, so that we can
-   access the strtold function if do not have an IEEE 128-bit version.  */
-#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IBM128__)
-#error "Long double is not IBM 128-bit"
-#endif
-
-/* If the user is using GLIBC 2.32, we can use the __strtoieee128 function.
-
-   If we are linked against an earlier library, we will have fake it by
-   converting the string to IBM 128-bit long double, and then converting that to
-   __float128.  This isn't ideal, as IEEE 128-bit has more exponent range than
-   IBM 128-bit.  */
-
-extern _Float128 __strtoieee128 (const char *, char **) __attribute__ ((__weak__));
-
-_Float128
-__strtokf (const char *string, char **endptr)
-{
-  if (__strtoieee128)
-    return __strtoieee128 (string, endptr);
-
-  return strtold (string, endptr);
-}
diff --git a/libgcc/config/rs6000/_strtokf.h b/libgcc/config/rs6000/_strtokf.h
deleted file mode 100644
index a7ca8e09244..00000000000
--- a/libgcc/config/rs6000/_strtokf.h
+++ /dev/null
@@ -1,27 +0,0 @@ 
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-<http://www.gnu.org/licenses/>.  */
-
-/* Declaration of the conversion function to IEEE 128-bit floating point from
-   string.  */
-
-extern _Float128 __strtokf (const char *, char **);
diff --git a/libgcc/config/rs6000/t-float128 b/libgcc/config/rs6000/t-float128
index 6fb1a3d871b..8b089d4433c 100644
--- a/libgcc/config/rs6000/t-float128
+++ b/libgcc/config/rs6000/t-float128
@@ -26,10 +26,6 @@  fp128_softfp_obj	= $(fp128_softfp_static_obj) $(fp128_softfp_shared_obj)
 fp128_dec_funcs		= _kf_to_sd _kf_to_dd _kf_to_td \
 			  _sd_to_kf _dd_to_kf _td_to_kf
 
-# _Float128 to/from string conversions that must be compiled with IBM 128-bit
-# long double.
-fp128_decstr_funcs	= _strtokf _sprintfkf
-
 # Decimal <-> __ibm128 conversions
 ibm128_dec_funcs	= _tf_to_sd _tf_to_dd _tf_to_td \
 			  _sd_to_tf _dd_to_tf _td_to_tf
@@ -38,7 +34,7 @@  ibm128_dec_funcs	= _tf_to_sd _tf_to_dd _tf_to_td \
 fp128_ppc_funcs		= floattikf floatuntikf fixkfti fixunskfti \
 			  extendkftf2-sw trunctfkf2-sw \
 			  sfp-exceptions _mulkc3 _divkc3 _powikf2 \
-			  $(fp128_dec_funcs) $(fp128_decstr_funcs)
+			  $(fp128_dec_funcs)
 
 fp128_ppc_src		= $(addprefix $(srcdir)/config/rs6000/,$(addsuffix \
 				.c,$(fp128_ppc_funcs)))
@@ -88,9 +84,6 @@  $(fp128_obj)		 : $(srcdir)/config/rs6000/quad-float128.h
 fp128_dec_objs		= $(addsuffix $(objext),$(fp128_dec_funcs)) \
 			  $(addsuffix _s$(objext),$(fp128_dec_funcs))
 
-fp128_decstr_objs	= $(addsuffix $(objext),$(fp128_decstr_funcs)) \
-			  $(addsuffix _s$(objext),$(fp128_decstr_funcs))
-
 ibm128_dec_objs		= $(addsuffix $(objext),$(ibm128_dec_funcs)) \
 			  $(addsuffix _s$(objext),$(ibm128_dec_funcs))
 
@@ -98,12 +91,8 @@  FP128_CFLAGS_DECIMAL	= -mno-gnu-attribute -Wno-psabi -mabi=ieeelongdouble
 IBM128_CFLAGS_DECIMAL	= -mno-gnu-attribute -Wno-psabi -mabi=ibmlongdouble
 
 $(fp128_dec_objs)	: INTERNAL_CFLAGS += $(FP128_CFLAGS_DECIMAL)
-$(fp128_decstr_objs)	: INTERNAL_CFLAGS += $(IBM128_CFLAGS_DECIMAL)
 $(ibm128_dec_objs)	: INTERNAL_CFLAGS += $(IBM128_CFLAGS_DECIMAL)
 
-$(fp128_decstr_objs)	: $(srcdir)/config/rs6000/_strtokf.h \
-			  $(srcdir)/config/rs6000/_sprintfkf.h \
-
 $(fp128_softfp_src) : $(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@)) $(fp128_dep)
 	@src="$(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@))"; \
 	echo "Create $@"; \
diff --git a/libgcc/dfp-bit.h b/libgcc/dfp-bit.h
index 5e3bfa65ab8..e04cb831026 100644
--- a/libgcc/dfp-bit.h
+++ b/libgcc/dfp-bit.h
@@ -298,8 +298,8 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define BFP_TYPE _Float128
 #define BFP_FMT "%.36Le"
 #define BFP_VIA_TYPE _Float128
-#define STR_TO_BFP __strtokf
-#include <_strtokf.h>
+#define STR_TO_BFP __strtoieee128
+extern _Float128 __strtoieee128 (const char *, char **);
 
 #endif /* BFP_KIND */
 
@@ -647,8 +647,8 @@  extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
 
 #elif defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
 extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
-#include <_sprintfkf.h>
-#define BFP_SPRINTF __sprintfkf
+extern int __sprintfieee128 (char *restrict, const char *restrict, ...);
+#define BFP_SPRINTF __sprintfieee128
 #endif
 
 #endif /* _DFPBIT_H */