From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 561313858C36; Tue, 27 Jun 2023 09:56:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 561313858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687859781; bh=1Jp9YD14EmrkZ8zYRBRlVkFjWzvTJbZRCD39q1pc5VE=; h=From:To:Subject:Date:From; b=a/DNNYSKlnWd/0VYUTf/PJ8c1+5gcfyXlzaCrsrAaf/xO0Wbylf/G68HdWj0mU1yT LbzGCXbY5yfVRoO7Ac7c4FPzYR/QI6cylrAfkGfb3nm9TzVar861ittNZlvRQrAdN/ 3fiol4qx9AtR+IVstlh7z++qJqDBA+RCNGGOuO/4= From: "sascha.scandella at dentsplysirona dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110432] New: macOS: Segmentation fault when using stdlibc++ from gcc 13.1 in combination with clang-16 Date: Tue, 27 Jun 2023 09:56:19 +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: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sascha.scandella at dentsplysirona 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110432 Bug ID: 110432 Summary: macOS: Segmentation fault when using stdlibc++ from gcc 13.1 in combination with clang-16 Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: sascha.scandella at dentsplysirona dot com Target Milestone: --- As you certainly all know GCC has changed the way how the global iostream objects are created since gcc 13.1. This can be found on the official page. "For C++, construction of the global iostream objects std::cout, std::cin, = etc. is now done inside the standard library, instead of in every source file th= at includes the header. This change improves the start-up performance of C++ programs, but it means that code compiled with GCC 13.1 will crash if the correct version of libstdc++.so is not used at runtime. See the documentati= on about using the right libstdc++.so at runtime. Future GCC releases will mitigate the problem so that the program cannot be run at all with an older libstdc++.so." More details can also be found here: https://developers.redhat.com/articles/2023/04/03/leaner-libstdc-gcc-13 On macOS SUPPORTS_INIT_PRIORITY within gcc is set to 0. This means that the global iostream object is not initialized and the fallback will be taken (i= .e. static initialization of the iostream object). The problem is that when the iostream include is used, the expression __has_attribute(__init_priority__) is true, since clang-16 supports __init_priority__ and the static initialization is not done. See here: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/= iostream#L78 This leads to a segmentation fault with a simple sample application when us= ing clang-16 in combination with stdlibc++. Sample application: #include int main() { std::cout << "Hello" << std::endl; } $HOMEBREW_PREFIX/opt/llvm@16/bin/clang++ \ -v \ -stdlib=3Dlibstdc++ \ -stdlib++-isystem $HOMEBREW_PREFIX/opt/gcc@13/include/c++/13 \ -cxx-isystem $HOMEBREW_PREFIX/opt/gcc@13/include/c++/13/x86_64-apple-darw= in22 \ -L $HOMEBREW_PREFIX/opt/gcc@13/lib/gcc/13/ \ -L $HOMEBREW_PREFIX/opt/llvm/lib \ -o test main.cpp Execute test -> segfault. =E2=9E=9C ~ ./test [1] 7965 segmentation fault ./test Would it be possible to change the #if statement such that it would also wo= rk on macOS when using clang in combination with the stdlibc++? #if !__has_attribute(__init_priority__) static ios_base::Init __ioinit; #elif defined(_GLIBCXX_SYMVER_GNU) __extension__ __asm (".globl _ZSt21ios_base_library_initv"); #endif Remarks: When compiling with gcc everything works as expected since the iostream object gets initialized properly with the fallback. gcc -v Using built-in specs. COLLECT_GCC=3Dgcc-13 COLLECT_LTO_WRAPPER=3D/usr/local/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_6= 4-apple-darwin22/13/lto-wrapper Target: x86_64-apple-darwin22 Configured with: ../configure --prefix=3D/usr/local/opt/gcc --libdir=3D/usr/local/opt/gcc/lib/gcc/current --disable-nls --enable-checking=3Drelease --with-gcc-major-version-only --enable-languages=3Dc,c++,objc,obj-c++,fortran --program-suffix=3D-13 --with-gmp=3D/usr/local/opt/gmp --with-mpfr=3D/usr/local/opt/mpfr --with-mpc=3D/usr/local/opt/libmpc --with-isl=3D/usr/local/opt/isl --with-zstd=3D/usr/local/opt/zstd --with-pkgversion=3D'Homebrew GCC 13.1.0' --with-bugurl=3Dhttps://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=3Dx86_64-apple-darwin22 --with-sysroot=3D/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.1.0 (Homebrew GCC 13.1.0)=20 OS: macOS Ventura 13.4 (Intel)=