[Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156 Bug ID: 94156 Summary: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: michal314314 at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- Created attachment 48024 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48024&action=edit main.ii from the example Following linker errors appear when creating the final executable: cd /d D:\Files\C++\workspace_windows\elements_fork\build_fork\examples\buttons && "C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\Buttons.dir\link.txt --verbose=1 "C:\Program Files\CMake\bin\cmake.exe" -E remove -f CMakeFiles\Buttons.dir/objects.a C:\mingw64\mingw64\bin\gcc-ar.exe cr CMakeFiles\Buttons.dir/objects.a @CMakeFiles\Buttons.dir\objects1.rsp C:\mingw64\mingw64\bin\g++.exe -O3 -DNDEBUG -flto -fno-fat-lto-objects -mwindows -Wl,--whole-archive CMakeFiles\Buttons.dir/objects.a -Wl,--no-whole-archive -o Buttons.exe -Wl,--out-implib,libButtons.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\Buttons.dir\linklibs.rsp C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `non-virtual thunk to cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `non-virtual thunk to cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here collect2.exe: error: ld returned 1 exit status Build command (generated by CMake): C:\mingw64\mingw64\bin\g++.exe -DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_UNICODE @CMakeFiles/EmptyStarter.dir/includes_CXX.rsp -O3 -DNDEBUG -flto -fno-fat-lto-objects -std=gnu++17 -o CMakeFiles\EmptyStarter.dir\main.cpp.obj -c C:\files\personal\repos\elements\examples\empty\main.cpp My observations so far: - This is not an ODR violation problem. I have verified no classes got accidental duplicate definitions or duplicate source files. - There is no diamond inheritance in the project. - The problem does not occur when building elements as a shared library. It occurs when I build elements as a static library and then try to link any executable (including ones from its examples directory or my external projects). - The problem occurs in CMake Release build type - The problem does not occur when LTO is not enabled - The only multiple reference errors I get are definitions of destructors and non-virtual thunks for classes that use multiple inheritance. Removing such classes or changing their inheritance to be linear results in successful linking. - The problem only reproduces on Windows but it does reproduce across at least 2 MinGW distributions and across many GCC versions (tried multiple ones in range 8.3 - 9.2.1) - The problem does not reproduce on smaller examples. I have tried minimizing the repository to only affected classes but then the issue does not appear. Apparently optimization-related problems manifest only with certain code path/size. What I suspect: - The issue looks similarly to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47218 - This looks like a bug in linker/LTO because symbols from the LTO plugin contain "gnu.linkonce" which sounds like a weak symbol mechanism that is similar to how C++ templates are expected to possibly contain duplicate instantations and sym
[Bug lto/94156] Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156 --- Comment #1 from Michał Urbański --- This discussion looks related: https://gcc.gnu.org/legacy-ml/gcc/2003-09/msg00984.html
[Bug lto/94776] New: lto1: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:153
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94776 Bug ID: 94776 Summary: lto1: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:153 Product: gcc Version: lto Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: michal314314 at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- The setup and projects being compiled are the same as in bug 94156 (just newer commits), however this time instead of getting linker symbol-related errors the linker crashes. link command: C:\mingw64\mingw64\bin\gcc-ar.exe cr CMakeFiles\filter_spirit_gui.dir/objects.a CMakeFiles/filter_spirit_gui.dir/main.cpp.obj C:\mingw64\mingw64\bin\g++.exe -O3 -DNDEBUG -flto -fno-fat-lto-objects -Wl,--whole-archive CMakeFiles\filter_spirit_gui.dir/objects.a -Wl,--no-whole-archive -o ..\..\bin\filter_spirit_gui.exe -Wl,--out-implib,..\..\bin\libfilter_spirit_gui.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -LC:/usr/include/../bin ../../bin/libfilter_spirit.dll.a ../../bin/libelements.a C:/mingw64/mingw64/lib/libssl.dll.a C:/mingw64/mingw64/lib/libboost_filesystem-mt.dll.a -lcurl -latomic C:/usr/lib/libcairo.dll.a C:/usr/lib/libfontconfig.dll.a C:/usr/lib/libfreetype.dll.a C:/usr/lib/libpng16.dll.a C:/mingw64/mingw64/lib/libz.dll.a C:/mingw64/mingw64/lib/libbz2.dll.a -lpthread -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 Full output: lto1.exe: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:153 libbacktrace could not find executable to open Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc-mcf.lhmouse.com/> for instructions. My toolchain: $ g++ -v Using built-in specs. COLLECT_GCC=C:\mingw64\mingw64\bin\g++.exe COLLECT_LTO_WRAPPER=C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-git/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=nocona --enable-languages=c,lto,c++ --enable-shared --enable-static --enable-threads=mcf --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-libstdcxx-filesystem-ts=yes --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --enable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='GCC with MCF thread model, built by LH_Mouse.' --with-bugurl=https://gcc-mcf.lhmouse.com/ --with-gnu-as --with-gnu-ld --disable-tls --enable-plugin Thread model: mcf gcc version 9.2.1 20200225 (GCC with MCF thread model, built by LH_Mouse.) $ ld --version GNU ld (GNU Binutils) 2.33.1 $ cmake --version cmake version 3.16.4 I have successfuly used -save-temps option but unfortunately both created temporary files are huge (main.s is 1.5MB, main.ii is 7.2MB) which is beyond allowed attachment size. This issue is hard to reproduce on different commits (probably due to all optimizations taking place) and only appears when link time optimization is used. Please guide me if I can help in any way with reproducing this problem. Right now it happens on a small hello world main.cpp that uses 2 libraries, but unfortunately both use a ton of boost which significantly increases the amount of actual code in the compiled translation unit.
[Bug lto/94156] Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156 --- Comment #3 from Michał Urbański --- I confirm that attached test files reproduce the bug for me - same error messages. Thanks Pavel, never expeced someone to manage to reproduce this problem.