official-stockfish / Stockfish

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

RetroFish: statically linking #3647

Closed hippke closed 3 years ago

hippke commented 3 years ago

I compiled SF14 on Linux (Ubuntu 18.04) with statically linked libraries. This is because I want to run SF on PCs where the latest versions of glibc are not available, and are not easily installable. Without various glibc dependencies, SF does not run.

To achieve a static compile, I modified line 320 in the makefile:

LDFLAGS += $(EXTRALDFLAGS) -static

I compile with gcc11:

make CXX="g++-11" build ARCH=x86-64-modern

The file is indeed statically linked:

$ file stockfish
stockfish: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, 
BuildID[sha1]=5322c01f61ed719243e9115d82d82a7297bb0b97, with debug_info, not stripped

However, when I run SF I get an error:

Stockfish 14 by the Stockfish developers (see AUTHORS file)
Segmentation fault (core dumped)

Any advice appreciated!

hippke commented 3 years ago

Some progress. I change line 320 of the makefile to:

LDFLAGS += $(EXTRALDFLAGS) -static-libstdc++

The segfault is gone. However, it does not statically link glibc and thus complains that GLIBC_2.16 and GLIBC_2.17 are missing on the old system (Debian Squeeze). I have spent hours trying to install glibc manually, so far without success. Any ideas how to statically link glibc?

ppigazzini commented 3 years ago

The glibc statically linking seems to be discouraged, see https://stackoverflow.com/questions/57476533/why-is-statically-linking-glibc-discouraged

ppigazzini commented 3 years ago

We build cutechess-cli (with static Qt5) on an old Linux distribution to raise the compatibility with different linux distributions / versions, see https://github.com/glinscott/fishtest/wiki/Build-cutechess-with-Qt5-static#linux

ppigazzini commented 3 years ago

You can install a modern gcc on old Ubuntu versions, perhaps this works also on Debian:

# install the default building tools
sudo apt update
sudo apt install -y git build-essential software-properties-common

# add the repository "ubuntu-toolchain-r/test"
sudo apt update
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update

# install other GCC versions
sudo apt install -y gcc-9 g++-9

# configure the alternatives for gcc and g++, setting a higher priority to a newer version (ymmv)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-9

# check or change the alternatives configuration
update-alternatives --config gcc
hippke commented 3 years ago

Thank you for your assistance! Debian Squeeze on my architecture (i486) is too old for pre-built packages such as those from Ubuntu, which are all i686. I also tried installing glibc and gcc from source, but many problems occur, including segfaults.

I am actually trying to run SF-NNUE on a physical 486 PC from the early 1990s - a fun experiment. I like to play a match at a few kN/s on the old machine, against an old software running on a new machine (e.g. Fritz 5 which runs on my i7).

However, with standard Linux that's surprisingly difficult. I have two more ideas: Gentoo Linux which apparently still runs on 486, or moving to Windows 95 or 98. But I guess compiling to these old Windowses will be even more difficult...

ppigazzini commented 3 years ago

Other info from your "Gento on 486" link: https://yeokhengmeng.com/2018/01/make-the-486-great-again/ https://retrocomputing.stackexchange.com/questions/1811/which-linux-or-bsd-distributions-do-still-support-i386-i486-or-i586-cpus

I'm suggesting to change the title in something like this "RetroFish: statically linking" :)

hippke commented 3 years ago

Solved using CFish. To reproduce:

Note: