From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2B16A3851C01; Tue, 28 Apr 2020 20:52:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B16A3851C01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588107162; bh=wdD2puRSigA5BM0Rok7BGY/RYMWJrtFUVGJDkPMbx9M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SgsbEoq6Zlu2Xk2bgwiXhxw9544QeSXNbxg87FTG7WnJaBUxZd3PfoFd4c6wyLsU4 5+P3ouX0dLF14kJSN9dH4wR/raC7jY1Pie+dg0vyi5y/RoXGcqEPoY4s8pEr63xjzr DU4W4TzGGm0HcgrUI08E+7NQ6mBLq4GPsW/WtqJQ= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function Date: Tue, 28 Apr 2020 20:52:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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_status resolution Message-ID: In-Reply-To: References: 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: Tue, 28 Apr 2020 20:52:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94810 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #8 from Jonathan Wakely --- No. The ambiguity only happens if you use the attribute explicitly, as you = are doing. Just create a global object with a constructor and a destructor, instead of using functions with __attribute__((constructor)) and __attribute__((destructor)). #include struct X { X() { std::cout << "Starting" << std::endl; } ~X() { std::cout << "Finishing" << std::endl; } }; int main() { std::cout << "Hello, World!" << std::endl; } I'm closing this as invalid, since the attribute is documented to have unspecified construction order relative to normal globals, which means your original example is not expected to work.=