Bug #2472
Build errors with LTO (Gentoo)
0%
Description
(via Eli Schwartz)
Gentoo Linux has been recently working on trying to get the entire
package tree LTO-clean, as users often want to enable LTO to speed up
their system and we want to make sure it is safe to do so.
I tried to build with the following *FLAGS to test that this works ok:
`-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 while building the file apps/plugins/hexen/libhexen.so:
FAILED: apps/plugins/hexen/libhexen.so : && ccache /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -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 -std=c++11 -Wno-deprecated-copy -Wno-class-memaccess -Wno-address-of-packed-member -DDENG_NO_RANGECHECKING -fno-tree-fre -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -shared -o apps/plugins/hexen/libhexen.so apps/plugins/hexen/CMakeFiles/hexen.dir/hexen_autogen/mocs_compilation.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/a_action.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/acfnlink.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/h2_main.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/hconsole.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/hrefresh.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/intermission.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/lightninganimator.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/m_cheat.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/m_random.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_enemy.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_inter.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_lights.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_maputl.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_mobj.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_pillar.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_pspr.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_setup.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_spec.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_telept.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_things.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/p_waggle.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/sn_sonix.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/st_stuff.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/tables.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/src/x_api.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_hud_widgets_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/animdefs.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/common.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/fi_lib.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/g_controls.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/gl_drawpatch.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/gl_special.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hexlex.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_inventory.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_lib.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_menu.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_msg.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_pspr.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hu_stuff.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/m_ctrl.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_inventory.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_iterlist.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_saveg.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_saveio.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_terraintype.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_user.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/p_view.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/r_common.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/r_special.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/x_hair.c.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hud/automapstyle.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/hud/hudwidget.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/__/common/src/menu/page.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_acs_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_game_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_hud_widgets_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_menu_widgets_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_network_turbo.cpp.o apps/plugins/hexen/CMakeFiles/hexen.dir/src_common_world_turbo.cpp.o -Wl,-rpath,/var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/libdoomsday:/var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/plugins/libgamefw:/var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/sdk/libshell:/var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/sdk/liblegacy:/var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/sdk/libcore: apps/libdoomsday/libdeng_doomsday.so.2.3.1 apps/plugins/libgamefw/libdeng_gamefw.so.2.3.1 sdk/libshell/libdeng_shell.so.2.3.1 sdk/liblegacy/libdeng_legacy.so.2.3.1 sdk/libcore/libdeng_core.so.2.3.1 /usr/lib64/libQt5Network.so.5.15.12 /usr/lib64/libQt5Core.so.5.15.12 -lz && : /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:45:8: error: type ‘struct Interpreter’ violates the C++ One Definition Rule [-Werror=odr] 45 | struct Interpreter | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:45:8: note: a different type is defined in another translation unit 45 | struct Interpreter | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:51:13: note: the first difference of corresponding definitions is field ‘_script’ 51 | Script *_script; | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:51:13: note: fields have different layout in another translation unit 51 | Script *_script; | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:77:9: error: type of ‘read’ does not match original declaration [-Werror=lto-type-mismatch] 77 | int read(MapStateReader *msr); | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/plugins/hexen/src_common_acs_turbo.cpp:913:5: note: ‘read’ was previously declared here 913 | int Interpreter::read(MapStateReader *msr) { | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/plugins/hexen/src_common_acs_turbo.cpp:913:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday/apps/plugins/common/include/acs/interpreter.h:82:10: error: type of ‘write’ does not match original declaration [-Werror=lto-type-mismatch] 82 | void write(MapStateWriter *msw) const; | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/plugins/hexen/src_common_acs_turbo.cpp:896:6: note: ‘write’ was previously declared here 896 | void Interpreter::write(MapStateWriter *msw) const { | ^ /var/tmp/portage/games-fps/doomsday-2.3.1/work/doomsday-2.3.1/doomsday_build/apps/plugins/hexen/src_common_acs_turbo.cpp:896:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used 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 ninja: build stopped: subcommand failed.
Originally reported downstream at https://bugs.gentoo.org/858743
A full build log is attached.