https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116159
Bug ID: 116159
Summary: undefined symbol: _ZSt21ios_base_library_initv with
mingw/i686+lld
Product: gcc
Version: 14.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: schueller at phimeca dot com
Target Milestone: ---
It would seem the "_ZSt21ios_base_library_initv" symbol from
libstdc++-v3/include/std/iostream is missing one leading underscore for the
i386/windows environment
(it has only one for the itanium c++ ABI):
#if !(_GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE \
&& __has_attribute(__init_priority__))
static ios_base::Init __ioinit;
#elif defined(_GLIBCXX_SYMVER_GNU)
__extension__ __asm (".globl _ZSt21ios_base_library_initv");
#endif
this causes the lld linker to reject the input (but not GNU ld):
#include <fstream>
#include <iostream>
#include <ostream>
int foo() {
std::ofstream file("/tmp/a.log");
return 0;
}
$ i686-w64-mingw32-g++ -fuse-ld=lld foo.cxx -shared -o libfoo.dll
-Wl,--out-implib,libfoo.dll.a
ld.lld: error: undefined symbol: _ZSt21ios_base_library_initv
>>> referenced by /tmp/ccV85ZXq.o
collect2: error: ld returned 1 exit status
see here for my report at lld and the detailed answer
https://github.com/llvm/llvm-project/issues/99286
we see in the actual libs that there are two:
$ i686-w64-mingw32-nm /usr/i686-w64-mingw32/sys-root/mingw/lib/libstdc++.dll.a
| grep _ZSt21ios_base_library_initv
00000000 T __ZSt21ios_base_library_initv
00000000 I __imp___ZSt21ios_base_library_initv
$ i686-w64-mingw32-nm /usr/i686-w64-mingw32/sys-root/mingw/lib/libstdc++.a |
grep _ZSt21ios_base_library_initv
00000000 T __ZSt21ios_base_library_initv
it was suggested that __USER_LABEL_PREFIX__ should be used here,
so I tried patch it with:
diff --git a/libstdc++-v3/include/std/iostream
b/libstdc++-v3/include/std/iostream
index 0c6a2d8a4b3..6bfb7e25271 100644
--- a/libstdc++-v3/include/std/iostream
+++ b/libstdc++-v3/include/std/iostream
@@ -79,7 +79,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __has_attribute(__init_priority__))
static ios_base::Init __ioinit;
#elif defined(_GLIBCXX_SYMVER_GNU)
- __extension__ __asm (".globl _ZSt21ios_base_library_initv");
+ #define XSTRINGIFY(X) STRINGIFY(X)
+ #define STRINGIFY(X) #X
+ __extension__ __asm (".globl " XSTRINGIFY(__USER_LABEL_PREFIX__)
"_ZSt21ios_base_library_initv");
#endif
and that fixed the link step with lld for mingw/i686