Skip to content

Commit 2003f89

Browse files
committed
libstdc++: Only use std::ios_base_library_init() for ELF [PR116159]
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. (cherry picked from commit fc7a1fb)
1 parent d5d6d3f commit 2003f89

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

libstdc++-v3/include/std/iostream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
7878
#if !(_GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE \
7979
&& __has_attribute(__init_priority__))
8080
static ios_base::Init __ioinit;
81-
#elif defined(_GLIBCXX_SYMVER_GNU)
81+
#elif defined(_GLIBCXX_SYMVER_GNU) && defined(__ELF__)
8282
__extension__ __asm (".globl _ZSt21ios_base_library_initv");
8383
#endif
8484

libstdc++-v3/src/c++98/ios_init.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
199199
return __ret;
200200
}
201201

202-
#ifdef _GLIBCXX_SYMVER_GNU
202+
#if defined(_GLIBCXX_SYMVER_GNU) && defined(__ELF__)
203203
#pragma GCC diagnostic ignored "-Wattribute-alias"
204204

205205
void ios_base_library_init (void)

0 commit comments

Comments
 (0)