https://sourceware.org/bugzilla/show_bug.cgi?id=24267
Bug ID: 24267 Summary: ld discard a symbol with -flto and -static Product: binutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: marxin.liska at gmail dot com Target Milestone: --- This is follow up of: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81879 $ cat simpler.ii namespace std { template <class> struct char_traits; template <typename a, typename = char_traits<a>> class basic_ostream; typedef basic_ostream<char> b; class ios_base { public: class Init { public: Init(); }; }; template <typename> class ctype { virtual char do_widen(char c) const { return c; } }; class d { ctype<char> e; }; template <typename, typename> class basic_ostream : d {}; template <class f> basic_ostream<char, f> &operator<<(basic_ostream<char, f> &, const char *); b cout; ios_base::Init g; } // namespace std int main() { std::cout << "ok"; } When compiler with: $ x86_64-w64-mingw32-g++ -v Using built-in specs. COLLECT_GCC=x86_64-w64-mingw32-g++ COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-w64-mingw32/8.2.0/lto-wrapper Target: x86_64-w64-mingw32 Configured with: ../configure --prefix=/usr --bindir=/usr/bin --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib64 --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --build=x86_64-suse-linux-gnu --host=x86_64-suse-linux-gnu --target=x86_64-w64-mingw32 --with-gnu-as --with-gnu-ld --verbose --without-newlib --disable-multilib --enable-shared --disable-plugin --with-system-zlib --disable-nls --without-included-gettext --disable-win32-registry --enable-threads=posix --enable-version-specific-runtime-libs --with-sysroot=/usr/x86_64-w64-mingw32/sys-root --enable-languages=c,c++,fortran,objc,obj-c++ --without-x --enable-hash-synchronization --enable-fully-dynamic-string --enable-libgomp --enable-linker-build-id --disable-vtable-verify --with-pkgversion='SUSE Linux' Thread model: posix gcc version 8.2.0 (SUSE Linux) $ x86_64-w64-mingw32-g++ simpler.ii -flto -O2 -static --save-temps --verbose ... $ cat simpler.res 1 simpler.o 10 257 4b7905b9947ad39f PREEMPTED_REG _ZNKSt5ctypeIcE8do_widenEc 260 4b7905b9947ad39f PREVAILING_DEF main 279 4b7905b9947ad39f PREEMPTED_REG _ZSt4cout 282 4b7905b9947ad39f PREVAILING_DEF_IRONLY _ZSt1g 291 4b7905b9947ad39f PREEMPTED_REG _ZTSSt5ctypeIcE 305 4b7905b9947ad39f PREEMPTED_REG _ZTISt5ctypeIcE 207 4b7905b9947ad39f PREEMPTED_REG _ZTVSt5ctypeIcE 316 4b7905b9947ad39f RESOLVED_EXEC _ZTVN10__cxxabiv117__class_type_infoE 271 4b7905b9947ad39f RESOLVED_EXEC _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 276 4b7905b9947ad39f RESOLVED_EXEC _ZNSt8ios_base4InitC1Ev as seen _ZNKSt5ctypeIcE8do_widenEc is both defined in the static libstdc++ and simpler.ii. Linker tells to not to emit assembly for the symbol. However we then end up with a binary where the symbol is missing: $ x86_64-w64-mingw32-nm a.exe | grep _ZNKSt5ctypeIcE8do_widenEc 0000000000acda70 N .debug_frame$_ZNKSt5ctypeIcE8do_widenEc 00000000004b9150 p .pdata$_ZNKSt5ctypeIcE8do_widenEc 00000000004c51b4 r .xdata$_ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc U _ZNKSt5ctypeIcE8do_widenEc Which is causing wine crash: wine a.exe wine: Unhandled page fault on read access to 0x00000000 at address 0x4a3a2e (thread 002b), starting debugger... So I suspect ld.bfd for not copying the _ZNKSt5ctypeIcE8do_widenEc from static libstdc++: $ x86_64-w64-mingw32-nm /usr/lib64/gcc/x86_64-w64-mingw32/8.2.0/libstdc++.dll.a | grep _ZNKSt5ctypeIcE8do_widenEc 0000000000000000 I __imp__ZNKSt5ctypeIcE8do_widenEc 0000000000000000 T _ZNKSt5ctypeIcE8do_widenEc If needed I can upload somewhere libstdc++.dll.a file. -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils