public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Meissner <meissner@linux.ibm.com>
To: Michael Meissner <meissner@linux.ibm.com>,
	gcc-patches@gcc.gnu.org,
	Segher Boessenkool <segher@kernel.crashing.org>,
	David Edelsohn <dje.gcc@gmail.com>,
	Bill Schmidt <wschmidt@linux.ibm.com>,
	Peter Bergner <bergner@linux.ibm.com>,
	Joseph Myers <joseph@codesourcery.com>
Subject: [PATCH 2/3 V2] Do not include stdio.h in libgcc's Decimal/Float128 conversions.
Date: Mon, 1 Mar 2021 12:18:52 -0500	[thread overview]
Message-ID: <20210301171852.GB9185@ibm-toto.the-meissners.org> (raw)
In-Reply-To: <20210301171432.GA7962@ibm-toto.the-meissners.org>

[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  <meissner@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: meissner@linux.ibm.com, phone: +1 (978) 899-4797

  parent reply	other threads:[~2021-03-01 17:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 17:14 [PATCH 0/3 V2] Honor --disable-decimal-float in PowerPC libgcc _Float128 Michael Meissner
2021-03-01 17:17 ` [PATCH 1/3 V2] Fix __sprintfkf prototype in libgcc Michael Meissner
2021-03-01 22:37   ` Segher Boessenkool
2021-03-01 17:18 ` Michael Meissner [this message]
2021-03-01 23:15   ` [PATCH 2/3 V2] Do not include stdio.h in libgcc's Decimal/Float128 conversions Segher Boessenkool
2021-03-02 21:25     ` Michael Meissner
2021-03-02 21:53       ` Segher Boessenkool
2021-03-03 19:12         ` Michael Meissner
2021-03-03 23:33           ` Joseph Myers
2021-03-04  1:01             ` Michael Meissner
2021-03-09 18:35           ` Segher Boessenkool
2021-03-01 17:19 ` [PATCH 3/3 V2] Do not build Decimal/Float128 conversions if decimal is disabled Michael Meissner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301171852.GB9185@ibm-toto.the-meissners.org \
    --to=meissner@linux.ibm.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).