official-stockfish / Stockfish

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

Compiling StockFish using arm-none-eabi-gcc and arm-none-eabi-g++ compilers? #5330

Open unebonnevie opened 1 month ago

unebonnevie commented 1 month ago

Describe the issue

Hi,

I am looking just to cross compile StockFish as baremetal executable using the ARM GNU Toolchain found at https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads. I don't want Android ARM platform.

How would I approach that?

Thank you!

Expected behavior

Able to build a StockFish executable for baremetal ARMv8.

Steps to reproduce

Follow the instructions at https://askubuntu.com/questions/1243252/how-to-install-arm-none-eabi-gdb-on-ubuntu-20-04-lts-focal-fossa to download GNU ARM Toolchain to cross-compile StockFish as a baremetal executable.

Anything else?

None

Operating system

Other or N/A

Stockfish version

Latest from GitHub

vondele commented 1 month ago

Things like

echo "crosses to RPI"
make clean && make -j build ARCH=armv7         COMP=gcc COMPILER=arm-linux-gnueabihf-g++  > crosses.out 2>&1 ; mv stockfish stockfish.RPI.armv7
make clean && make -j build ARCH=armv7-neon    COMP=gcc COMPILER=arm-linux-gnueabihf-g++  > crosses.out 2>&1 ; mv stockfish stockfish.RPI.armv7-neon
make clean && make -j build ARCH=armv8         COMP=gcc COMPILER=aarch64-linux-gnu-g++    > crosses.out 2>&1 ; mv stockfish stockfish.RPI.armv8

can be used e.g. to cross from Linux x86 to a RPI. You will need to try out, and possibly fix some issues in the Makefile.

unebonnevie commented 1 month ago

After installing the aarch64 toolchain for baremetal from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads, that is, armv8 platform, I get the below. It looks like the distributed Makefile file would need a lot tailoring for armv8 baremetal platform.

~/projects/StockFish/src$ make -j build ARCH=armv8 COMP=aarch64-none-elf-gcc COMPCXX=aarch64-none-elf-g++

Default net: nn-ddcfb9224cdb.nnue nn-ddcfb9224cdb.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: 'armv8' bits: '64' kernel: 'Linux' os: 'GNU/Linux' prefetch: 'yes' popcnt: 'yes' pext: 'no' sse: 'no' mmx: 'no' sse2: 'no' ssse3: 'no' sse41: 'no' avx2: 'no' avxvnni: 'no' avx512: 'no' vnni256: 'no' vnni512: 'no' neon: 'yes' dotprod: 'no' arm_version: '8' target_windows: ''

Flags: CXX: aarch64-none-elf-g++ CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_PTHREADS -DNDEBUG -O3 -funroll-loops -DIS_64BIT -DUSE_POPCNT -DUSE_NEON=8 -DARCH=armv8 -flto=full LDFLAGS: -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_PTHREADS -DNDEBUG -O3 -funroll-loops -DIS_64BIT -DUSE_POPCNT -DUSE_NEON=8 -DARCH=armv8 -flto=full

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

make: *** [Makefile:1040: config-sanity] Error 1

vondele commented 1 month ago

Try:

make -j build ARCH=armv8 COMP=gcc COMPCXX=aarch64-none-elf-g++
unebonnevie commented 1 month ago

Try:

make -j build ARCH=armv8 COMP=gcc COMPCXX=aarch64-none-elf-g++

Much better, but tons of errors on the thread.cpp file, etc. Attached file. errors.txt I can work out one at a time, but if you have any tips, greatly appreciate it! Thank you very much!

vondele commented 1 month ago

no real suggestions at this time, seems like some of the common functionality is not available in this cross build, assumptions on posix threads being available etc. Probably needs to be answered by someone who knows this toolchain/setup.

unebonnevie commented 1 month ago

no real suggestions at this time, seems like some of the common functionality is not available in this cross build, assumptions on posix threads being available etc. Probably needs to be answered by someone who knows this toolchain/setup.

I think the answer lies in the below errors, configing the C++, and many other things. Anyway, make can't pass compiling score.cpp. Calling it a night!

~/tools/ArmToolchain/aarch64/v13_2/aarch64-none-elf/include$ grep _GLIBCXX_HAVE_WCHAR_H -r * c++/13.2.1/cwchar:#if _GLIBCXX_HAVE_WCHAR_H c++/13.2.1/aarch64-none-elf/ilp32/bits/c++config.h:#define _GLIBCXX_HAVE_WCHAR_H 1 c++/13.2.1/aarch64-none-elf/bits/c++config.h:#define _GLIBCXX_HAVE_WCHAR_H 1

MinetaS commented 19 hours ago

We assume std::mutex is always present - which means it is not able to compile Stockfish with bare metal ARM compilers. You need to either implement threading components on your own, or find libraries that implement them.