[PATCH 2/3 V2] Do not include stdio.h in libgcc's Decimal/Float128 conversions.

The _sprintfkf.c file was including stdio.h to get the definition of sprintf.
This patch modifies this so that stdio.h is not included in order to support
freestanding cross compilers that might not provide stdio.h.

I have done bootstraps on a little endian power9 system with each of the long
double variants (128-bit IBM, 128-bit IEEE, 64-bit) enabled, and there were no
regressions in each of the builds with the previous version.

In addition, I have built 2 cross compilers from my x86_64 system to little
endian PowerPC Linux.  One build enabled decimal support and one disabled the
decimal support.  On the build that disabled decimal support, I verified that
the _Float128 <-> Decimal conversions were not built.

Can I check this patch into the master branch for GCC 11?

libgcc/
2021-03-01  Michael Meissner  <meiss...@linux.ibm.com>

        * config/rs6000/_sprintfkf.c: Do not include stdio.h.
        (__sprintfkf): Call __builtin_sprintf not sprintf.
---
 libgcc/config/rs6000/_sprintfkf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libgcc/config/rs6000/_sprintfkf.c 
b/libgcc/config/rs6000/_sprintfkf.c
index 2d624f14e25..9bbc26145ab 100644
--- a/libgcc/config/rs6000/_sprintfkf.c
+++ b/libgcc/config/rs6000/_sprintfkf.c
@@ -27,7 +27,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #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
@@ -42,7 +41,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
    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.  */
+   128-bit.
+
+   We use __builtin_sprintf so that we don't have to include stdio.h to define
+   sprintf.  Stdio.h might not be present for freestanding cross compilers that
+   do not need to include a library.  */
 
 extern int __sprintfieee128 (char *restrict, const char *restrict, ...)
   __attribute__ ((__weak__));
@@ -54,5 +57,5 @@ int __sprintfkf (char *restrict string,
   if (__sprintfieee128)
     return __sprintfieee128 (string, format, number);
 
-  return sprintf (string, format, (long double) number);
+  return __builtin_sprintf (string, format, (long double) number);
 }
-- 
2.22.0


-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797

Reply via email to