Skip to content

Build fails with LTO #128

@eli-schwartz

Description

@eli-schwartz

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:

make[2]: Entering directory '/var/tmp/portage/net-dialup/freeradius-client-1.1.7-r3/work/freeradius-client-1.1.7/lib'
/bin/sh ../libtool  --tag=CC   --mode=link x86_64-pc-linux-gnu-gcc  -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=3 -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 -version-info 2:0:0 -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -o libfreeradius-client.la -rpath /usr/lib64 buildreq.lo clientid.lo env.lo sendserver.lo avpair.lo config.lo dict.lo ip_util.lo log.lo util.lo rc-md5.lo md5.lo  -lcrypt -lnsl 
libtool: link: x86_64-pc-linux-gnu-gcc -shared  -fPIC -DPIC  .libs/buildreq.o .libs/clientid.o .libs/env.o .libs/sendserver.o .libs/avpair.o .libs/config.o .libs/dict.o .libs/ip_util.o .libs/log.o .libs/util.o .libs/rc-md5.o .libs/md5.o   -Wl,--as-needed -lcrypt -lnsl  -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -Wl,-O1 -Wl,-z -Wl,pack-relative-relocs -flto=3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0   -Wl,-soname -Wl,libfreeradius-client.so.2 -o .libs/libfreeradius-client.so.2.0.0
../include/freeradius-client.h:524:6: error: type of 'rc_md5_calc' does not match original declaration [-Werror=lto-type-mismatch]
  524 | void rc_md5_calc(unsigned char *, unsigned char const *, unsigned int);
      |      ^
rc-md5.c:15:6: note: type mismatch in parameter 3
   15 | void rc_md5_calc(unsigned char *output, unsigned char const *input,
      |      ^
rc-md5.c:15:6: note: type 'size_t' should match type 'unsigned int'
rc-md5.c:15:6: note: 'rc_md5_calc' was previously declared here
rc-md5.c:15: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[2]: *** [Makefile:444: libfreeradius-client.la] Error 1
make[2]: Leaving directory '/var/tmp/portage/net-dialup/freeradius-client-1.1.7-r3/work/freeradius-client-1.1.7/lib'
make[1]: *** [Makefile:427: all-recursive] Error 1
make: *** [Makefile:359: all] Error 2

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

Indeed, if we look at the current versions of the affected code, we see they are untruthful and disagree with each other:

void rc_md5_calc(unsigned char *output, unsigned char const *input,
size_t inlen)

void rc_md5_calc(unsigned char *, unsigned char const *, unsigned int);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions