Strange bug while compiling OCaml under Windows

While trying to debug a patch for OCaml failing on Windows (unrelated to the issue I am currently presenting to you), I am trying to compile OCaml for the first on time on Windows (cross-compilation under cygwin for mingw32, the usual way apparently).

I have a very strange problem/bug right at configure stage: at some point the configure script creates a test program with wrong user/group and cannot continue because it cannot delete it. Even more strange, 1) once this happens, it happens right off the bat after running configure again even after cleaning-up, 2) the problem disappears if I reboot the computer (before it starts to failing again). The state of the current ocaml build/repo directory does not seem involved: even if I delete and re-clone it the problem stays at stage 1). The state of the cygwin installation seems involved though: if I reinstall cygwin I am back at the beginning.

See the cygwin session below where it happens. Let me know if you know what is the problem.

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ ./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
configure: Configuring OCaml version 5.1.0+dev1-2022-06-09
checking build system type... x86_64-pc-cygwin
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
checking for x86_64-w64-mingw32-ld... x86_64-w64-mingw32-ld
checking how to print strings... printf
checking for x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-w64-mingw32-gcc accepts -g... yes
checking for x86_64-w64-mingw32-gcc option to accept ISO C89... none needed
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-ld
checking if the linker (x86_64-w64-mingw32-ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/x86_64-w64-mingw32-nm -B
checking the name lister (/usr/bin/x86_64-w64-mingw32-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 8192
checking how to convert x86_64-pc-cygwin file names to x86_64-w64-mingw32 format... func_convert_file_cygwin_to_w32
checking how to convert x86_64-pc-cygwin file names to toolchain format... func_convert_file_noop
checking for x86_64-w64-mingw32-ld option to reload object files... -r
checking for x86_64-w64-mingw32-objdump... x86_64-w64-mingw32-objdump
checking how to recognize dependent libraries... file_magic ^x86 archive import|^x86 DLL
checking for x86_64-w64-mingw32-dlltool... x86_64-w64-mingw32-dlltool
checking how to associate runtime and link libraries... func_cygming_dll_for_implib
checking for x86_64-w64-mingw32-ar... x86_64-w64-mingw32-ar
checking for archiver @FILE support... @
checking for x86_64-w64-mingw32-strip... x86_64-w64-mingw32-strip
checking for x86_64-w64-mingw32-ranlib... x86_64-w64-mingw32-ranlib
checking for gawk... gawk
checking command to parse /usr/bin/x86_64-w64-mingw32-nm -B output from x86_64-w64-mingw32-gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for x86_64-w64-mingw32-mt... no
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... x86_64-w64-mingw32-gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... no
checking for objdir... .libs
checking if x86_64-w64-mingw32-gcc supports -fno-rtti -fno-exceptions... no
checking for x86_64-w64-mingw32-gcc option to produce PIC... -DDLL_EXPORT -DPIC
checking if x86_64-w64-mingw32-gcc PIC flag -DDLL_EXPORT -DPIC works... yes
checking if x86_64-w64-mingw32-gcc static flag -static works... yes
checking if x86_64-w64-mingw32-gcc supports -c -o file.o... yes
checking if x86_64-w64-mingw32-gcc supports -c -o file.o... (cached) yes
checking whether the x86_64-w64-mingw32-gcc linker (x86_64-w64-mingw32-ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking C compiler vendor... gcc-11-3
checking whether host executables can be run in the build... yes
checking whether #! works in shell scripts... yes
checking for flexdll sources... $(ROOTDIR)/flexdll
checking for flexlink... no
checking flexdll.h usability... yes
checking flexdll.h presence... yes
checking for flexdll.h... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for cos in -lm... rm: cannot remove 'conftest.exe': Permission denied
yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking for unistd.h... (cached) yes
checking for stdint.h... (cached) yes
checking for dirent.h... yes
checking for sys/select.h... no
checking stdatomic.h usability... yes
checking stdatomic.h presence... yes
checking for stdatomic.h... yes
checking sys/mman.h usability... no
checking sys/mman.h presence... no
checking for sys/mman.h... no
checking for off_t... yes
checking size of int... 4
checking size of long... 4
checking size of long *... 8
checking size of short... 2
checking size of long long... 8
configure: Target is a 64 bits architecture
checking whether byte ordering is bigendian... no
checking alignment of double... 8
checking alignment of long... 4
checking alignment of long long... 8
checking whether the C compiler supports _Atomic types... rm: cannot remove 'conftest.exe': Permission denied
no
rm: cannot remove 'conftest.exe': Permission denied
configure: error: in `/home/gadmm/ocaml':
configure: error: C11 atomic support is required, use another C compiler
See `config.log' for more details
rm: cannot remove 'conftest.exe': Permission denied

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ ls -l conftest.exe
ls: conftest.exe: Permission denied
-rwxr-x--- 1 Unknown+User Unknown+Group 0 Jul  5 02:40 conftest.exe

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ rm conftest.exe
rm: remove write-protected regular file 'conftest.exe'? y
rm: cannot remove 'conftest.exe': Permission denied

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ cmd
Microsoft Windows [version 10.0.19044.1766]
(c) Microsoft Corporation. Tous droits réservés.

C:\cygwin64-2\home\gadmm\ocaml>del conftest.exe
C:\cygwin64-2\home\gadmm\ocaml\conftest.exe
Le fichier spécifié est introuvable.

C:\cygwin64-2\home\gadmm\ocaml>exit

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ ls conftest.exe
ls: cannot access 'conftest.exe': No such file or directory

gadmm@DESKTOP-ITGR1EG ~/ocaml
$ ./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
configure: Configuring OCaml version 5.1.0+dev1-2022-06-09
checking build system type... x86_64-pc-cygwin
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
checking for x86_64-w64-mingw32-ld... x86_64-w64-mingw32-ld
checking how to print strings... printf
checking for x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... configure: error: in `/home/gadmm/ocaml':
configure: error: cannot compute suffix of executables: cannot compile and link
See `config.log' for more details
rm: cannot remove 'conftest.exe': Permission denied

Let me know also if you have another suggestion for compiling ocaml for mingw and run the testsuite.

(cc @dra27 in case this rings a bell to you.)

Don’t have anything precise to suggest, but are you running antivirus software? I have a feeling that a couple of times in the past I saw some mysterious permissions problems that were due to overly zealous antivirus programs…

Cheers,
Nicolas

I did try to disable Windows Defender and retry, but this did not work. Also Windows Defender did not report anything suspicious.

Now my computer came with some HP bloatware, I am unable to tell if there is some “antivirus” hidden in there.

I’ve not seen that specifically, but I’d try building mingw64 OCaml in a non-Cygwin directory - e.g. /cygdrive/c/Users/you/Documents/ocaml. If that also fails, the next step is to add noacl to the mount options in /etc/fstab, restart Cygwin and try again (at that point, you’re at my default setup).

It’s ringing a possible bell about a recent Cygwin bug, but I’d try building in a non-Cygwin controlled directory before I dig further into that.

Thank you, the first suggestion worked (build in a non-cygwin directory).

The configure script succeeds and compilation proceeds until boot/ocamlruns.exe fails on camlInternalFormal.mli (with a GUI dialog libwinpthread-1.dll not found / or after I add its directory to the PATH variable, a dialog with an error code 0xc00007b “unable to start correctly”).

With host x86_64-w64-mingw64 instead of x86_64-w64-mingw32, (I have to add --enable-imprecise-c99-float-ops and) the build fails on runtime/unix.c because it does not find flexdll.h (I use the git submodule approach and configure finds it correctly).

Oops, that’s the last of my “before 5.0 goes into beta” fixes :dizzy_face: You need to do export PATH=$PATH:/usr/x86_64-w64-mingw32/sys-root/mingw/bin at the moment, until we switch the pthreads library to be linked statically.

I did export PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin:$PATH. Unless it behaves differently from your PATH, I have the error 0xc0007b in a dialog.

OK, that is weird! Is the DLL present in /usr/x86_64-w64-mingw32/sys-root/mingw/bin?

@gadmm - what version of Windows are you running this on?

Version 10.0.19044.1766. I’ll try again and double check when I’m back at my Windows machine. But I’d say yes since without the PATH the message says “libwinpthread-1.dll missing” and with the PATH it says “the application was unable to start correctly”.

If you already have a patch for static linking then I could apply it to run my tests.

As an update, I tried again and it worked this time (with out-of-cygwin build directory, correctly set-up PATH). I suspect that I forgot rebooting as a universal solution to issues on Windows. Thanks everyone for the help.

1 Like