From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9CD8E385DC14; Mon, 27 Apr 2020 21:44:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CD8E385DC14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588023892; bh=HBKirR91qqZxJtwGDizGgd/tlYbNvPJzwdJ30yyT6oM=; h=From:To:Subject:Date:From; b=WaCD/Xng7tbetbI7B/M8uIkOgo8H9zIzCCe06A3oD+hIZpnkIyz1i6b7L8Ycj+eOv UR6pR68tYNXi1VvoP/Djv1sPQ5uTl/2/m3JzSYrpeI3IIwT/WUqaLS+kMWyEIOCV6O F9ZJOI/3WkZP+ulBYB9+r6QQUUkbklwcdTGLDZxU= From: "gcasper42 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function Date: Mon, 27 Apr 2020 21:44:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcasper42 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2020 21:44:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94810 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=3D48389&action=3Dedit 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 fau= lt 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.=20 See end for successful build environment. GDB Stacktrace/Useful Output: Program received signal SIGSEGV, Segmentation fault. 0x00007fffff6e661a in std::ostream::sentry::sentry (this=3D0x7ffffffee460, __os=3D...) at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostr= eam.tcc:46 46=20=20=20=20=20 /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostr= eam.tcc: No such file or directory. (gdb) bt #0 0x00007fffff6e661a in std::ostream::sentry::sentry (this=3D0x7ffffffee4= 60, __os=3D...) at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostr= eam.tcc:46 #1 0x00007fffff6e6d4c in std::__ostream_insert > (__out=3D..., __s=3D__s@entry=3D0x8002005 "Starting", __n=3D8) at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostr= eam_insert.h:76 #2 0x00007fffff6e722e in std::operator<< > ( __out=3D..., __s=3D0x8002005 "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=