Skip to content

Initialization order... or something. #57

@winapiadmin

Description

@winapiadmin

I don't know how to describe this...

Step 1: build the library
Step 2:

#include <attacks.h>
int main(){
    return chess::attacks::bishop(chess::SQ_A1,0);
}

Step 3: build the program with the library
Step 4:

gdb ./a.out
GNU gdb (Ubuntu 15.1-1ubuntu1~24.04.1) 15.1
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...
(gdb) r
Starting program: /mnt/c/Users/winapiadmin/Desktop/chess_engine/build2/chesslib/a.out

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc3000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000555555555b68 in chess::attacks::generate_magic_table<chess::_chess::_HyperbolaBishopAttacks, 5248, true> () at /mnt/c/Users/winapiadmin/Desktop/chess_engine/build2/chesslib/attacks.cpp:170
170                 attacks[offset + idx] = AttackFunc(static_cast<Square>(sq), occ);
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) bt
#0  0x0000555555555b68 in chess::attacks::generate_magic_table<chess::_chess::_HyperbolaBishopAttacks, 5248, true> () at /mnt/c/Users/winapiadmin/Desktop/chess_engine/build2/chesslib/attacks.cpp:170
#1  0x0000555555555f46 in __static_initialization_and_destruction_0 () at /mnt/c/Users/winapiadmin/Desktop/chess_engine/build2/chesslib/attacks.cpp:180
#2  0x0000555555556000 in _GLOBAL__sub_I__ZN5chess7attacks10RookMagicsE () at /mnt/c/Users/winapiadmin/Desktop/chess_engine/build2/chesslib/attacks.cpp:211
#3  0x00007ffff7c2a304 in call_init (env=<optimized out>, argv=0x7fffffffd708, argc=1) at ../csu/libc-start.c:145
#4  __libc_start_main_impl (main=0x5555555551a9 <main>, argc=1, argv=0x7fffffffd708, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd6f8) at ../csu/libc-start.c:347
#5  0x00005555555550e5 in _start ()
(gdb) quit
A debugging session is active.

        Inferior 1 [process 1337] will be killed.

Quit anyway? (y or n) y

Workaround: Move rook and bishop attack generation to source file

... but why?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions