I tried to compile with LTO: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.
I got this error:
[7/15] /usr/bin/x86_64-pc-linux-gnu-gcc -DENABLE_PCIE -DXTRXLL_STATIC -Dxtrxll_EXPORTS -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -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 -fPIC -Wl,-z,defs -Wall -g -MD -MT CMakeFiles/xtrxll.dir/xtrxll_base.c.o -MF CMakeFiles/xtrxll.dir/xtrxll_base.c.o.d -o CMakeFiles/xtrxll.dir/xtrxll_base.c.o -c /var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c
FAILED: CMakeFiles/xtrxll.dir/xtrxll_base.c.o
/usr/bin/x86_64-pc-linux-gnu-gcc -DENABLE_PCIE -DXTRXLL_STATIC -Dxtrxll_EXPORTS -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -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 -fPIC -Wl,-z,defs -Wall -g -MD -MT CMakeFiles/xtrxll.dir/xtrxll_base.c.o -MF CMakeFiles/xtrxll.dir/xtrxll_base.c.o.d -o CMakeFiles/xtrxll.dir/xtrxll_base.c.o -c /var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c: In function ‘xtrxll_base_dev_init’:
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c:1212:26: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1212 | ((struct internal_base_state*)dev->internal_state)->rev5 = 1;
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c: At top level:
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c:882:12: warning: ‘PPS_CFG_TIME_PPS_EDGE’ defined but not used [-Wunused-const-variable=]
882 | localparam PPS_CFG_TIME_PPS_EDGE = 3;
| ^~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/xtrxll_base.c:880:12: warning: ‘PPS_CFG_OSC_PPS_EDGE’ defined but not used [-Wunused-const-variable=]
880 | localparam PPS_CFG_OSC_PPS_EDGE = 1;
| ^~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
[8/15] /usr/bin/x86_64-pc-linux-gnu-gcc -DXTRXLL_STATIC -I/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/.. -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -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 -Wl,-z,defs -Wall -g -fPIC -MD -MT mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o -MF mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o.d -o mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o -c /var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c
FAILED: mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o
/usr/bin/x86_64-pc-linux-gnu-gcc -DXTRXLL_STATIC -I/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/.. -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -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 -Wl,-z,defs -Wall -g -fPIC -MD -MT mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o -MF mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o.d -o mod_pcie/CMakeFiles/xtrxll_pcie.dir/xtrxll_pcie_linux.c.o -c /var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c: In function ‘internal_xtrxll_reg_in_n’:
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c:127:19: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
127 | *((uint64_t*)&to_read[0]) = *((uint64_t*)&dev->mmap_xtrxll_regs[streg]);
| ~^~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c: In function ‘xtrxllpciev0_discovery’:
/var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c:248:25: warning: ‘readdir_r’ is deprecated [-Wdeprecated-declarations]
248 | int res = readdir_r(d, &local_dir, &dir);
| ^~~
In file included from /var/tmp/portage/net-wireless/libxtrxll-0.0_p20201202/work/libxtrxll-1b6eddfbedc700efb6f7e3c3594e43ac6ff29ea4/mod_pcie/xtrxll_pcie_linux.c:36:
/usr/include/dirent.h:185:12: note: declared here
185 | extern int readdir_r (DIR *__restrict __dirp,
| ^~~~~~~~~
cc1: some warnings being treated as errors
Downstream report: https://bugs.gentoo.org/861932
Full build log: build.log
I tried to compile with LTO:
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasingThe -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.
I got this error:
Downstream report: https://bugs.gentoo.org/861932
Full build log: build.log