]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Only use std::ios_base_library_init() for ELF [PR116159]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 Sep 2024 13:36:26 +0000 (14:36 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 Sep 2024 17:23:30 +0000 (18:23 +0100)
The undefined std::ios_base_library_init() symbol that is referenced by
<iostream> is only supposed to be used for targets where symbol
versioning is supported.

The mingw-w64 target defaults to --enable-symvers=gnu due to using GNU
ld but doesn't actually support symbol versioning. This means it tries
to emit references to the std::ios_base_library_init() symbol, which
isn't really defined in the library. This causes problems when using lld
to link user binaries.

Disable the undefined symbol reference for non-ELF targets.

libstdc++-v3/ChangeLog:

PR libstdc++/116159
* include/std/iostream (ios_base_library_init): Only define for
ELF targets.
* src/c++98/ios_init.cc (ios_base_library_init): Likewise.

libstdc++-v3/include/std/iostream
libstdc++-v3/src/c++98/ios_init.cc

index 4f4fa6880d572b77538a3775df782720b6740c61..4a6dc584d38a100388120deeb4d71f23d8137f51 100644 (file)
@@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if !(_GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE \
       && __has_attribute(__init_priority__))
   static ios_base::Init __ioinit;
-#elif defined(_GLIBCXX_SYMVER_GNU)
+#elif defined(_GLIBCXX_SYMVER_GNU) && defined(__ELF__)
   __extension__ __asm (".globl _ZSt21ios_base_library_initv");
 #endif
 
index 1422e20d940500e92eb34d19c59592a8c3927754..6e2e5014cf0fc94b5d84df5c9ec5a1e8ef90e303 100644 (file)
@@ -199,7 +199,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     return __ret;
   }
 
-#ifdef _GLIBCXX_SYMVER_GNU
+#if defined(_GLIBCXX_SYMVER_GNU) && defined(__ELF__)
 #pragma GCC diagnostic ignored "-Wattribute-alias"
 
   void ios_base_library_init (void)