public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
@ 2020-03-12 15:05 michal314314 at gmail dot com
  2020-03-12 18:16 ` [Bug lto/94156] " michal314314 at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: michal314314 at gmail dot com @ 2020-03-12 15:05 UTC (permalink / raw)
  To: gcc-bugs

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 symbols across different translation units.

I have made sample commits which reproduce this issue on this repo:
https://github.com/Xeverous/elements/

- branch "radio-button-build-debug-1": first commit in the library that breaks
the build
- branches "lto-debug-2" and branch "lto-debug-3": I removed some library's
dependencies, pasted their headers to the library repo and reduced CMake files.
This makes the build to have a ton of undefined references when linking
executables, but the problematic multiple definitions appear too. Perhaps I
could reduce dependencies even more if someone wants a such repo for
reproduction uses.

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 -v
GNU ld (GNU Binutils) 2.33.1

Attaching compressed main.ii from the smallest library example.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/94156] Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
  2020-03-12 15:05 [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library michal314314 at gmail dot com
@ 2020-03-12 18:16 ` michal314314 at gmail dot com
  2020-10-17  8:52 ` pavel51tunin at gmail dot com
  2020-10-17 15:04 ` michal314314 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: michal314314 at gmail dot com @ 2020-03-12 18:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156

--- Comment #1 from Michał Urbański <michal314314 at gmail dot com> ---
This discussion looks related:
https://gcc.gnu.org/legacy-ml/gcc/2003-09/msg00984.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/94156] Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
  2020-03-12 15:05 [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library michal314314 at gmail dot com
  2020-03-12 18:16 ` [Bug lto/94156] " michal314314 at gmail dot com
@ 2020-10-17  8:52 ` pavel51tunin at gmail dot com
  2020-10-17 15:04 ` michal314314 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pavel51tunin at gmail dot com @ 2020-10-17  8:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156

Павел Тюнин <pavel51tunin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pavel51tunin at gmail dot com

--- Comment #2 from Павел Тюнин <pavel51tunin at gmail dot com> ---
Created attachment 49391
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49391&action=edit
minimal sample to reproduce the bug

This sample triggers this or similar bug on both mingw 9.2.0 and mingw-w64
10.2.1. Compilation log:
D:\test>g++ -O2 -flto -c test1.cpp

D:\test>g++ -O2 -flto -c test2.cpp

D:\test>g++ -flto -o test.exe test1.o test2.o
D:/mingw-w64/mingw/bin/../lib/gcc/i686-w64-mingw32/10.2.1/../../../../i686-w64-m
ingw32/bin/ld.exe: test2.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3foo
Ev[__ZThn4_N7Derived3fooEv]+0x0): multiple definition of `Derived::foo()';
test1
.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3fooEv[__ZThn8_N7Derived3foo
Ev]+0x0): first defined here
D:/mingw-w64/mingw/bin/../lib/gcc/i686-w64-mingw32/10.2.1/../../../../i686-w64-m
ingw32/bin/ld.exe: test2.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3foo
Ev[__ZThn4_N7Derived3fooEv]+0x0): multiple definition of `non-virtual thunk to
D
erived::foo()'; test1.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3fooEv[
__ZThn8_N7Derived3fooEv]+0x0): first defined here
D:/mingw-w64/mingw/bin/../lib/gcc/i686-w64-mingw32/10.2.1/../../../../i686-w64-m
ingw32/bin/ld.exe: test2.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3foo
Ev[__ZThn4_N7Derived3fooEv]+0x0): multiple definition of `non-virtual thunk to
D
erived::foo()'; test1.o (symbol from
plugin):(.gnu.linkonce.t._ZN7Derived3fooEv[
__ZThn8_N7Derived3fooEv]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/94156] Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library
  2020-03-12 15:05 [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library michal314314 at gmail dot com
  2020-03-12 18:16 ` [Bug lto/94156] " michal314314 at gmail dot com
  2020-10-17  8:52 ` pavel51tunin at gmail dot com
@ 2020-10-17 15:04 ` michal314314 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: michal314314 at gmail dot com @ 2020-10-17 15:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156

--- Comment #3 from Michał Urbański <michal314314 at gmail dot com> ---
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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-17 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 15:05 [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library michal314314 at gmail dot com
2020-03-12 18:16 ` [Bug lto/94156] " michal314314 at gmail dot com
2020-10-17  8:52 ` pavel51tunin at gmail dot com
2020-10-17 15:04 ` michal314314 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).