public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS
@ 2023-07-06 15:11 redi at gcc dot gnu.org
  2023-07-06 15:28 ` [Bug libstdc++/110574] " cvs-commit at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-06 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

            Bug ID: 110574
           Summary: --enable-cstdio=stdio_pure is incompatible with LFS
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: keithp at keithp dot com
  Target Milestone: ---

Using --enable-cstdio=stdio_pure on x86_64-pc-linux-gnu results in test
failures:

FAIL: 27_io/basic_filebuf/imbue/char/13171-2.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/12790-3.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/45628-2.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/1-in.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/1-io.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/1-out.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/2-in.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/2-io.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/2-out.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/26777.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/char/4.cc execution test
FAIL: 27_io/basic_filebuf/seekoff/wchar_t/4.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/12790-2.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/12790-3.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/1-in.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/1-io.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/1-out.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/2-in.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/2-io.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/char/2-out.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/wchar_t/9874.cc execution test
FAIL: 27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc execution test
FAIL: 27_io/basic_filebuf/sgetn/char/2-in.cc execution test
FAIL: 27_io/basic_filebuf/sgetn/char/2-io.cc execution test
FAIL: 27_io/basic_filebuf/sputbackc/char/1-io.cc execution test
FAIL: 27_io/basic_filebuf/sputbackc/char/2-io.cc execution test
FAIL: 27_io/basic_filebuf/sungetc/char/1-io.cc execution test
FAIL: 27_io/basic_filebuf/sungetc/char/2-io.cc execution test
FAIL: 27_io/basic_filebuf/underflow/char/10097.cc execution test
FAIL: 27_io/basic_filebuf/underflow/wchar_t/5.cc execution test
FAIL: 27_io/basic_fstream/53984.cc execution test
FAIL: 27_io/basic_istream/peek/char/6414.cc execution test
FAIL: 27_io/basic_istream/peek/wchar_t/6414.cc execution test
FAIL: 27_io/basic_istream/seekg/char/fstream.cc execution test
FAIL: 27_io/basic_istream/seekg/wchar_t/fstream.cc execution test
FAIL: 27_io/basic_istream/tellg/char/fstream.cc execution test
FAIL: 27_io/basic_istream/tellg/wchar_t/fstream.cc execution test
FAIL: 27_io/objects/wchar_t/12.cc execution test

This seems to be because of code like:

  streamoff
  __basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way) throw
()
  {
#ifdef _GLIBCXX_USE_LFS
    return lseek64(this->fd(), __off, __way);
#else
    if (__off > numeric_limits<off_t>::max()
        || __off < numeric_limits<off_t>::min())
      return -1L;
#ifdef _GLIBCXX_USE_STDIO_PURE
    return fseek(this->file(), __off, __way);
#else
    return lseek(this->fd(), __off, __way);
#endif
#endif

If LFS is being used then the STDIO_PURE config is ignored, and we use lseek64
on the file descriptor unconditionally. Then when we read we do respect the
STDIO_PURE config:

  streamsize
  __basic_file<char>::xsgetn(char* __s, streamsize __n)
  {
    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;
  }

But now we're seeking on the file descriptor and reading from the FILE. We need
to use fseek before fread.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
@ 2023-07-06 15:28 ` cvs-commit at gcc dot gnu.org
  2023-07-06 15:38 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-06 15:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:b90a70984a9beee39b41f842b56926f9db2069ca

commit r14-2366-gb90a70984a9beee39b41f842b56926f9db2069ca
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 6 16:25:47 2023 +0100

    libstdc++: Document --enable-cstdio=stdio_pure [PR110574]

    libstdc++-v3/ChangeLog:

            PR libstdc++/110574
            * doc/xml/manual/configure.xml: Describe stdio_pure argument to
            --enable-cstdio.
            * doc/html/manual/configure.html: Regenerate.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
  2023-07-06 15:28 ` [Bug libstdc++/110574] " cvs-commit at gcc dot gnu.org
@ 2023-07-06 15:38 ` redi at gcc dot gnu.org
  2023-07-06 16:24 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-06 15:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Doh, I put the wrong PR number in that commit, it's meant to be for PR 104299

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
  2023-07-06 15:28 ` [Bug libstdc++/110574] " cvs-commit at gcc dot gnu.org
  2023-07-06 15:38 ` redi at gcc dot gnu.org
@ 2023-07-06 16:24 ` redi at gcc dot gnu.org
  2023-07-06 18:01 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-06 16:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> Using --enable-cstdio=stdio_pure on x86_64-pc-linux-gnu results in test
> failures:
> 
> FAIL: 27_io/basic_filebuf/imbue/char/13171-2.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/12790-3.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/45628-2.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/1-in.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/1-io.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/1-out.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/2-in.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/2-io.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/2-out.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/26777.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/char/4.cc execution test
> FAIL: 27_io/basic_filebuf/seekoff/wchar_t/4.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/12790-2.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/12790-3.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/1-in.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/1-io.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/1-out.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/2-in.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/2-io.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/char/2-out.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/wchar_t/9874.cc execution test
> FAIL: 27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc execution test
> FAIL: 27_io/basic_filebuf/sgetn/char/2-in.cc execution test
> FAIL: 27_io/basic_filebuf/sgetn/char/2-io.cc execution test
> FAIL: 27_io/basic_filebuf/sputbackc/char/1-io.cc execution test
> FAIL: 27_io/basic_filebuf/sputbackc/char/2-io.cc execution test
> FAIL: 27_io/basic_filebuf/sungetc/char/1-io.cc execution test
> FAIL: 27_io/basic_filebuf/sungetc/char/2-io.cc execution test
> FAIL: 27_io/basic_filebuf/underflow/char/10097.cc execution test
> FAIL: 27_io/basic_filebuf/underflow/wchar_t/5.cc execution test
> FAIL: 27_io/basic_fstream/53984.cc execution test
> FAIL: 27_io/basic_istream/peek/char/6414.cc execution test
> FAIL: 27_io/basic_istream/peek/wchar_t/6414.cc execution test
> FAIL: 27_io/basic_istream/seekg/char/fstream.cc execution test
> FAIL: 27_io/basic_istream/seekg/wchar_t/fstream.cc execution test
> FAIL: 27_io/basic_istream/tellg/char/fstream.cc execution test
> FAIL: 27_io/basic_istream/tellg/wchar_t/fstream.cc execution test
> FAIL: 27_io/objects/wchar_t/12.cc execution test
> 
> This seems to be because of code like:
> 
>   streamoff
>   __basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way)
> throw ()
>   {
> #ifdef _GLIBCXX_USE_LFS
>     return lseek64(this->fd(), __off, __way);
> #else
>     if (__off > numeric_limits<off_t>::max()
> 	|| __off < numeric_limits<off_t>::min())
>       return -1L;
> #ifdef _GLIBCXX_USE_STDIO_PURE
>     return fseek(this->file(), __off, __way);

Oh, and fseek returns 0 or -1, not the position, so we shouldn't return its
value here.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-06 16:24 ` redi at gcc dot gnu.org
@ 2023-07-06 18:01 ` redi at gcc dot gnu.org
  2023-07-07  5:54 ` keithp at keithp dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-06 18:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-07-06
     Ever confirmed|0                           |1
   Target Milestone|---                         |11.5

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I have a patch ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-06 18:01 ` redi at gcc dot gnu.org
@ 2023-07-07  5:54 ` keithp at keithp dot com
  2023-07-12 20:04 ` cvs-commit at gcc dot gnu.org
  2023-07-18 11:00 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: keithp at keithp dot com @ 2023-07-07  5:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #5 from keithp at keithp dot com <keithp at keithp dot com> ---
Seems like using fseeko would be a reasonable choice here -- while it's not in
ISO C, it is in POSIX 2017.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-07  5:54 ` keithp at keithp dot com
@ 2023-07-12 20:04 ` cvs-commit at gcc dot gnu.org
  2023-07-18 11:00 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-12 20:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:2f6bbc9a7d9a62423c576e13dc46323fe16ba5aa

commit r14-2476-g2f6bbc9a7d9a62423c576e13dc46323fe16ba5aa
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 6 17:10:41 2023 +0100

    libstdc++: Fix --enable-cstdio=stdio_pure [PR110574]

    When configured with --enable-cstdio=stdio_pure we need to consistently
    use fseek and not mix seeks on the file descriptor with reads and writes
    on the FILE stream.

    There are also a number of bugs related to error handling and return
    values, because fread and fwrite return 0 on error, not -1, and fseek
    returns 0 on success, not the file offset.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110574
            * acinclude.m4 (GLIBCXX_CHECK_LFS): Check for fseeko and ftello
            and define _GLIBCXX_USE_FSEEKO_FTELLO.
            * config.h.in: Regenerate.
            * configure: Regenerate.
            * config/io/basic_file_stdio.cc (xwrite) [_GLIBCXX_USE_STDIO_PURE]:
            Check for fwrite error correctly.
            (__basic_file<char>::xsgetn) [_GLIBCXX_USE_STDIO_PURE]: Check for
            fread error correctly.
            (get_file_offset): New function.
            (__basic_file<char>::seekoff) [_GLIBCXX_USE_STDIO_PURE]: Use
            fseeko if available. Use get_file_offset instead of return value
            of fseek.
            (__basic_file<char>::showmanyc): Use get_file_offset.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/110574] --enable-cstdio=stdio_pure is incompatible with LFS
  2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-07-12 20:04 ` cvs-commit at gcc dot gnu.org
@ 2023-07-18 11:00 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-18 11:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110574

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:5342e3cc446d9ba0017c167aa3ff9d3c08c11f0f

commit r13-7578-g5342e3cc446d9ba0017c167aa3ff9d3c08c11f0f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 6 17:10:41 2023 +0100

    libstdc++: Fix --enable-cstdio=stdio_pure [PR110574]

    When configured with --enable-cstdio=stdio_pure we need to consistently
    use fseek and not mix seeks on the file descriptor with reads and writes
    on the FILE stream.

    There are also a number of bugs related to error handling and return
    values, because fread and fwrite return 0 on error, not -1, and fseek
    returns 0 on success, not the file offset.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110574
            * acinclude.m4 (GLIBCXX_CHECK_LFS): Check for fseeko and ftello
            and define _GLIBCXX_USE_FSEEKO_FTELLO.
            * config.h.in: Regenerate.
            * configure: Regenerate.
            * config/io/basic_file_stdio.cc (xwrite) [_GLIBCXX_USE_STDIO_PURE]:
            Check for fwrite error correctly.
            (__basic_file<char>::xsgetn) [_GLIBCXX_USE_STDIO_PURE]: Check for
            fread error correctly.
            (get_file_offset): New function.
            (__basic_file<char>::seekoff) [_GLIBCXX_USE_STDIO_PURE]: Use
            fseeko if available. Use get_file_offset instead of return value
            of fseek.
            (__basic_file<char>::showmanyc): Use get_file_offset.

    (cherry picked from commit 2f6bbc9a7d9a62423c576e13dc46323fe16ba5aa)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-18 11:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 15:11 [Bug libstdc++/110574] New: --enable-cstdio=stdio_pure is incompatible with LFS redi at gcc dot gnu.org
2023-07-06 15:28 ` [Bug libstdc++/110574] " cvs-commit at gcc dot gnu.org
2023-07-06 15:38 ` redi at gcc dot gnu.org
2023-07-06 16:24 ` redi at gcc dot gnu.org
2023-07-06 18:01 ` redi at gcc dot gnu.org
2023-07-07  5:54 ` keithp at keithp dot com
2023-07-12 20:04 ` cvs-commit at gcc dot gnu.org
2023-07-18 11:00 ` cvs-commit at gcc dot gnu.org

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).