This bug only appears on the laptop on my boss. I also found 2 unresolved issues online with similar problem. It is extremely hard to reproduce.
Environnment is Windows + gfortran installed with msys2
The Code :
!! module.f90
module utils
contains
subroutine say_hello
print *, 'Hello, World!'
end subroutine
end module
!! program.f90
program hello
use utils
call say_hello()
end program
gfortran -o foo module.f90 program.f90
The Error
f951.exe: Fatal Error: Reading module ‘utils.mod’ at line 1 column 26: Unexpected EOF compilation terminated.
What I have test
The file utils.mod is generated, but seems kind of corrupted. It doesn’t work on cmd.exe or PowerShell, but the file is valid when generated in Git Bash.
Also, if you rename the module, sometimes it works, sometimes no.
utile.mod and utils.mod failed. But utila.mod and utilz.mod works.
stdlib_kinds.mod of the stdlib also failed.
I try random forbidden word, like cannabis.mod cannot be read, but cannabiss.mod is ok.
It works fine on my machine, it only fails on 1 of our machine. I can’t reproduce it on any other device.
My first guess is windows preventing the generation of the mod file to be complete due to some naming convention? I was thinking about the antivirus filtering some mod file if the name contains some word? But this does not explain why it works on Git Bash and not cmd.exe.
Any hint to resolve, or try to resolve the problem would be veeeeeery welcomed
Probably same issue but neither is resolved
Works fine for me with gfortran 12.2 MinGW-w64 on Windows 7, from both cmd.exe and PowerShell.
My guess would be that this has something to do with the environment. Is the gfortran version/executable used in cmd.exe or PowerShell the same as under Git Bash?
The *.mod files produced by Gfortran are run-of-the-mill text files compressed by gzip. You can do
gzip -cd utils.mod
and you should see something similar to
GFORTRAN module version '15' created from module.f90
(() () () () () () () () () () () () () () () () () () () () () () () ()
() () ())
()
()
()
()
()
(2 'say_hello' 'utils' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC DECL
UNKNOWN 0 0 SUBROUTINE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () ()
() 0 0)
3 'utils' 'utils' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN
UNKNOWN 0 0) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 0)
)
('say_hello' 0 2 'utils' 0 3)
1 Like
That will be very useful, I will see what’s in there on Monday, thank you!
Since the behavior is observed sporadically, it is probably related to parallelization. In the context here, I could imagine that write to disk is buffered.
@cyrilgandon are you compiling on a network drive or any other uncommon storage device?
As expected, the mod files generated is an invalid zip file. Trying to decompress it renders an error:
gzip: utils.mod: invalid compressed data–crc error
gzip: utils.mod: invalid compressed data–length error
The file is still processed anyway and looks like that:
GFORTRAN module version '15' created from utils.f90
(() () () () () () () () () () () () () () () () () () () () () () () ()
() () ())
()
()
()
()
()
(2 'say_hello' 'utils' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC DECL
UNKNOWN 0 0 SUBROUTINE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () ()
() 0 0)
3 'utils' 'utils' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN
UNKNOWN 0 0INE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () 0 UNKr
() 0 UNKr
() 0 UNKr
Uvo0 (0oO0 3)
There is effectively corrupted data if you compare to what it should looks like.
That starts at
UNKNOWN 0 0INE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () 0 UNKr
instead of
UNKNOWN 0 0) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 0)
I’m compiling locally, no network or other weird thing.
The next question is, what could trigger a failed zip action by gfortran when it tried to generate the .mod file?
Here is the failed utils.mod file (renamed to avoid upload restriction)
utils.mod.txt (219 Bytes)
Some research on an invalid generation of a zip files:
sometimes caused by hardware issue on your side. For example failing harddrive, bad ram, network issues. Antivirus/firewall software is known to cause this also.
Also here is a diff between a compilation made under cmd.exe (left) and one made with git bash (right). Module name tested was bbbb in this case (b, bb and bbb works fine).
Installing gfortran from Fortran, C, C++ for Windows, the latest version, fixed the problem!