public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function
@ 2020-04-27 21:44 gcasper42 at gmail dot com
  2020-04-27 22:32 ` [Bug libstdc++/94810] " redi at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: gcasper42 at gmail dot com @ 2020-04-27 21:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94810
           Summary: std::cout segmentation fault in
                    __attribute__((constructor)) function
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcasper42 at gmail dot com
  Target Milestone: ---

Created attachment 48389
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48389&action=edit
Code to reproduce bug

Exact Version of GCC:
g++ (Arch Linux 9.3.0-1) 9.3.0

System Type:
Arch Linux (under Windows Subsystem for Linux 1)

The attached code compiles and runs, but runs into a seg fault. The seg fault
occurs when trying to print using std::cout in my function marked with the
__attribute__((constructor)), but when I instead use printf to print there is
no seg fault. 

See end for successful build environment.

GDB Stacktrace/Useful Output:

Program received signal SIGSEGV, Segmentation fault.
0x00007fffff6e661a in std::ostream::sentry::sentry (this=0x7ffffffee460,
    __os=...)
    at
/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:46
46     
/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:
No such file or directory.

(gdb) bt
#0  0x00007fffff6e661a in std::ostream::sentry::sentry (this=0x7ffffffee460,
    __os=...)
    at
/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:46
#1  0x00007fffff6e6d4c in std::__ostream_insert<char, std::char_traits<char> >
(__out=..., __s=__s@entry=0x8002005 "Starting", __n=8)
    at
/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:76
#2  0x00007fffff6e722e in std::operator<< <std::char_traits<char> > (
    __out=..., __s=0x8002005 "Starting")
    at
/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:335
#3  0x0000000008001180 in constructor () at test.cpp:4
#4  0x00000000080012ad in __libc_csu_init ()
#5  0x00007fffff2b6fb0 in __libc_start_main () from /usr/lib/libc.so.6
#6  0x000000000800109e in _start ()

Something weird to mention (other build environment):

While using the below build environment, the attached code runs as expected.

Exact Version of GCC:
g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

System Type:
MinGW-W64 Windows 10

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

end of thread, other threads:[~2023-02-06  4:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
2020-04-27 22:32 ` [Bug libstdc++/94810] " redi at gcc dot gnu.org
2020-04-27 23:41 ` gcasper42 at gmail dot com
2020-04-28  8:51 ` redi at gcc dot gnu.org
2020-04-28 13:16 ` gcasper42 at gmail dot com
2020-04-28 16:07 ` redi at gcc dot gnu.org
2020-04-28 16:09 ` redi at gcc dot gnu.org
2020-04-28 17:39 ` gcasper42 at gmail dot com
2020-04-28 20:52 ` redi at gcc dot gnu.org
2023-02-03 19:29 ` murugesandins at gmail dot com
2023-02-03 19:47 ` pinskia at gcc dot gnu.org
2023-02-03 22:04 ` murugesandins at gmail dot com
2023-02-04  3:22 ` murugesandins at gmail dot com
2023-02-06  4:41 ` murugesandins at gmail dot com

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