public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "sascha.scandella at dentsplysirona dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-110432-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110432 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 that 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 documentation 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 using clang-16 in combination with stdlibc++. Sample application: #include <iostream> int main() { std::cout << "Hello" << std::endl; } $HOMEBREW_PREFIX/opt/llvm@16/bin/clang++ \ -v \ -stdlib=libstdc++ \ -stdlib++-isystem $HOMEBREW_PREFIX/opt/gcc@13/include/c++/13 \ -cxx-isystem $HOMEBREW_PREFIX/opt/gcc@13/include/c++/13/x86_64-apple-darwin22 \ -L $HOMEBREW_PREFIX/opt/gcc@13/lib/gcc/13/ \ -L $HOMEBREW_PREFIX/opt/llvm/lib \ -o test main.cpp Execute test -> segfault. ➜ ~ ./test [1] 7965 segmentation fault ./test Would it be possible to change the #if statement such that it would also work 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=gcc-13 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-apple-darwin22/13/lto-wrapper Target: x86_64-apple-darwin22 Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 13.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin22 --with-sysroot=/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) OS: macOS Ventura 13.4 (Intel)
next reply other threads:[~2023-06-27 9:56 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-27 9:56 sascha.scandella at dentsplysirona dot com [this message] 2023-06-27 10:27 ` [Bug libstdc++/110432] " redi at gcc dot gnu.org 2023-06-27 10:32 ` sascha.scandella at dentsplysirona dot com 2023-06-27 10:46 ` iains at gcc dot gnu.org 2023-06-27 10:50 ` sascha.scandella at dentsplysirona dot com 2023-06-27 11:05 ` iains at gcc dot gnu.org 2023-06-27 12:08 ` sascha.scandella at dentsplysirona dot com 2023-06-27 12:09 ` redi at gcc dot gnu.org 2023-06-29 15:54 ` sascha.scandella at dentsplysirona dot com 2023-06-29 16:09 ` ppalka at gcc dot gnu.org 2023-06-29 16:12 ` iains at gcc dot gnu.org 2023-06-29 16:28 ` redi at gcc dot gnu.org 2023-06-30 14:37 ` cvs-commit at gcc dot gnu.org 2023-06-30 15:19 ` sascha.scandella at dentsplysirona dot com 2023-06-30 15:25 ` jakub at gcc dot gnu.org 2023-07-01 14:11 ` sascha.scandella at dentsplysirona dot com 2023-07-19 19:35 ` cvs-commit at gcc dot gnu.org 2023-07-19 19:36 ` redi at gcc dot gnu.org 2023-07-20 11:58 ` redi at gcc dot gnu.org 2023-08-07 13:04 ` sascha.scandella at dentsplysirona dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110432-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).