Skip to content

Build fails with LTO

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:

x86_64-pc-linux-gnu-gcc '-DICKINCLUDEDIR="/usr/include/ick-0.32"' '-DICKDATADIR="/usr/share/ick-0.32"' '-DICKBINDIR="/usr/bin"' '-DICKLIBDIR="/usr/lib64"' -DYYDEBUG -DICK_HAVE_STDINT_H=1 -fno-toplevel-reorder -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -fno-toplevel-reorder  -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -o ick src/feh2.o src/dekludge.o src/ick_lose.o src/fiddle.o src/perpet.o src/uncommon.o parser.o lexer.o libidiot.a 
lexer.l:61:12: error: type of ‘clclex’ does not match original declaration [-Werror=lto-type-mismatch]
   61 | extern int clclex;
      |            ^
src/perpet.c:100:6: note: type ‘_Bool’ should match type ‘int’
  100 | bool clclex;            /* AIS: 1 means use CLC-INTERCAL meanings for @, ? */
      |      ^
src/perpet.c:100:6: note: ‘clclex’ was previously declared here
src/perpet.c:100:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
parser.y:37:12: error: type of ‘mark112’ does not match original declaration [-Werror=lto-type-mismatch]
   37 | extern int mark112;    /* AIS: Mark the tuple for W112 when it's created. */
      |            ^
src/feh2.c:31:6: note: type ‘_Bool’ should match type ‘int’
   31 | bool mark112 = 0; /* AIS: Mark the ick_next generated tuple for W112 */
      |      ^
src/feh2.c:31:6: note: ‘mark112’ was previously declared here
src/feh2.c:31:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-gcc returned 1 exit status
compilation terminated.
/usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:752: ick] Error 1

Originally reported downstream: https://bugs.gentoo.org/855590 Full build log: build.log