Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes FreeBSD compilation when using clang #3342

Closed
wants to merge 1 commit into from
Closed

Fixes FreeBSD compilation when using clang #3342

wants to merge 1 commit into from

Conversation

Cubox
Copy link
Contributor

@Cubox Cubox commented Feb 8, 2021

No description provided.

@snicolet
Copy link
Member

Hi @Cubox

Thanks for the pull request and the fix!

Could you provide us with the error message that the default Makefile emits on FreeBSD,
so that we can try to reproduce the error and check the bug fix?

Thanks :-)

@Cubox
Copy link
Contributor Author

Cubox commented Feb 10, 2021

Hi,

Here is the error if you are using the current version of Stockfish:

<cubox@Onyx>-<~/chess/stockfish/src> λ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
<cubox@Onyx>-<~/chess/stockfish/src> λ gmake -j8 build ARCH=x86-64-bmi2 COMP=clang
Default net: nn-62ef826d1a6d.nnue
Already available.

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'x86_64'
bits: '64'
kernel: 'FreeBSD'
os: ''
prefetch: 'yes'
popcnt: 'yes'
pext: 'yes'
sse: 'yes'
mmx: 'no'
sse2: 'yes'
ssse3: 'yes'
sse41: 'yes'
avx2: 'yes'
avx512: 'no'
vnni256: 'no'
vnni512: 'no'
neon: 'no'

Flags:
CXX: clang++
CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin
LDFLAGS:  -latomic -m64 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin

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

gmake ARCH=x86-64-bmi2 COMP=clang all
gmake[1]: Entering directory '/usr/home/cubox/chess/stockfish/src'
clang++ -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin   -c -o search.o search.cpp
clang++ -o stockfish benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o tune.o tbprobe.o evaluate_nnue.o half_kp.o  -latomic -m64 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin
ld: error: unable to find library -latomic
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[1]: *** [Makefile:843: stockfish] Error 1
gmake[1]: Leaving directory '/usr/home/cubox/chess/stockfish/src'
gmake: *** [Makefile:715: build] Error 2
<cubox@Onyx>-<~/chess/stockfish/src> λ

With the fix:

<cubox@Onyx>-<~/chess/stockfish/src> λ git diff
diff --git a/src/Makefile b/src/Makefile
index 87203547..f9bfba1a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -365,7 +365,7 @@ ifeq ($(COMP),clang)
        CXXFLAGS += -pedantic -Wextra -Wshadow

        ifneq ($(KERNEL),Darwin)
-       ifneq ($(KERNEL),OpenBSD)
+       ifneq ($(KERNEL),FreeBSD)
                LDFLAGS += -latomic
        endif
        endif
<cubox@Onyx>-<~/chess/stockfish/src> λ gmake -j8 build ARCH=x86-64-bmi2 COMP=clang
Default net: nn-62ef826d1a6d.nnue
Already available.

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'x86_64'
bits: '64'
kernel: 'FreeBSD'
os: ''
prefetch: 'yes'
popcnt: 'yes'
pext: 'yes'
sse: 'yes'
mmx: 'no'
sse2: 'yes'
ssse3: 'yes'
sse41: 'yes'
avx2: 'yes'
avx512: 'no'
vnni256: 'no'
vnni512: 'no'
neon: 'no'

Flags:
CXX: clang++
CXXFLAGS: -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin
LDFLAGS:  -m64 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin

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

gmake ARCH=x86-64-bmi2 COMP=clang all
gmake[1]: Entering directory '/usr/home/cubox/chess/stockfish/src'
clang++ -o stockfish benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o tune.o tbprobe.o evaluate_nnue.o half_kp.o  -m64 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++17  -pedantic -Wextra -Wshadow -m64 -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -msse -msse3 -mpopcnt -DUSE_POPCNT -DUSE_AVX2 -mavx2 -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DUSE_PEXT -mbmi2 -flto=thin
gmake[1]: Leaving directory '/usr/home/cubox/chess/stockfish/src'
<cubox@Onyx>-<~/chess/stockfish/src>

We are trying to get FreeBSD builds for fishnet build compilation (niklasf#4). You can see the build worked here https://github.com/niklasf/Stockfish/actions/runs/554567039

If you wish to reproduce the issue and confirm the fix is indeed working, here are the steps from any clean FreeBSD system:

pkg install -y curl gmake
git clone https://github.com/official-stockfish/Stockfish
cd Stockfish/src
gmake arch=x86-64 COMP=clang
# Compilation fail here
git fetch origin pull/3342/head:patch-1
git checkout patch-1
gmake arch=x86-64 COMP=clang
# Works

gmake being used here is because FreeBSD's make is different from GNU's make.

@vondele vondele added the to be merged Will be merged shortly label Feb 10, 2021
@vondele vondele closed this in 1f87a9e Feb 10, 2021
BM123499 pushed a commit to BM123499/Stockfish that referenced this pull request Feb 22, 2021
joergoster pushed a commit to joergoster/Stockfish-old that referenced this pull request Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be merged Will be merged shortly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants