Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with LTO #437

Open
eli-schwartz opened this issue Apr 1, 2024 · 0 comments
Open

Build fails with LTO #437

eli-schwartz opened this issue Apr 1, 2024 · 0 comments
Assignees
Milestone

Comments

@eli-schwartz
Copy link

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:

FAILED: fortran/libnetcdff.so.7.1.0 
: && /usr/bin/x86_64-pc-linux-gnu-gfortran -fPIC -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fallow-argument-mismatch  -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -shared -Wl,-soname,libnetcdff.so.7 -o fortran/libnetcdff.so.7.1.0 fortran/CMakeFiles/netcdff_c.dir/nf_lib.c.o fortran/CMakeFiles/netcdff_c.dir/nf_v2compat.c.o fortran/CMakeFiles/netcdff.dir/typeSizes.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_nc_data.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_nc_interfaces.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_nf_data.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_nf_interfaces.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_f03.F90.o fortran/CMakeFiles/netcdff.dir/nf_attio.F90.o fortran/CMakeFiles/netcdff.dir/nf_control.F90.o fortran/CMakeFiles/netcdff.dir/nf_dim.F90.o fortran/CMakeFiles/netcdff.dir/nf_misc.F90.o fortran/CMakeFiles/netcdff.dir/nf_genatt.F90.o fortran/CMakeFiles/netcdff.dir/nf_geninq.F90.o fortran/CMakeFiles/netcdff.dir/nf_genvar.F90.o fortran/CMakeFiles/netcdff.dir/nf_vario.F90.o fortran/CMakeFiles/netcdff.dir/nf_var1io.F90.o fortran/CMakeFiles/netcdff.dir/nf_varaio.F90.o fortran/CMakeFiles/netcdff.dir/nf_varmio.F90.o fortran/CMakeFiles/netcdff.dir/nf_varsio.F90.o fortran/CMakeFiles/netcdff.dir/nf_nc_noparallel.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf4_nc_interfaces.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf4_nf_interfaces.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf4_f03.F90.o fortran/CMakeFiles/netcdff.dir/nf_nc4.F90.o fortran/CMakeFiles/netcdff.dir/nf_logging.F90.o fortran/CMakeFiles/netcdff.dir/netcdf4.F90.o fortran/CMakeFiles/netcdff.dir/module_netcdf_fortv2_c_interfaces.F90.o fortran/CMakeFiles/netcdff.dir/nf_fortv2.F90.o  -Wl,-rpath,::::::::::  /usr/lib64/libnetcdf.so.19  -ldl  /usr/lib64/libhdf5_hl.so  /usr/lib64/libhdf5.so  /usr/lib64/libz.so  /usr/lib64/libdl.a  -lm  /usr/lib64/libzstd.so  /usr/lib64/libbz2.so  /usr/lib64/libcurl.so  /usr/lib64/libxml2.so && :
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/netcdf4_func.F90:807:81: error: type of ‘nf_inq_var_fill’ does not match original declaration [-Werror=lto-type-mismatch]
  807 |     nf90_inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
      |                                                                                 ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1761:1: note: type mismatch in parameter 5
 1761 |  Function nf_inq_var_fill( ncid, varid, no_fill, fill_value) RESULT(status)
      | ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1761:1: note: type ‘long int’ should match type ‘void’
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1761:1: note: ‘nf_inq_var_fill’ was previously declared here
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1761:1: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/netcdf4_func.F90:747:81: error: type of ‘nf_def_var_fill’ does not match original declaration [-Werror=lto-type-mismatch]
  747 |     nf90_def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
      |                                                                                 ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1733:1: note: type mismatch in parameter 5
 1733 |  Function nf_def_var_fill( ncid, varid, no_fill, fill_value) RESULT(status)
      | ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1733:1: note: type ‘long int’ should match type ‘void’
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1733:1: note: ‘nf_def_var_fill’ was previously declared here
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1733:1: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/netcdf4_func.F90:470:76: error: type of ‘nf_inq_enum_member’ does not match original declaration [-Werror=lto-type-mismatch]
  470 |     nf90_inq_enum_member = nf_inq_enum_member(ncid, xtype, idx, name, value)
      |                                                                            ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1220:1: note: type mismatch in parameter 7
 1220 |  Function nf_inq_enum_member( ncid, xtype, idx, name, value) RESULT (status)
      | ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1220:1: note: type ‘long int’ should match type ‘void’
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1220:1: note: ‘nf_inq_enum_member’ was previously declared here
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1220:1: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/netcdf4_func.F90:447:63: error: type of ‘nf_insert_enum’ does not match original declaration [-Werror=lto-type-mismatch]
  447 |     nf90_insert_enum = nf_insert_enum(ncid, xtype, name, value)
      |                                                               ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1144:1: note: type mismatch in parameter 6
 1144 |  Function nf_insert_enum( ncid, xtype, name, value) RESULT (status)
      | ^
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1144:1: note: type ‘long int’ should match type ‘void’
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1144:1: note: ‘nf_insert_enum’ was previously declared here
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1144:1: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
/var/tmp/portage/sci-libs/netcdf-fortran-9999/work/netcdf-fortran-9999/fortran/nf_nc4.F90:1899:73: error: type of ‘nc_inq_var_filter’ does not match original declaration [-Werror=lto-type-mismatch]
 1899 |  cstatus = nc_inq_var_filter(cncid, cvarid, cfilterid, cnparams, cparams)
      |                                                                         ^
/usr/include/netcdf.h:978:1: note: ‘nc_inq_var_filter’ was previously declared here
  978 | nc_inq_var_filter(int ncid, int varid, unsigned int* idp, size_t* nparams, unsigned int* params);
      | ^
/usr/include/netcdf.h:978:1: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-gfortran returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Downstream report: https://bugs.gentoo.org/927588
Full build log: build.log

Note: the downstream report was for the latest stable release but my local reproducer used a git checkout and it is still reproducible there.

@WardF WardF self-assigned this Apr 2, 2024
@WardF WardF added this to the 4.6.2 milestone Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants