Bug 486486

Summary: Build fails with LTO
Product: [Applications] kmymoney Reporter: Eli Schwartz <eschwartz93>
Component: buildsystemAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 5.1.3   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.1.4
Sentry Crash Report:
Attachments: build.log

Description Eli Schwartz 2024-05-03 03:19:04 UTC
Created attachment 169124 [details]
build.log

I tried to build with the following *FLAGS to optimize the build: `-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing`

Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.

I got this error:
```
FAILED: bin/kmymoney 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Werror=init-self -Wvla -Wdate-time -Wsuggest-override -Wlogical-op -fdiagnostics-color=always -fexceptions -Wall -Wextra -Wlogical-op -Wno-null-dereference -Wshadow -Wunused -Wno-misleading-indentation -Wsuggest-override -Wcast-qual -Wformat=2 -fno-common -Wl,--enable-new-dtags -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,--as-needed -Wl,--allow-multiple-definition    -Wl,--no-undefined kmymoney/CMakeFiles/kmymoney.dir/kmymoney_autogen/mocs_compilation.cpp.o kmymoney/CMakeFiles/kmymoney.dir/main.cpp.o kmymoney/CMakeFiles/kmymoney.dir/kmymoney.cpp.o kmymoney/CMakeFiles/kmymoney.dir/pluginloader.cpp.o kmymoney/CMakeFiles/kmymoney.dir/kmymoneyadaptor.cpp.o kmymoney/CMakeFiles/kmymoney.dir/qrc_kmymoney.cpp.o -o bin/kmymoney  -Wl,-rpath,/var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3_build/lib:  lib/libviews.a  lib/libkmymoney_base.a  lib/libkmymoney_common.a  lib/libnewuserwizard.a  lib/libnewaccountwizard.a  lib/libnewinvestmentwizard.a  lib/libnewloanwizard.a  lib/libendingbalancedlg.a  lib/libwizardpages.a  lib/libdialogs.a  lib/libwidgets.a  lib/libsettings.a  lib/libconverter.a  lib/libkmm_menus.so.5.1.3  lib/libkmm_widgets.so.5.1.3  lib/libinterfaces.a  /usr/lib64/libQt5WebEngineWidgets.so.5.15.13  /usr/lib64/libQt5WebEngineCore.so.5.15.13  /usr/lib64/libQt5WebChannel.so.5.15.13  lib/libkmm_printer.so.5.1.3  lib/libkmm_models.so.5.1.3  /usr/lib64/libKF5ItemModels.so.5.115.0  /usr/lib64/libKF5Notifications.so.5.115.0  lib/libonlinetask_interfaces.a  lib/libkmymoney_base.a  lib/libkmymoney_common.a  lib/libkmm_settings.so.5.1.3  /usr/lib64/libKF5KIOFileWidgets.so.5.115.0  /usr/lib64/libKF5Bookmarks.so.5.115.0  /usr/lib64/libKF5KIONTLM.so.5.115.0  lib/libkmm_utils_webconnect.a  lib/libkmm_utils_platformtools.a  lib/libnewaccountwizard.a  lib/libkmymoneywizard.a  lib/libkmm_csvimportercore.so.5.1.3  lib/libkmm_mymoney.so.5.1.3  lib/libkmm_plugin.so.5.1.3  lib/libkmm_icons.so.5.1.3  lib/libkmm_payeeidentifier.so.5.1.3  /usr/lib64/libKF5KCMUtils.so.5.115.0  /usr/lib64/libQt5Quick.so.5.15.13  /usr/lib64/libQt5QmlModels.so.5.15.13  /usr/lib64/libQt5Qml.so.5.15.13  /usr/lib64/libKF5XmlGui.so.5.115.0  /usr/lib64/libQt5PrintSupport.so.5.15.13  /usr/lib64/libKF5ItemViews.so.5.115.0  /usr/lib64/libalkimia5.so.8.1.2  /usr/lib64/libKF5TextWidgets.so.5.115.0  /usr/lib64/libKF5SonnetUi.so.5.115.0  /usr/lib64/libKF5KIOWidgets.so.5.115.0  /usr/lib64/libKF5IconThemes.so.5.115.0  /usr/lib64/libKF5ConfigWidgets.so.5.115.0  /usr/lib64/libKF5Codecs.so.5.115.0  /usr/lib64/libKF5Auth.so.5.115.0  /usr/lib64/libKF5Completion.so.5.115.0  /usr/lib64/libKF5ConfigGui.so.5.115.0  /usr/lib64/libKF5KIOGui.so.5.115.0  /usr/lib64/libKF5KIOCore.so.5.115.0  /usr/lib64/libKF5Service.so.5.115.0  /usr/lib64/libKF5I18n.so.5.115.0  /usr/lib64/libKF5ConfigCore.so.5.115.0  /usr/lib64/libKF5AuthCore.so.5.115.0  /usr/lib64/libQt5Network.so.5.15.13  /usr/lib64/libKF5Solid.so.5.115.0  /usr/lib64/libQt5Xml.so.5.15.13  /usr/lib64/libKF5JobWidgets.so.5.115.0  /usr/lib64/libKF5WidgetsAddons.so.5.115.0  /usr/lib64/libKF5CoreAddons.so.5.115.0  /usr/lib64/libQt5Widgets.so.5.15.13  /usr/lib64/libKF5WindowSystem.so.5.115.0  /usr/lib64/libQt5Gui.so.5.15.13  /usr/lib64/libX11.so  /usr/lib64/libQt5DBus.so.5.15.13  /usr/lib64/libQt5Core.so.5.15.13  /usr/lib64/libgmp.so  /usr/lib64/libsqlcipher.so && cd /var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3_build/lib && /usr/bin/cmake -E create_symlink . kmymoney
/var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3/kmymoney/menus/menuenums.h:18:12: error: type ‘eMenu::Action’ violates the C++ One Definition Rule [-Werror=odr]
   18 | enum class Action {
      |            ^
/var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3/kmymoney/dialogs/kcurrencyeditdlg.cpp:55:12: note: an enum with different value name is defined in another translation unit
   55 | enum class Action {
      |            ^
/var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3/kmymoney/menus/menuenums.h:22:5: note: name ‘FileOpenDatabase’ differs from name ‘NewCurrency’ defined in another translation unit
   22 |     FileOpenDatabase, FileSaveAsDatabase, FileBackup,
      |     ^
/var/tmp/portage/app-office/kmymoney-5.1.3/work/kmymoney-5.1.3/kmymoney/dialogs/kcurrencyeditdlg.cpp:59:5: note: mismatching definition
   59 |     NewCurrency, RenameCurrency, DeleteCurrency,
      |     ^
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
```
Originally reported downstream: https://bugs.gentoo.org/865943
Full build log is attached.
Comment 1 Eli Schwartz 2024-05-03 03:20:08 UTC
https://invent.kde.org/office/kmymoney/-/blob/b49b51460c3314562fb88d81a28b58f5637f2b23/kmymoney/dialogs/kcurrencyeditdlg.cpp#L51

```
// duplicated eMenu namespace from menuenums.h for consistency
// there shouldn't be any clash, because we don't need menuenums.h here
namespace eMenu {
enum class Action {
    // *************
    // The currency menu
    // *************
    NewCurrency, RenameCurrency, DeleteCurrency,
    SetBaseCurrency,
```

no clash?
Comment 2 Thomas Baumgart 2024-05-03 13:43:20 UTC
Which version of the compiler are you using (I assume it's g++)?
Comment 3 Eli Schwartz 2024-05-03 13:48:05 UTC
Per the cmake configure output in the attached log:

```
-- The CXX compiler identification is GNU 13.2.1
-- Detecting CXX compiler ABI info
```
Comment 4 Thomas Baumgart 2024-05-03 16:31:26 UTC
Git commit eef04f1e9dc9f765ec74320008f095870e16a537 by Thomas Baumgart.
Committed on 03/05/2024 at 16:30.
Pushed by tbaumgart into branch '5.1'.

Avoid violation of the C++ One Definition Rule
FIXED-IN: 5.1.4

M  +7    -21   kmymoney/dialogs/kcurrencyeditdlg.cpp
M  +9    -23   kmymoney/dialogs/kmymoneypricedlg.cpp
M  +10   -0    kmymoney/menus/menuenums.h

https://invent.kde.org/office/kmymoney/-/commit/eef04f1e9dc9f765ec74320008f095870e16a537
Comment 5 Thomas Baumgart 2024-05-03 16:47:00 UTC
Git commit 726e6b82ac1e6182de574ed5e0c12b7cfcd74441 by Thomas Baumgart.
Committed on 03/05/2024 at 16:46.
Pushed by tbaumgart into branch 'master'.

Avoid violation of the C++ One Definition Rule

(cherry picked from commit eef04f1e9dc9f765ec74320008f095870e16a537)

M  +7    -22   kmymoney/dialogs/kcurrencyeditdlg.cpp
M  +1    -16   kmymoney/dialogs/kmymoneypricedlg.cpp
M  +10   -0    kmymoney/menus/menuenums.h

https://invent.kde.org/office/kmymoney/-/commit/726e6b82ac1e6182de574ed5e0c12b7cfcd74441