ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Bug] Builds fail with LTO

Open jonathanspw opened this issue 1 year ago • 4 comments

Operating System

Linux

What's the issue you encountered?

Builds fail with LTO flags enabled (-flto=auto -ffat-lto-objects).

https://koji.fedoraproject.org/koji/watchlogs?taskID=90242911

Confirmed on Fedora and ArchLinux.

How can the issue be reproduced?

Build from source using -flto=auto -ffat-lto-objects flags.

ImHex Version

1.19.3

ImHex Build Type

  • [ ] Nightly or built from sources

Additional context?

Context/discussion from discord: https://discord.com/channels/789833418631675954/789833418631675957/1003044011885477978

jonathanspw avatar Jul 30 '22 21:07 jonathanspw

State of things : (what I think I understood)

Linux : gcc+lto+lld is not supported, and mold will only support gcc+lto with gcc 13.1 see https://bugs.llvm.org/show_bug.cgi?id=42446 and https://github.com/rui314/mold/issues/181#issuecomment-1266574026

if we do not use lld, we have an error

/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource1_size'
/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource0_size'
/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource2'
/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource2_size'
/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource0'
/usr/bin/ld: ../lib/libimhex/libimhex.so.1.24.3: undefined reference to `resource1'

The error seems to happen because of LTO between libimhex and the lib target of libromfs. It can be fixed by adding set_target_properties(${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) to that target (see https://github.com/iTrooz/libromfs/commit/429693e6e10db5c605782d332a7eb54953587569), but the Fedora build will still fail because it forces the option by adding -flto=auto globally with CMAKE_CXX_FLAGS

Windows : quite the same issue as Linux, but I didn't investigate as much

MacOS : seems to need a "linker plugin" to support LTO with gcc. Once again did not investigate much as I do not have a Mac

For now I will stop investigating this. Anyone willing to look at it is welcome :)

iTrooz avatar Oct 14 '22 09:10 iTrooz

As of 1.25.0 I think this can be marked resolved :)

jonathanspw avatar Nov 15 '22 14:11 jonathanspw

Yay !

I'd like to keep this issue open for Windows and MacOS, do you mind to unsubscribe if you do not want to keep track of it ?

iTrooz avatar Nov 15 '22 14:11 iTrooz

Sounds good to me.

jonathanspw avatar Nov 15 '22 14:11 jonathanspw