public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable
@ 2021-11-23 17:22 maxiwell at gmail dot com
  2021-11-23 18:32 ` [Bug libstdc++/103387] " meissner at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: maxiwell at gmail dot com @ 2021-11-23 17:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103387
           Summary: powerpc64le: segmentation fault on std::cout with
                    ieee128 long double variable
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maxiwell at gmail dot com
  Target Milestone: ---

How to reproduce:

- Building GCC from the master branch:

~/devel> git clone git://gcc.gnu.org/git/gcc.git && cd gcc/

~/devel/gcc> git rev-parse HEAD
a944b5dec3adb28ed199234d2116145ca9010d6a

~/devel/gcc> mkdir build && cd build

~/devel/gcc/build> ../configure --prefix=/home/maxiwell/usr/
--build=powerpc64le-linux-gnu --host=powerpc64le-linux-gnu
--target=powerpc64le-linux-gnu --enable-languages=c++ --disable-bootstrap
CC=gcc-11 CXX=g++-11

~/devel/gcc/build> make && make install

~/devel/gcc/build> /home/maxiwell/usr/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/home/maxiwell/usr/bin/g++
COLLECT_LTO_WRAPPER=/home/maxiwell/usr/libexec/gcc/powerpc64le-linux-gnu/12.0.0/lto-wrapper
Target: powerpc64le-linux-gnu
Configured with: ../configure --prefix=/home/maxiwell/usr/
--build=powerpc64le-linux-gnu --host=powerpc64le-linux-gnu
--target=powerpc64le-linux-gnu --enable-languages=c++ --disable-bootstrap
CC=gcc-11 CXX=g++-11
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211123 (experimental) (GCC)


- Running a simple C++ program to print an IEEE long double var using std::cout

~> cat test.cpp
#include <iostream>

int main()
{
    long double n = 0.1L;
    std::cout << n;
    return 0;
}

~> /home/maxiwell/usr/bin/g++ test.cpp -g -o test -mabi=ieeelongdouble
~> ./test
Segmentation fault (core dumped)

- It works with printf:

~> cat test-printf.cpp
#include <stdio.h>

int main()
{
    long double n = 0.1L;
    printf("%Lg\n", n);
    return 0;
}

~> /home/maxiwell/usr/bin/g++ test-printf.cpp -g -o test-printf
-mabi=ieeelongdouble
~> ./test-printf
0.1

- Running the std::cout program with GDB

~> gdb -q -s --args test
Reading symbols from test...
(gdb) r
Starting program: /home/maxiwell/test

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff7d3667c in std::__gnu_cxx_ieee128::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > >::put
(__v=6.95334903218850043777638611569573e-310, __fill=32 ' ',
    __io=..., __s=..., this=0x7ffff7f55208 <(anonymous namespace)::num_put_c>)
    at
/usr/src/debug/gcc11-11.1.1+git340-1.1.ppc64le/obj-powerpc64le-suse-linux/powerpc64le-suse-linux/libstdc++-v3/include/bits/locale_facets.h:2461
#2  std::ostream::_M_insert<__ieee128> (this=0x7ffff7f536e8 <std::cout>,
__v=6.95334903218850043777638611569573e-310)
        at
/usr/src/debug/gcc11-11.1.1+git340-1.1.ppc64le/obj-powerpc64le-suse-linux/powerpc64le-suse-linux/libstdc++-v3/include/bits/ostream.tcc:73
#3  0x00007ffff7d368c8 in std::ostream::operator<< (this=<optimized out>,
__f=<optimized out>)
            at
/usr/src/debug/gcc11-11.1.1+git340-1.1.ppc64le/obj-powerpc64le-suse-linux/powerpc64le-suse-linux/libstdc++-v3/include/ostream:233
#4  0x000000001000098c in main () at test.cpp:6

The __v parameter from #1 and #2 has the same value that was reported here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100912

- Versions:

~> cat /etc/os-release
NAME="openSUSE Tumbleweed"
# VERSION="20210626"
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
VERSION_ID="20210626"
PRETTY_NAME="openSUSE Tumbleweed"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:tumbleweed:20210626"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Tumbleweed"
LOGO="distributor-logo"

~> g++-11 -v
Using built-in specs.
COLLECT_GCC=g++-11
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/powerpc64le-suse-linux/11/lto-wrapper
Target: powerpc64le-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,ada,go,jit --enable-host-shared
--enable-checking=release --disable-werror
--with-gxx-include-dir=/usr/include/c++/11 --enable-ssp --disable-libssp
--disable-libvtv --enable-cet=auto --disable-libcc1 --enable-plugin
--with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --enable-version-specific-runtime-libs
--with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex
--enable-gnu-indirect-function --program-suffix=-11 --without-system-libunwind
--with-cpu=power8 --with-tune=power9 --enable-secureplt --with-long-double-128
--enable-targets=powerpcle-linux --disable-multilib
--with-build-config=bootstrap-lto-lean --enable-link-mutex
--build=powerpc64le-suse-linux --host=powerpc64le-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.1 20210617 [revision 79c1185de4a05fdea13b6b020795892913f8184e]
(SUSE Linux)

~> /lib64/libc.so.6
GNU C Library (GNU libc) release release version 2.33 (git 9826b03b74).
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for ppc64le-suse-linux.
Compiled by GNU CC version 11.1.1 20210510 [revision
23855a176609fe8dda6abaf2b21846b4517966eb].
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<http://bugs.opensuse.org>.

~> rpm -qa binutils
binutils-2.36-4.14.ppc64le

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
@ 2021-11-23 18:32 ` meissner at gcc dot gnu.org
  2021-11-23 21:21 ` redi at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: meissner at gcc dot gnu.org @ 2021-11-23 18:32 UTC (permalink / raw)
  To: gcc-bugs

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

Michael Meissner <meissner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major
   Last reconfirmed|                            |2021-11-23
           Priority|P3                          |P1
                 CC|                            |meissner at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Michael Meissner <meissner at gcc dot gnu.org> ---
I tried it on a current trunk compiler (from November 23, 2021) using glibc
2.34 (IBM AT 14.0), and it does fail.  It works fine if I build a toolchain
where the default long double is IEEE 128-bit.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
  2021-11-23 18:32 ` [Bug libstdc++/103387] " meissner at gcc dot gnu.org
@ 2021-11-23 21:21 ` redi at gcc dot gnu.org
  2021-11-24 22:37 ` tuliom at ascii dot art.br
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-23 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
  2021-11-23 18:32 ` [Bug libstdc++/103387] " meissner at gcc dot gnu.org
  2021-11-23 21:21 ` redi at gcc dot gnu.org
@ 2021-11-24 22:37 ` tuliom at ascii dot art.br
  2022-05-06  8:31 ` jakub at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tuliom at ascii dot art.br @ 2021-11-24 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

Tulio Magno Quites Machado Filho <tuliom at ascii dot art.br> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tuliom at ascii dot art.br

--- Comment #2 from Tulio Magno Quites Machado Filho <tuliom at ascii dot art.br> ---
(In reply to Michael Meissner from comment #1)
> I tried it on a current trunk compiler (from November 23, 2021) using glibc
> 2.34 (IBM AT 14.0), and it does fail.  It works fine if I build a toolchain
> where the default long double is IEEE 128-bit.

So, it sounds like this is happening because libstdc++ is not distributing cout
implementations for all the supported long double types, but just for the
default type as explained in bug #100912.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (2 preceding siblings ...)
  2021-11-24 22:37 ` tuliom at ascii dot art.br
@ 2022-05-06  8:31 ` jakub at gcc dot gnu.org
  2023-03-23 19:01 ` bergner at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-06  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |12.2

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 12.1 is being released, retargeting bugs to GCC 12.2.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (3 preceding siblings ...)
  2022-05-06  8:31 ` jakub at gcc dot gnu.org
@ 2023-03-23 19:01 ` bergner at gcc dot gnu.org
  2023-03-28  9:16 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: bergner at gcc dot gnu.org @ 2023-03-23 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Bergner <bergner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bergner at gcc dot gnu.org

--- Comment #5 from Peter Bergner <bergner at gcc dot gnu.org> ---
I think this is fixed now due to Jonathan's fix for PR100912, correct?


bergner@ltcden2-lp1:PR103387$ cat foo.cc 
#include <iostream>

int main()
{
    long double n = 0.1L;
    std::cout << n << std::endl;
    return 0;
}

bergner@ltcden2-lp1:PR103387$
/home/bergner/gcc/install/gcc-fsf-mainline-base/bin/g++
-L/home/bergner/gcc/install/gcc-fsf-mainline-base/lib64
-R/home/bergner/gcc/install/gcc-fsf-mainline-base/lib64 -mabi=ibmlongdouble
foo.cc 
bergner@ltcden2-lp1:PR103387$ ./a.out 
0.1

So can we mark this P1 bug as RESOLVED/FIXED?

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (4 preceding siblings ...)
  2023-03-23 19:01 ` bergner at gcc dot gnu.org
@ 2023-03-28  9:16 ` redi at gcc dot gnu.org
  2023-03-28 14:54 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-28  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-11-23 00:00:00         |2023-3-28

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I thought it was, but no, it seems to still crash:

$ ~/gcc/13/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/home/test/gcc/13/bin/g++
COLLECT_LTO_WRAPPER=/home/test/gcc/13/libexec/gcc/powerpc64le-unknown-linux-gnu/13.0.1/lto-wrapper
Target: powerpc64le-unknown-linux-gnu
Configured with: /home/test/src/gcc/configure --enable-languages=c++
--disable-bootstrap --prefix=/home/test/gcc/13
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.1 20230327 (experimental) (GCC) 
$ ~/gcc/13/bin/g++ d.cc -mabi=ieeelongdouble -Wl,-rpath,$HOME/gcc/13/lib64 
$ ldd ./a.out
        linux-vdso64.so.1 (0x00007fffa0fa0000)
        libstdc++.so.6 => /home/test/gcc/13/lib64/libstdc++.so.6
(0x00007fffa0c00000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fffa0ab0000)
        libgcc_s.so.1 => /home/test/gcc/13/lib64/libgcc_s.so.1
(0x00007fffa0a50000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fffa0600000)
        /lib64/ld64.so.2 (0x00007fffa0fb0000)
$ ./a.out
Segmentation fault (core dumped)

GCC is built with the implied default of --with-long-double-format=ibm and the
testcase is built with -mabi=ieeelongdouble

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-28  9:16 ` redi at gcc dot gnu.org
@ 2023-03-28 14:54 ` redi at gcc dot gnu.org
  2023-03-28 15:00 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-28 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
OK, I see what's happening now:

Breakpoint 3.3, std::__gnu_cxx_ldbl128::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > >::num_put (
    this=0x101c1f98 <(anonymous namespace)::num_put_c>, __refs=1)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:2339
2339          num_put(size_t __refs = 0) : facet(__refs) { }
(gdb) p this
$9 = (std::__gnu_cxx_ldbl128::num_put<char, std::ostreambuf_iterator<char,
std::char_traits<char> > > * const) 0x101c1f98 <(anonymous
namespace)::num_put_c>
(gdb) cont
Continuing.

Breakpoint 3.4, std::__gnu_cxx_ldbl128::num_put<wchar_t,
std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> > >::num_put (
    this=0x101c25f8 <(anonymous namespace)::num_put_w>, __refs=1)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:2339
2339          num_put(size_t __refs = 0) : facet(__refs) { }
(gdb) p this
$10 = (std::__gnu_cxx_ldbl128::num_put<wchar_t,
std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> > > * const)
0x101c25f8 <(anonymous namespace)::num_put_w>
(gdb) cont
Continuing.

Breakpoint 3.1, std::__gnu_cxx_ieee128::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > >::num_put (
    this=0x101c06b8 <std::(anonymous namespace)::num_put_c>, __refs=1)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:2339
2339          num_put(size_t __refs = 0) : facet(__refs) { }
(gdb) p this
$11 = (std::__gnu_cxx_ieee128::num_put<char, std::ostreambuf_iterator<char,
std::char_traits<char> > > * const) 0x101c06b8 <std::(anonymous
namespace)::num_put_c>
(gdb) cont
Continuing.

Breakpoint 3.2, std::__gnu_cxx_ieee128::num_put<wchar_t,
std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> > >::num_put (
    this=0x101c06f8 <std::(anonymous namespace)::num_put_w>, __refs=1)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:2339
2339          num_put(size_t __refs = 0) : facet(__refs) { }
(gdb) p this
$12 = (std::__gnu_cxx_ieee128::num_put<wchar_t,
std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> > > * const)
0x101c06f8 <std::(anonymous namespace)::num_put_w>
(gdb) cont
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) up
#1  0x0000000010015640 in std::__gnu_cxx_ieee128::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > >::put (
    this=0x101c1f98 <(anonymous namespace)::num_put_c>, __s=..., __io=...,
__fill=32 ' ', __v=0.100000000000000000000000000000000005)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:2468
2468          { return this->do_put(__s, __io, __fill, __v); }
(gdb) p this
$13 = (const std::__gnu_cxx_ieee128::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > > * const) 0x101c1f98
<(anonymous namespace)::num_put_c>


The facet used for the output is __gnu_cxx_ieee128::num_put<char> but it has
the address of $9 which is a __gnu_cxx_ldbl128::num_put<char>. So the wrong
pointer is being returned when accessing the facet.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (6 preceding siblings ...)
  2023-03-28 14:54 ` redi at gcc dot gnu.org
@ 2023-03-28 15:00 ` redi at gcc dot gnu.org
  2023-03-28 16:48 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-28 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And that's because we're using the ostream's cached _M_num_put but that is the
wrong one:

(gdb) step
std::basic_ostream<char, std::char_traits<char> >::_M_insert<__ieee128>
(this=0x101c0900 <std::cout>, __v=0.100000000000000000000000000000000005)
    at
/home/test/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:66
66              sentry __cerb(*this);
(gdb) n
67              if (__cerb)
(gdb) 
69                  ios_base::iostate __err = ios_base::goodbit;
(gdb) 
72                      const __num_put_type& __np =
__check_facet(this->_M_num_put);
(gdb) p _M_num_put
$18 = (const std::basic_ios<char, std::char_traits<char> >::__num_put_type *)
0x101c1f98 <(anonymous namespace)::num_put_c>

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (7 preceding siblings ...)
  2023-03-28 15:00 ` redi at gcc dot gnu.org
@ 2023-03-28 16:48 ` redi at gcc dot gnu.org
  2023-03-28 23:18 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-28 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This fixes the testcase, but I'll check for other problems using the cached
facets:

--- a/libstdc++-v3/include/bits/ostream.tcc
+++ b/libstdc++-v3/include/bits/ostream.tcc
@@ -69,7 +69,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            ios_base::iostate __err = ios_base::goodbit;
            __try
              {
+#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
                const __num_put_type& __np = __check_facet(this->_M_num_put);
+#else
+               const __num_put_type& __np
+                 = use_facet<__num_put_type>(this->_M_ios_locale);
+#endif
                if (__np.put(*this, *this, this->fill(), __v).failed())
                  __err |= ios_base::badbit;
              }

The _M_num_put cache exists to avoid doing the RTTI check implied by use_facet
every time we use the stream. But that RTTI check has been removed for GCC 13
anyway. Since the cached facet is the cause of this bug, we can just ignore it
for powercp64le when we support two forms of long double.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (8 preceding siblings ...)
  2023-03-28 16:48 ` redi at gcc dot gnu.org
@ 2023-03-28 23:18 ` cvs-commit at gcc dot gnu.org
  2023-03-28 23:19 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-28 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 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:ec12639c82e944d37200a744156e183ea19add00

commit r13-6918-gec12639c82e944d37200a744156e183ea19add00
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Mar 28 21:07:21 2023 +0100

    libstdc++: Do not use facets cached in ios for ATL128 build [PR103387]

    For the powerpc64le build with two different long double
    representations, we cannot use the ios_base::_M_num_put and
    ios_base::_M_num_get pointers, because they might have been initialized
    in a translation unit using the other long double type. With the changes
    to add __try_use_facet to GCC 13 the cache isn't really needed now, we
    can just access the right facet in the locale directly, without needing
    RTTI checks.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103387
            * include/bits/istream.tcc (istream::_M_extract(ValueT&)): Use
            std::use_facet instead of cached _M_num_get facet.
            (istream::operator>>(short&)): Likewise.
            (istream::operator>>(int&)): Likewise.
            * include/bits/ostream.tcc (ostream::_M_insert(ValueT)): Use
            std::use_facet instead of cached _M_num_put facet.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (9 preceding siblings ...)
  2023-03-28 23:18 ` cvs-commit at gcc dot gnu.org
@ 2023-03-28 23:19 ` redi at gcc dot gnu.org
  2023-04-20 13:57 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-28 23:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk now.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (10 preceding siblings ...)
  2023-03-28 23:19 ` redi at gcc dot gnu.org
@ 2023-04-20 13:57 ` cvs-commit at gcc dot gnu.org
  2023-04-20 16:38 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-20 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:24cf9f4c6f45f7d8b37757cdb34576ee5d2d40e1

commit r12-9454-g24cf9f4c6f45f7d8b37757cdb34576ee5d2d40e1
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Mar 28 21:07:21 2023 +0100

    libstdc++: Do not use facets cached in ios for ALT128 build [PR103387]

    For the powerpc64le build with two different long double
    representations, we cannot use the ios_base::_M_num_put and
    ios_base::_M_num_get pointers, because they might have been initialized
    in a translation unit using the other long double type. With the changes
    to add __try_use_facet to GCC 13 the cache isn't really needed now, we
    can just access the right facet in the locale directly, without needing
    RTTI checks.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103387
            * include/bits/istream.tcc (istream::_M_extract(ValueT&)): Use
            std::use_facet instead of cached _M_num_get facet.
            (istream::operator>>(short&)): Likewise.
            (istream::operator>>(int&)): Likewise.
            * include/bits/ostream.tcc (ostream::_M_insert(ValueT)): Use
            std::use_facet instead of cached _M_num_put facet.

    (cherry picked from commit ec12639c82e944d37200a744156e183ea19add00)

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (11 preceding siblings ...)
  2023-04-20 13:57 ` cvs-commit at gcc dot gnu.org
@ 2023-04-20 16:38 ` redi at gcc dot gnu.org
  2023-04-21 15:01 ` cvs-commit at gcc dot gnu.org
  2023-04-21 15:03 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-20 16:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #9)
> The _M_num_put cache exists to avoid doing the RTTI check implied by
> use_facet every time we use the stream. But that RTTI check has been removed
> for GCC 13 anyway. Since the cached facet is the cause of this bug, we can
> just ignore it for powercp64le when we support two forms of long double.

I've backported this to gcc-12, but we don't have the optimization to make
std::use_facet faster on gcc-12 (and it requires new exported symbols, so can't
be backported). That means there's a performance hit for those iostream ops on
gcc-12 now. But they don't segfault!

Maybe I should look into a powerpc64le-specific change to avoid that
performance hit on the branch. Or maybe only avoid the cached facet when
outputting an __ieee128, as that's when the cached facet is not usable.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (12 preceding siblings ...)
  2023-04-20 16:38 ` redi at gcc dot gnu.org
@ 2023-04-21 15:01 ` cvs-commit at gcc dot gnu.org
  2023-04-21 15:03 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-21 15:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:8caf5805ad76125b84430b8653003f4776489d46

commit r12-9462-g8caf5805ad76125b84430b8653003f4776489d46
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Apr 20 21:02:22 2023 +0100

    libstdc++: Optimize std::try_facet and std::use_facet [PR103755]

    The std::try_facet and std::use_facet functions were optimized in
    r13-3888-gb3ac43a3c05744 to avoid redundant checking for all facets that
    are required to always be present in every locale.

    This performs a simpler version of the optimization that only applies to
    std::ctype<char>, std::num_get<char>, std::num_put<char>, and the
    wchar_t specializations of those facets. Those are the facets that are
    cached by std::basic_ios, which means they're used on construction for
    every iostream object. This smaller change is suitable for the gcc-12
    branch, and mitigates the performance loss for powerpc64le-linux on the
    gcc-12 branch caused by r12-9454-g24cf9f4c6f45f7 for PR 103387. It also
    greatly improves the performance of constructing iostreams objects, for
    all targets.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103755
            * include/bits/locale_classes.tcc (try_facet, use_facet): Do not
            check array index or dynamic type when accessing required
            specializations of std::ctype, std::num_get, or std::num_put.
            * testsuite/22_locale/ctype/is/string/89728_neg.cc: Adjust
            expected errors.

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

* [Bug libstdc++/103387] powerpc64le: segmentation fault on std::cout with ieee128 long double variable
  2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
                   ` (13 preceding siblings ...)
  2023-04-21 15:01 ` cvs-commit at gcc dot gnu.org
@ 2023-04-21 15:03 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-21 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also fixed for 12.3 now.

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

end of thread, other threads:[~2023-04-21 15:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 17:22 [Bug libstdc++/103387] New: powerpc64le: segmentation fault on std::cout with ieee128 long double variable maxiwell at gmail dot com
2021-11-23 18:32 ` [Bug libstdc++/103387] " meissner at gcc dot gnu.org
2021-11-23 21:21 ` redi at gcc dot gnu.org
2021-11-24 22:37 ` tuliom at ascii dot art.br
2022-05-06  8:31 ` jakub at gcc dot gnu.org
2023-03-23 19:01 ` bergner at gcc dot gnu.org
2023-03-28  9:16 ` redi at gcc dot gnu.org
2023-03-28 14:54 ` redi at gcc dot gnu.org
2023-03-28 15:00 ` redi at gcc dot gnu.org
2023-03-28 16:48 ` redi at gcc dot gnu.org
2023-03-28 23:18 ` cvs-commit at gcc dot gnu.org
2023-03-28 23:19 ` redi at gcc dot gnu.org
2023-04-20 13:57 ` cvs-commit at gcc dot gnu.org
2023-04-20 16:38 ` redi at gcc dot gnu.org
2023-04-21 15:01 ` cvs-commit at gcc dot gnu.org
2023-04-21 15:03 ` redi 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).