TerjeKir / weiss

Weiss - a UCI chess engine
GNU General Public License v3.0
99 stars 18 forks source link

Compilation error with GCC 13.1 in msys2 [Win7 ;)] #680

Open rwbc opened 10 months ago

rwbc commented 10 months ago

This error might be related to another new check in GCC, as referred in: https://github.com/TerjeKir/weiss/issues/677

Guenther Simon@CAPPUCCINO MINGW64 ~/weiss/src
$ make pgo
gcc -std=gnu11 -Wall -Wextra -Wshadow -Werror -Wmissing-declarations -O3 -flto -march=native -static -DNDEBUG *.c pyrrhic/tbprobe.c tuner/*.c query/*.c noobprobe/*.c onlinesyzygy/*.c -pthread -lm -lwsock32 -o weiss -fprofile-generate="pgo"
lto-wrapper.exe: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper.exe: note: see the '-flto' option documentation for more information
search.c: In function 'IterativeDeepening':
search.c:664:13: error: '<anonymous>' is used uninitialized [-Werror=uninitialized]
  664 |         if (setjmp(thread->jumpBuffer)) break;
      |             ^
search.c:664:13: error: '<anonymous>' is used uninitialized [-Werror=uninitialized]
lto1.exe: all warnings being treated as errors
lto-wrapper.exe: fatal error: C:\msys64\mingw64\bin\gcc.exe returned 1 exit status
compilation terminated.
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:80: pgo] Error 1

The error disappears when removing the -flto flag.

output from cmd (old quadcore Q8200)

uci
id name Weiss 2.1-dev r686
id author Terje Kirstihagen
option name Hash type spin default 32 min 2 max 33554432
option name Threads type spin default 1 min 1 max 2048
option name SyzygyPath type string default <empty>
option name MultiPV type spin default 1 min 1 max 64
option name UCI_Chess960 type check default false
option name NoobBook type check default false
option name NoobBookLimit type spin default 0 min 0 max 1000
option name OnlineSyzygy type check default false
uciok
isready
readyok
position startpos
go infinite
info depth 1 seldepth 1 multipv 1 score cp 68 time 1 nodes 49 nps 24500 tbhits 0 hashfull 0 pv b1c3
info depth 2 seldepth 2 multipv 1 score cp 49 time 18 nodes 133 nps 7000 tbhits 0 hashfull 0 pv b1c3 b8c6
info depth 3 seldepth 3 multipv 1 score cp 68 time 35 nodes 221 nps 6138 tbhits 0 hashfull 0 pv b1c3
info depth 4 seldepth 6 multipv 1 score cp 40 time 51 nodes 2227 nps 42826 tbhits 0 hashfull 1 pv b1c3 e7e6 e2e3 d7d5
info depth 5 seldepth 8 multipv 1 score cp 53 time 73 nodes 3326 nps 44945 tbhits 0 hashfull 1 pv b1c3 e7e6 e2e3 d7d5
info depth 6 seldepth 11 multipv 1 score cp 41 time 131 nodes 54075 nps 409659 tbhits 0 hashfull 8 pv b1c3 b8c6 e2e3 d7d5 d2d4 e7e6
info depth 7 seldepth 13 multipv 1 score cp 59 time 170 nodes 78542 nps 459309 tbhits 0 hashfull 14 pv b1c3 d7d5 e2e3 d8d7 d2d4 g8f6
info depth 8 seldepth 17 multipv 1 score cp 53 time 733 nodes 800978 nps 1091250 tbhits 0 hashfull 140 pv b1c3 d7d5 g1f3 g8f6 d2d4 e7e6 e2e3 f6e4
info depth 9 seldepth 20 multipv 1 score cp 63 time 2793 nodes 3579149 nps 1281012 tbhits 0 hashfull 450 pv e2e3 g8f6 d2d4 e7e6 g1f3 b8c6 c2c4 f8e7 b1c3
info depth 10 seldepth 17 multipv 1 score cp 71 time 2830 nodes 3589461 nps 1267912 tbhits 0 hashfull 451 pv d2d4 g8f6 e2e3 e7e6 g1f3 f8e7 f1e2 e8g8 e1g1 f6e4 b1c3
info depth 11 seldepth 19 multipv 1 score cp 68 time 2868 nodes 3603454 nps 1255996 tbhits 0 hashfull 453 pv d2d4 g8f6 e2e3 e7e6 g1f3 f8e7 f1e2 d7d5 e1g1 b8c6 f3e5 c6e5 d4e5 f6e4 c2c3
info depth 12 seldepth 21 multipv 1 score cp 82 time 2909 nodes 3618253 nps 1243385 tbhits 0 hashfull 454 pv d2d4 d7d5 e2e3 b8c6 g1f3 e7e6 b1d2 f8e7 c2c4 g8f6 c4d5
info depth 13 seldepth 25 multipv 1 score cp 85 lowerbound time 3011 nodes 3691091 nps 1225461 tbhits 0 hashfull 463 pv e2e4
info depth 13 seldepth 25 multipv 1 score cp 88 time 3043 nodes 3703641 nps 1216702 tbhits 0 hashfull 466 pv e2e4 d7d5 e4d5 g8f6 f1b5 c8d7 b5d7 d8d7 g1f3 f6d5 e1g1 b8c6 b1c3 e7e6 d2d3
info depth 14 seldepth 26 multipv 1 score cp 76 upperbound time 3132 nodes 3760083 nps 1200154 tbhits 0 hashfull 474 pv e2e4 e7e6
info depth 14 seldepth 29 multipv 1 score cp 85 time 3166 nodes 3772053 nps 1191049 tbhits 0 hashfull 477 pv e2e4 e7e6 g1f3 d7d5 e4d5 e6d5 d2d4 g8f6 f1d3 f8e7 e1g1 e8g8 c1g5 d8d7 f1e1 b8c6
info depth 15 seldepth 28 multipv 1 score cp 75 time 3264 nodes 3838830 nps 1175751 tbhits 0 hashfull 487 pv e2e4 e7e6 g1f3 d7d5 e4d5 e6d5 d2d4 g8f6 f1d3 f8d6 e1g1 e8g8 f1e1 b8c6 b1c3 c8g4
info depth 16 seldepth 29 multipv 1 score cp 75 time 3373 nodes 3912305 nps 1159545 tbhits 0 hashfull 499 pv e2e4 e7e6 g1f3 d7d5 e4d5 e6d5 d2d4 g8f6 f1d3 f8d6 e1g1 e8g8 c2c3 b8c6 c1g5 d6e7 f1e1 f6e4 g5e7
info depth 17 seldepth 30 multipv 1 score cp 63 upperbound time 3659 nodes 4155130 nps 1135281 tbhits 0 hashfull 539 pv e2e4 e7e6
info depth 17 seldepth 30 multipv 1 score cp 78 lowerbound time 3997 nodes 4444708 nps 1111732 tbhits 0 hashfull 586 pv e2e4
info depth 17 seldepth 30 multipv 1 score cp 70 time 4098 nodes 4507072 nps 1099554 tbhits 0 hashfull 595 pv e2e4 e7e6 d2d4 d7d5 e4d5 e6d5 f1d3 f8d6 d1e2 g8e7 g1f3 e8g8 e1g1 c8f5 f1e1 b8c6
info depth 18 seldepth 29 multipv 1 score cp 82 lowerbound time 4622 nodes 4966906 nps 1074390 tbhits 0 hashfull 658 pv d2d4
info depth 18 seldepth 29 multipv 1 score cp 79 time 4680 nodes 5008799 nps 1070027 tbhits 0 hashfull 665 pv d2d4 e7e6 g1f3 g8f6 c2c4 b8c6 b1c3 d7d5 e2e3 f8b4 d1c2 e8g8 c4d5 e6d5 f1d3 f6e4 e1g1 b4c3
info depth 19 seldepth 31 multipv 1 score cp 67 upperbound time 5041 nodes 5315522 nps 1054248 tbhits 0 hashfull 695 pv d2d4 e7e6
info depth 19 seldepth 31 multipv 1 score cp 55 upperbound time 5705 nodes 5918391 nps 1037222 tbhits 0 hashfull 751 pv d2d4 e7e6
info depth 19 seldepth 31 multipv 1 score cp 71 lowerbound time 5985 nodes 6160567 nps 1029162 tbhits 0 hashfull 771 pv d2d4
info depth 19 seldepth 31 multipv 1 score cp 81 time 6064 nodes 6219333 nps 1025446 tbhits 0 hashfull 777 pv d2d4 e7e6 e2e4 d7d5 e4d5 e6d5 g1f3 g8f6 f1d3 d8e7 d3e2 c8e6 e1g1 b8c6 b1c3 e8c8 c1f4 a7a6 f3g5 c8b8 g5e6
info depth 20 seldepth 34 multipv 1 score cp 72 time 6480 nodes 6563792 nps 1012774 tbhits 0 hashfull 799 pv d2d4 e7e6 e2e4 d7d5 e4d5 e6d5 g1f3 g8f6 f1d3 f8e7 e1g1 e8g8 c2c3 c7c5 c1f4 d8b6 b1d2 b6b2 d1b3 b2b3 a2b3 b8c6
info depth 21 seldepth 35 multipv 1 score cp 74 time 7658 nodes 7609924 nps 993592 tbhits 0 hashfull 866 pv d2d4 e7e6 e2e4 d7d5 e4d5 e6d5 g1f3 g8f6 f1d3 f8e7 e1g1 e8g8 c2c3 c7c5 h2h3 c5c4 d3c2 b8c6 f1e1 e7d6 c1g5 c8e6 b1d2
info depth 22 seldepth 36 multipv 1 score cp 62 upperbound time 9324 nodes 9077740 nps 973484 tbhits 0 hashfull 920 pv d2d4 e7e6
info depth 22 seldepth 36 multipv 1 score cp 77 lowerbound time 10378 nodes 10007425 nps 964199 tbhits 0 hashfull 946 pv d2d4
info depth 22 seldepth 36 multipv 1 score cp 73 time 10558 nodes 10151833 nps 961438 tbhits 0 hashfull 950 pv d2d4 e7e6 e2e4 d7d5 e4d5 e6d5 g1f3 g8f6 f1d3 f8e7 e1g1 e8g8 h2h3 c7c5 d4c5 e7c5 c2c3 f6e4 d1c2 f8e8 b1d2 c5f2 f1f2 e4f2
info depth 23 seldepth 37 multipv 1 score cp 61 upperbound time 15608 nodes 14635752 nps 937648 tbhits 0 hashfull 991 pv d2d4 g8f6
info depth 23 seldepth 37 multipv 1 score cp 76 lowerbound time 16432 nodes 15352589 nps 934253 tbhits 0 hashfull 993 pv d2d4
info depth 23 seldepth 37 multipv 1 score cp 85 time 18391 nodes 17118364 nps 930750 tbhits 0 hashfull 995 pv d2d4 g8f6 c2c4 d7d6 b1c3 b8d7 g2g3 e7e5 e2e3 g7g6 f1g2 f8g7 g1e2 e8g8 b2b3 e5d4 e3d4 d8e7 e1g1 c7c6 f1e1 f8e8 h2h3
TerjeKir commented 10 months ago

Hey, thanks for the report. The error message doesn't make sense to me, and it seems to not happen with GCC 13.2 on another machine, so I'm guessing a GCC issue for now - when msys releases 13.2 can you let me know if you still get this?

skiminki commented 10 months ago

@rwbc I got a clean build with GCC 13.2 (-flto enabled), although that was on Linux.

I see at least one potentially related bug fix in GCC ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110228 ), so this could be a problem in GCC 13.1.

The error message would hint at either compiler internals (anonymous variable access) or setjmp() internals. If this was a Weiss issue, then by default I'd expect something more specific than '\<anonymous>'. Also, I don't quite see what would be wrong with Weiss to trigger this.

skiminki commented 10 months ago

Actually, not quite sure what's this about. I tried gcc 13.1 (via https://hub.docker.com/_/gcc) and Weiss still compiles and benches fine for me. Perhaps this is an msys2-related issue.

root@ea2540b3bbc7:/weiss/src# gcc --version
gcc (GCC) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@ea2540b3bbc7:/weiss/src# make pgo
gcc -std=gnu11 -Wall -Wextra -Wshadow -Werror -Wmissing-declarations -O3 -flto -march=native -DUSE_PEXT -DNDEBUG *.c pyrrhic/tbprobe.c tuner/*.c query/*.c noobprobe/*.c onlinesyzygy/*.c -pthread -lm -o weiss -fprofile-generate="pgo"
lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more information
./weiss bench 12 > /dev/null 2>&1
gcc -std=gnu11 -Wall -Wextra -Wshadow -Werror -Wmissing-declarations -O3 -flto -march=native -DUSE_PEXT -DNDEBUG *.c pyrrhic/tbprobe.c tuner/*.c query/*.c noobprobe/*.c onlinesyzygy/*.c -pthread -lm -o weiss -fprofile-use="pgo"
lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more information

root@ea2540b3bbc7:/weiss/src# ./weiss bench | tail -n 1
OVERALL:    4373 ms      22069011 nodes    5046652 nps
TerjeKir commented 10 months ago

Thanks for taking the time to look into it @skiminki, much appreciated 👍

rwbc commented 10 months ago

Hey, thanks for the report. The error message doesn't make sense to me, and it seems to not happen with GCC 13.2 on another machine, so I'm guessing a GCC issue for now - when msys releases 13.2 can you let me know if you still get this?

I am doing an upgrade right now and try again later.

rwbc commented 10 months ago

There is the same gcc error complaining with 13.2 here.

Out of curiosity I tried to recompile rev 602, which didn't show this error when compiled in March 7 and it now also shows this error with 13.2 (and also the unsignedness error of #677, which I applied the fix for). Originally I compiled rev with GCC 11.2 at that time.

So it seems it is some additional nit-picking in GCC 13.x and may be the one remaining for me just for Win?

TerjeKir commented 10 months ago

Seems that way, yeah. For now I'll recommend just removing -Werror so it compiles despite the warning.

skiminki commented 10 months ago

So it seems it is some additional nit-picking in GCC 13.x and may be the one remaining for me just for Win?

Yes, so I'm suspecting that there is some bad interaction between the mingw implementation of setjmp() and GCC 13 with flto. The declarations are here:

https://sourceforge.net/p/mingw-w64/mingw-w64/ci/0622020e9e2be8a39bb22f60ab1a22d2e9fa4995/tree/mingw-w64-headers/crt/setjmp.h

The unusual things about mingw setmp() are:

I think it is a plausible guess that the unusual things (one or the other or a combination) could trigger the spurious warning about using an anonymous object without initialization. This looks to be a bug in mingw (part of msys2) and/or GCC 13, and my suspicion is that it's the latter, since it's triggered only by flto.

The flto optimization does extra passes related to internal representation of sources (GIMPLE stuff). It is possible that there is an oversight related to the aforementioned attributes. In general, returns_twice is basically only ever used by fork()/setjmp() functions and their variants. This combination of attributes and built-ins looks to be mingw-specific.

skiminki commented 10 months ago

Ok, I was able to repro this on Linux with some hacks. It's the returns_twice attribute in combination with __builtin_frame_address(0) that triggers this issue for external functions. I'll investigate this a bit more.

skiminki commented 10 months ago

I figured out a minimal repro:

int threadIndex = 1;
int __attribute__ ((__returns_twice__)) _setjmpex(void *context);

int main(int argc, char **argv)
{
    int mainThread = threadIndex;

    while (!mainThread) {
        _setjmpex(__builtin_frame_address (0));
        if (threadIndex) break;
    }

    return 0;
}

Compile this with: gcc-13.2 -c -O2 -Wuninitialized -Werror and you'll see the error.

Checking with godbolt, this seems to be a regression in gcc-12. Reference: https://godbolt.org/z/Mv5b5rc75

I'll double-check the GCC bug database and file an issue later.

TerjeKir commented 10 months ago

Very cool! Hope to see it fixed before long :)

skiminki commented 9 months ago

The GCC bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

This seems to be fixed on GCC trunk as a side effect of something else, so I'd guess GCC 14 won't be affected.

skiminki commented 9 months ago

Well, that was fast. The GCC issue is already fixed in GCC trunk (was an issue there after all but the warning print was missing, I guess). Backport to GCC 13.x to follow.

As a result, piece of distilled Weiss gets to live in GCC as a test case to protect against future regressions: https://gcc.gnu.org/g:92ea12ea99fce546772a40b7bbc2ea850db9b1be :)

I'd suggest keeping this issue open until we can verify the fix with msys2/mingw. That said, no strong opinions about this.

TerjeKir commented 9 months ago

Fast indeed! Cool stuff, I'll leave this open as you suggested :)

TerjeKir commented 3 weeks ago

Made the mistake of updating my msys gcc and was stuck with this issue for about half a year. msys finally updated to 14.1 so now it works again lol