Open knedlsepp opened 7 years ago
cc @globin @fpletz
I'm not sure if we can disable format hardening for all fortran projects automatically but it should be done somehow. We have to look into it.
Thanks for the report!
Or could we just filter these in gfortran wrapper?
You can always add hardeningDisable = [ "format" ];
to a derivation to disable this. Otherwise, though, we don't know ahead of time what language gcc is being used to compile for. Since this isn't a fatal error, I think it is best to disable this on a case-by-case basis. Hardening is still nice to have in fortran even if it doesn't work in this case.
I think this issue should be reopened. Current state provides absolutely horrible user experience when developing in fortran. Every fortran files gives 3 lines of spurious warnings which drown out legitimate ones. So i think
You can always add hardeningDisable = [ "format" ]; to a derivation to disable this.
isn't really a solution since it's not documented anywhere. Where to add it? What will it do? For anyone without understanding of gcc packaging it's an impenetrable mistery
@Shimuuar The format issue was seemingly resolved by f42aa7e1d7ac4fb1050b73b296912fa7c7b927c2. I only see errors with -iframework
, but that's on Darwin.
It seems it isn't. On release-20.09 branch warning is still present. I tried to test it with commit 4c4a45e284cd505976618825eff9b5e44332d0cf on release-21.05 and it still persists. Test is easy. Compile hello world
program hello
print *, 'Hello, World!'
end program hello
Then you get following warnings
$ gfortran hello.for
f951: Warning: command line option '-Wformat=1' is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: command line option '-Wformat-security' is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: '-Werror=' argument '-Werror=format-security' is not valid for Fortran
@Shimuuar I don't see it:
with import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/4c4a45e284cd505976618825eff9b5e44332d0cf.tar.gz") {};
runCommandNoCC "fortran-test" {
buildInputs = [ gfortran ];
file = writeText "fortran-test.f" "
program hello
print *, 'Hello, World!'
end program hello
";
} ''
gfortran "$file"
install -Dm555 ./a.out "$out"
''
A-ha! Yes problem doesn't happen when you call gfortran inside derivation but it does happen when it's called in nix-shell:
with import (builtins.fetchTarball
"https://github.com/NixOS/nixpkgs/archive/4c4a45e284cd505976618825eff9b5e44332d0cf.tar.gz") {};
pkgs.mkShell
{ buildInputs = [pkgs.gfortran];
}
$ gfortran hello.for
f951: Warning: command line option '-Wformat=1' is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: command line option '-Wformat-security' is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: '-Werror=' argument '-Werror=format-security' is not valid for Fortran
This is very inconvenient if you're mixing compilers which support different flags and want to use a NIX_CFLAGS_COMPILE value that your fortran compiler errors out on, rather than just showing a warning.
Issue description
Building Fortran projects currently leads to a massive amount of warning messages
See e.g. liblapack's log output This is caused by the format hardening adding those flags to
NIX_CFLAGS_COMPILE
, which in turn is used also for Fortran builds.This also leads to the breakage of a build system of one package I try to compile, as it expects
gfortran
not to produce any warnings for some tests. I propose thus to disable $NIX_CFLAGS_COMPILE for fortran builds or to disable the format hardening for Fortran by default.