official-stockfish / Stockfish

A free and strong UCI chess engine
https://stockfishchess.org/
GNU General Public License v3.0
11.74k stars 2.3k forks source link

Commit 55df0ee causes runtime crash when compiled with MinGW-w64 on Windows 10. #5108

Open jackL999 opened 8 months ago

jackL999 commented 8 months ago

Describe the issue

Using MinGW-w64 from winlibs.com (gcc 13.2) Stockfish crashes with a runtime fault. All previous Stockfish versions from commit 632f1c2 and before compile and run without any problems. I successfully compiled and executed commit 55df0ee in Linux and Android (arm64-v8a and armeabi-v7a) without any issues. Only the Windows 10 version fails to execute after compilation.

Expected behavior

To run in Windows 10 without crashing.

Steps to reproduce

stockfish.exe bench 2048 2 13 default depth nnue

Anything else?

No response

Operating system

Windows

Stockfish version

Stockfish development commit 55df0ee (12/03/2024)

Disservin commented 8 months ago

Can you give us some information about how you compiled it and what the compilation output and stockfish output was?

jackL999 commented 8 months ago

I compiled it as I always do using the command, make -j8 profile-bulid ARCH=x86-64-bmi2 COMP=mingw CPPFLAGS="-DNNUE_EMBEDDDING_OFF -march=haswell" this compilation will fail as soon as it tries to execute Stockfish during profiling.

After experimenting on this I discovered that the problem only occurs when "-march=haswell" is included in CPPFLAGS. Note the source compiles with out any errors using make -j8 bulid ARCH=x86-64-bmi2 COMP=mingw CPPFLAGS="-DNNUE_EMBEDDDING_OFF -march=haswell" it just won't run without crashing.

Something in the latest source is clobbering or interfering with the optimization setting "-march=haswell".

Disservin commented 8 months ago

Can you run this through gdb perhaps (if it is installed for you)? gdb .\stockfish.exe run

jackL999 commented 8 months ago

Upon examining the changes to src/nnue/network.cpp and src/uci.cpp I noticed a lot of changes to Embedding nnue. I wonder if those are the source of bug. Could it be the source isn't parsing the CPPFLAGS instruction properly?

Disservin commented 8 months ago

@jackL999 can you please give the entire output of what is shown on the terminal?

Disservin commented 8 months ago

You also have a typo in profile-bulid it's profile-build and in -DNNUE_EMBEDDDING_OFF... it's -DNNUE_EMBEDDING_OFF

jackL999 commented 8 months ago

Yes, but those typos were only made here. They don't exist in the command line executed in the terminal window. That command is taken directly from the history file and has successfully executed the compilation of Stockfish source scores of times.

Disservin commented 8 months ago

@jackL999 can you please give the entire output of what is shown on the terminal?

…?

jackL999 commented 8 months ago

from previous request, running gdb, I get (gdb) r Starting program: c:\v\Stockfish\src\stockfish.exe [New Thread 33284.0x9214] [New Thread 33284.0x91b0] [New Thread 33284.0x9118] Stockfish dev-20240312-55df0ee0 by the Stockfish developers (see AUTHORS file)

Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff622e3561a in Stockfish::UCI::UCI(int, char**) () (gdb)

jackL999 commented 8 months ago

Compilation produces the following, make -j8 build ARCH=x86-64-bmi2 COMP=mingw CPPFLAGS="-DNNUE_EMBEDDING_OFF -march=haswell" Default net: nn-1ceb1ade0001.nnue nn-1ceb1ade0001.nnue available : OK Network validated Default net: nn-baff1ede1f90.nnue nn-baff1ede1f90.nnue available : OK Network validated

Config: debug: 'no' sanitize: 'none' optimize: 'yes' arch: 'x86_64' bits: '64' kernel: 'MSYS_NT-10.0-19045' os: 'Windows_NT' prefetch: 'yes' popcnt: 'yes' pext: 'yes' sse: 'yes' mmx: 'no' sse2: 'yes' ssse3: 'yes' sse41: 'yes' avx2: 'yes' avxvnni: 'no' avx512: 'no' vnni256: 'no' vnni512: 'no' neon: 'no' dotprod: 'no' arm_version: '0' target_windows: 'yes'

Flags: CXX: x86_64-w64-mingw32-c++ CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one LDFLAGS: -static -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -save-temps

Testing config sanity. If this fails, try 'make help' ...

make ARCH=x86-64-bmi2 COMP=mingw all make[1]: Entering directory 'c:/v/Stockfish/src' x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o benchmark.o benchmark.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o bitboard.o bitboard.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o evaluate.o evaluate.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o main.o main.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o misc.o misc.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o movegen.o movegen.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o movepick.o movepick.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o position.o position.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o search.o search.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o thread.o thread.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o timeman.o timeman.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o tt.o tt.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o uci.o uci.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o ucioption.o ucioption.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o tune.o tune.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o tbprobe.o syzygy/tbprobe.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o nnue_misc.o nnue/nnue_misc.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o half_ka_v2_hm.o nnue/features/half_ka_v2_hm.cpp x86_64-w64-mingw32-c++ -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -DNNUE_EMBEDDING_OFF -march=haswell -c -o network.o nnue/network.cpp x86_64-w64-mingw32-c++ -o stockfish.exe benchmark.o bitboard.o evaluate.o main.o misc.o movegen.o movepick.o position.o search.o thread.o timeman.o tt.o uci.o ucioption.o tune.o tbprobe.o nnue_misc.o half_ka_v2_hm.o network.o -static -Wall -Wcast-qual -fno-exceptions -std=c++17 -pedantic -Wextra -Wshadow -Wmissing-declarations -DNDEBUG -O3 -funroll-loops -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -mbmi -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -DGIT_SHA=55df0ee0 -DGIT_DATE=20240312 -DARCH=x86-64-bmi2 -flto -flto-partition=one -save-temps make[1]: Leaving directory 'c:/v/Stockfish/src'

jackL999 commented 8 months ago

I re-ran gdb with stockfish compiled using debug=yes make -j8 build ARCH=x86-64-bmi2 debug=yes COMP=mingw CPPFLAGS="-DNNUE_EMBEDDING_OFF -march=haswell" Default net: nn-1ceb1ade0001.nnue nn-1ceb1ade0001.nnue available : OK Network validated Default net: nn-baff1ede1f90.nnue nn-baff1ede1f90.nnue available : OK Network validated

Config: debug: 'yes' [....] make[1]: Leaving directory 'c:/v/Stockfish/src'

It produced the following output gdb.exe stockfish.exe [...] Reading symbols from stockfish.exe... (gdb) r Starting program: c:\v\Stockfish\src\stockfish.exe [New Thread 41048.0x85f8] [New Thread 41048.0x9970] [New Thread 41048.0xa334] Stockfish dev-20240312-55df0ee0 by the Stockfish developers (see AUTHORS file)

Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff7a1746d20 in Stockfish::UCI::UCI (this=this@entry=0x5ffc20, argc=argc@entry=1, argv=argv@entry=0x791ba0) at uci.cpp:96 96 threads.set({options, threads, tt, networks}); (gdb)

jackL999 commented 8 months ago

FYI, I was able to successfully compile and execute commit f072634, but commit 1a26d69 "Refactor Network Usage" causes the same Segmentation fault as noted with the latest commit. It appears the problem began with changes made in commit 1a26d69.

jackL999 commented 8 months ago

I was able to get the latest commit 55df0ee to compile and execute on Windows without problems using MinGW64 on ARCH Linux.

Running the command "stockfish.exe compiler" in Windows using the ARCH Linux build produces the following output,

Stockfish dev-20240312-55df0ee0 by the Stockfish developers (see AUTHORS file) Compiled by : g++ (GNUC) 13.1.0 on MinGW64 Compilation architecture : x86-64-bmi2 Compilation settings : 64bit BMI2 AVX2 SSE41 SSSE3 SSE2 POPCNT Compiler VERSION macro : 13.1.0

This means that the problem is likely with the winlibs.com MinGW64 compiler and not with the Stockfish source. It is odd though that every build using this compiler on source commits prior to 1a26d69 worked without any issues.

Disservin commented 8 months ago

@jackL999 btw the new comple uses 13.1 vs your original one was 13.2 ... did you also try running a make clean before compiliation?

Regarding winlibs, I recommend following the installation guide for windows from here https://github.com/official-stockfish/Stockfish/wiki/Developers#windows