From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 88C35396EC0E; Thu, 12 Mar 2020 15:05:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88C35396EC0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584025519; bh=ef0Ctgf8/UzZmfSJkW0AXK+3bZ2+flnT2FHgCrVX5NI=; h=From:To:Subject:Date:From; b=jlphvpdEnHfMMF1hwDHjJDh2vFfwisDZYPJMZWa8nxFbM825FQK7EhFfmuL7bDvnv 1kDOQsB8Y3ei44d62I8BREXbJlkTDLcIQ20jID7OydNDv03J/aX0kVOj58rNJZnjfC T3mT5vyoVPAOm9B2lQGkYqOIIG3PNIk01AHwsK8U= From: "michal314314 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug lto/94156] New: Multiple definition of destructor and non-virtual thunk for classes that use multiple inheritance when building static library Date: Thu, 12 Mar 2020 15:05:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 9.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: michal314314 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Mar 2020 15:05:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94156 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=3D48024&action=3Dedit 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\butt= ons && "C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\Buttons.dir\link.txt --verbose=3D1 "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=20 -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[_ZThn20= 8_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[_ZThn20= 8_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[_ZThn20= 8_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=3Dgnu++17 -o CMakeFiles\EmptyStarter.dir\main.c= pp.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 a= nd 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 le= ast 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 minimizi= ng 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=3D47218 - 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 bre= aks 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 fi= les. 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=3DC:\mingw64\mingw64\bin\g++.exe COLLECT_LTO_WRAPPER=3DC:/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=3D/mingw64 --with-local-prefix=3D/mingw64/local --build=3Dx86_64-w64-mingw32 --host=3Dx86_64-w64-mingw32 --target=3Dx86_64-w64-mingw32 --with-native-system-header-dir=3D/mingw64/x86_64-w64-mingw32/include --libexecdir=3D/mingw64/lib --enable-bootstrap --with-arch=3Dx86-64 --with-tune=3Dnocona --enable-languages=3Dc,lto,c++ --enable-shared --enabl= e-static --enable-threads=3Dmcf --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=3Dyes --disable-libstdcxx-pch --disable-libstdcxx-d= ebug --enable-libstdcxx-filesystem-ts=3Dyes --disable-isl-version-check --enable= -lto --enable-libgomp --disable-multilib --enable-checking=3Drelease --disable-r= path --disable-win32-registry --enable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=3D/mingw64 --with-mpfr=3D/min= gw64 --with-mpc=3D/mingw64 --with-isl=3D/mingw64 --with-pkgversion=3D'GCC with M= CF thread model, built by LH_Mouse.' --with-bugurl=3Dhttps://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.=