From patchwork Thu Dec 10 02:46:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 1413786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=v8qhBfgb; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cryxp2VjCz9sR4 for ; Thu, 10 Dec 2020 13:47:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43EE0393D026; Thu, 10 Dec 2020 02:47:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43EE0393D026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1607568429; bh=OjvwFMte5r3XFrplH0LGfZsgwhrxkmvk5VTv2W8U/wg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=v8qhBfgbyf0rC6FXfPT6JU5Mr2InjQ0zZtNS3/iXdzpDAkQgB5WXx/V8H18fjD3dk 1jLCZ+EuNmvw5RQWCcd3ATML95nZCIjmbzCMGX6TLGa1EV/a2LX7nZtRE+HNDTOeNP Vm/z+hswpH2tdRemptGZmz1ClUmIX73Be9Lc0Ud0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id AE2D63857C7B; Thu, 10 Dec 2020 02:47:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AE2D63857C7B Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 8955B3F2D58D; Wed, 9 Dec 2020 18:47:02 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vGU976ehMjEf; Wed, 9 Dec 2020 18:47:02 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id B38573F2E354; Wed, 9 Dec 2020 18:47:01 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 523C615820D9; Wed, 9 Dec 2020 18:47:01 -0800 (PST) To: libstdc++@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Add --enable-stdio=stdio_pure option [v2] Date: Wed, 9 Dec 2020 18:46:56 -0800 Message-Id: <20201210024657.3395687-2-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210024657.3395687-1-keithp@keithp.com> References: <20201209101700.GS2309743@redhat.com> <20201210024657.3395687-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Keith Packard via Gcc-patches From: Keith Packard Reply-To: Keith Packard Cc: gcc-patches@gcc.gnu.org, Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This option directs the library to only use simple stdio APIs instead of using fileno to get the file descriptor for use with POSIX APIs. Aided-by: Jonathan Wakely Signed-off-by: Keith Packard ----- v2: Switch from --enable-libstdcxx-pure-stdio to --enable-stdio=stdio_pure based on a patch from Jonathan Wakely . --- libstdc++-v3/acinclude.m4 | 20 ++++++---- libstdc++-v3/config/io/basic_file_stdio.cc | 46 +++++++++++++++++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index fcd9ea3d23a..703962ce2d7 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -2862,24 +2862,30 @@ AC_DEFUN([GLIBCXX_ENABLE_PARALLEL], [ dnl -dnl Check for which I/O library to use: stdio, or something specific. +dnl Check for which I/O library to use: stdio and POSIX, or pure stdio. dnl -dnl Default is stdio. +dnl Default is stdio_posix. dnl AC_DEFUN([GLIBCXX_ENABLE_CSTDIO], [ AC_MSG_CHECKING([for underlying I/O to use]) GLIBCXX_ENABLE(cstdio,stdio,[[[=PACKAGE]]], - [use target-specific I/O package], [permit stdio]) + [use target-specific I/O package], [permit stdio|stdio_posix|stdio_pure]) - # Now that libio has been removed, you can have any color you want as long - # as it's black. This is one big no-op until other packages are added, but - # showing the framework never hurts. + # The only available I/O model is based on stdio, via basic_file_stdio. + # The default "stdio" is actually "stdio + POSIX" because it uses fdopen(3) + # to get a file descriptor and then uses read(3) and write(3) with it. + # The "stdio_pure" model doesn't use fdopen and only uses FILE* for I/O. case ${enable_cstdio} in - stdio) + stdio*) CSTDIO_H=config/io/c_io_stdio.h BASIC_FILE_H=config/io/basic_file_stdio.h BASIC_FILE_CC=config/io/basic_file_stdio.cc AC_MSG_RESULT(stdio) + + if test "x$enable_cstdio" = "xstdio_pure" ; then + AC_DEFINE(_GLIBCXX_USE_STDIO_PURE, 1, + [Define to restrict std::__basic_file<> to stdio APIs.]) + fi ;; esac diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc index ba830fb9e97..eedffb017b6 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.cc +++ b/libstdc++-v3/config/io/basic_file_stdio.cc @@ -111,13 +111,21 @@ namespace // Wrapper handling partial write. static std::streamsize +#ifdef _GLIBCXX_USE_STDIO_PURE + xwrite(FILE *__file, const char* __s, std::streamsize __n) +#else xwrite(int __fd, const char* __s, std::streamsize __n) +#endif { std::streamsize __nleft = __n; for (;;) { +#ifdef _GLIBCXX_USE_STDIO_PURE + const std::streamsize __ret = fwrite(__file, 1, __nleft, __file); +#else const std::streamsize __ret = write(__fd, __s, __nleft); +#endif if (__ret == -1L && errno == EINTR) continue; if (__ret == -1L) @@ -133,7 +141,7 @@ namespace return __n - __nleft; } -#ifdef _GLIBCXX_HAVE_WRITEV +#if defined(_GLIBCXX_HAVE_WRITEV) && !defined(_GLIBCXX_USE_STDIO_PURE) // Wrapper handling partial writev. static std::streamsize xwritev(int __fd, const char* __s1, std::streamsize __n1, @@ -286,9 +294,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __basic_file::is_open() const throw () { return _M_cfile != 0; } +#ifndef _GLIBCCXX_USE_STDIO_PURE int __basic_file::fd() throw () { return fileno(_M_cfile); } +#endif __c_file* __basic_file::file() throw () @@ -315,28 +325,46 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { streamsize __ret; do +#ifdef _GLIBCXX_USE_STDIO_PURE + __ret = fread(__s, 1, __n, this->file()); +#else __ret = read(this->fd(), __s, __n); +#endif while (__ret == -1L && errno == EINTR); return __ret; } streamsize __basic_file::xsputn(const char* __s, streamsize __n) - { return xwrite(this->fd(), __s, __n); } + { +#ifdef _GLIBCXX_USE_STDIO_PURE + return xwrite(this->file(), __s, __n); +#else + return xwrite(this->fd(), __s, __n); +#endif + } streamsize __basic_file::xsputn_2(const char* __s1, streamsize __n1, const char* __s2, streamsize __n2) { streamsize __ret = 0; -#ifdef _GLIBCXX_HAVE_WRITEV +#if defined(_GLIBCXX_HAVE_WRITEV) && !defined(_GLIBCXX_USE_STDIO_PURE) __ret = xwritev(this->fd(), __s1, __n1, __s2, __n2); #else if (__n1) +#ifdef _GLIBCXX_USE_STDIO_PURE + __ret = xwrite(this->file(), __s1, __n1); +#else __ret = xwrite(this->fd(), __s1, __n1); +#endif if (__ret == __n1) +#ifdef _GLIBCXX_USE_STDIO_PURE + __ret += xwrite(this->file(), __s2, __n2); +#else __ret += xwrite(this->fd(), __s2, __n2); +#endif #endif return __ret; } @@ -350,7 +378,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__off > numeric_limits::max() || __off < numeric_limits::min()) return -1L; +#ifdef _GLIBCXX_USE_STDIO_PURE + return fseek(this->file(), __off, __way); +#else return lseek(this->fd(), __off, __way); +#endif #endif } @@ -361,7 +393,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION streamsize __basic_file::showmanyc() { -#ifndef _GLIBCXX_NO_IOCTL +#if !defined(_GLIBCXX_NO_IOCTL) && !defined(_GLIBCXX_USE_STDIO_PURE) #ifdef FIONREAD // Pipes and sockets. int __num = 0; @@ -371,7 +403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif #endif -#ifdef _GLIBCXX_HAVE_POLL +#if defined(_GLIBCXX_HAVE_POLL) && !defined(_GLIBCXX_USE_STDIO_PURE) // Cheap test. struct pollfd __pfd[1]; __pfd[0].fd = this->fd(); @@ -395,8 +427,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct stat __buffer; const int __err = fstat(this->fd(), &__buffer); if (!__err && _GLIBCXX_ISREG(__buffer.st_mode)) +#ifdef _GLIBCXX_USE_STDIO_PURE + return __buffer.st_size - fseek(this->file(), 0, ios_base::cur); +#else return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur); #endif +#endif #endif return 0; } From patchwork Thu Dec 10 02:46:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 1413785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=oExCT9+s; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cryxd5lHbz9sW8 for ; Thu, 10 Dec 2020 13:47:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03492387089E; Thu, 10 Dec 2020 02:47:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03492387089E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1607568428; bh=nDt0bNPDUtd5EDtEC0g7K0b+kgbU2uhiQtm9WDRLdic=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oExCT9+sWw+4fFNcLuqtolfCYmOK83TDBpspkMixak79o8LnhA0fE8Bp87KxwAVMD vUEc++WhDh6q7LHVKAN1uVgdvAc19W+Xhh30esDXgf70g6JEYjkZqTB9/8rF/xjt2l OEQ/+5NPjDj/KSTOyMjOhFttKpwl4xHh7TYmvHJA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id B4A80384BC17; Thu, 10 Dec 2020 02:47:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B4A80384BC17 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 067863F2E356; Wed, 9 Dec 2020 18:47:02 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id upYaeNoQNX2g; Wed, 9 Dec 2020 18:47:01 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id B21B73F2E353; Wed, 9 Dec 2020 18:47:01 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 572011582188; Wed, 9 Dec 2020 18:47:01 -0800 (PST) To: libstdc++@gcc.gnu.org Subject: [PATCH 2/2] Regenerate libstdc++-v3 autoconf files Date: Wed, 9 Dec 2020 18:46:57 -0800 Message-Id: <20201210024657.3395687-3-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210024657.3395687-1-keithp@keithp.com> References: <20201209101700.GS2309743@redhat.com> <20201210024657.3395687-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Keith Packard via Gcc-patches From: Keith Packard Reply-To: Keith Packard Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" These are the changes to autoconf files for the stdio_pure patch Signed-off-by: Keith Packard --- libstdc++-v3/config.h.in | 3 +++ libstdc++-v3/configure | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 72faabfb2c1..c0c166715cb 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -1022,6 +1022,9 @@ /* Define if POSIX read/write locks are available in . */ #undef _GLIBCXX_USE_PTHREAD_RWLOCK_T +/* Define to restrict std::__basic_file<> to stdio APIs. */ +#undef _GLIBCXX_USE_STDIO_PURE + /* Define if /dev/random and /dev/urandom are available for the random_device of TR1 (Chapter 5.1). */ #undef _GLIBCXX_USE_RANDOM_TR1 diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index d128de2f186..36c61a77d07 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -16376,7 +16376,7 @@ $as_echo_n "checking for underlying I/O to use... " >&6; } if test "${enable_cstdio+set}" = set; then : enableval=$enable_cstdio; case "$enableval" in - stdio) ;; + stdio|stdio_posix|stdio_pure) ;; *) as_fn_error $? "Unknown argument to enable/disable cstdio" "$LINENO" 5 ;; esac @@ -16386,16 +16386,23 @@ fi - # Now that libio has been removed, you can have any color you want as long - # as it's black. This is one big no-op until other packages are added, but - # showing the framework never hurts. + # The only available I/O model is based on stdio, via basic_file_stdio. + # The default "stdio" is actually "stdio + POSIX" because it uses fdopen(3) + # to get a file descriptor and then uses read(3) and write(3) with it. + # The "stdio_pure" model doesn't use fdopen and only uses FILE* for I/O. case ${enable_cstdio} in - stdio) + stdio*) CSTDIO_H=config/io/c_io_stdio.h BASIC_FILE_H=config/io/basic_file_stdio.h BASIC_FILE_CC=config/io/basic_file_stdio.cc { $as_echo "$as_me:${as_lineno-$LINENO}: result: stdio" >&5 $as_echo "stdio" >&6; } + + if test "x$enable_cstdio" = "xstdio_pure" ; then + +$as_echo "#define _GLIBCXX_USE_STDIO_PURE 1" >>confdefs.h + + fi ;; esac