Build fails with LTO due to ODR violations

Thomas Beierlein <[email protected]> Fri, 25 Oct 2024 13:16:06 +0200
Newsgroups gmane.comp.sysutils.backup.bacula.devel
Message-ID <fdfgjkrolh3wbpqhtkd5mftvzdwk2wne4hpxyqksqgioqx2xnu@dmqewwmlwqae>
Hello,

building bacula-15.0.2 here on Gentoo with 
'-Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -flto' 
failes with the following error:

+++
Linking bacula-fd ...
/var/tmp/portage/app-backup/bacula-15.0.2/work/bacula-15.0.2/libtool --silent --tag=CXX --mode=link /usr/bin/x86_64-pc-linux-gnu-g++  -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=odr -flto -L../lib -L../findlib -o bacula-fd filed.o authenticate.o backup.o crypto.o win_efs.o estimate.o fdcollect.o fd_plugins.o accurate.o bacgpfs.o filed_conf.o runres_conf.o heartbeat.o hello.o job.o fd_snapshot.o restore.o status.o verify.o verify_vol.o fdcallsdir.o suspend.o org_filed_dedup.o bacl.o bacl_linux.o bxattr.o bxattr_linux.o \
   -lacl 	      -lz -lbacfind -lbaccfg -lbac -lm \
  -rpath /usr/lib64   -lssl -lcrypto -lpthread  -lcap  -llzo2 -lzstd
../jcr.h:203:7: error: type 'struct JCR' violates the C++ One Definition Rule [-Werror=odr]
  203 | class JCR {
      |       ^
../jcr.h:203:7: note: a different type is defined in another translation unit
  203 | class JCR {
      |       ^
../jcr.h:472:11: note: the first difference of corresponding definitions is field 'sd_calls_client_bsock'
  472 |    BSOCK *sd_calls_client_bsock;      /* Socket used by SDCallsClient feature */
      |           ^
../jcr.h:203:7: note: a type with different number of fields is defined in another translation unit
  203 | class JCR {
      |       ^
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/15/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
+++

Looks like the optional extensions of JCR are clashing with the JCR definition
without extensions.

See https://bugs.gentoo.org/940695 for original bug and
https://940695.bugs.gentoo.org/attachment.cgi?id=904745 for full build log.

Regards,
    Thomas <[email protected]>