Created attachment 15734 [details] gdb.log I build gdb with -O2, -fsanitize=thread and gcc 13, and ran into a data race in test-case gdb.trace/basic-libipa.exp: ... WARNING: ThreadSanitizer: data race (pid=16416) Write of size 4 at 0x7ffff7fc7a90 by thread T1: #0 gdb_agent_helper_thread /data/vries/gdb/src/gdbserver/tracepoint.cc:7165 (libinproctrace.so+0x148e5) (BuildId: 6c13e370f9e1c8cc0c77b4dabce7a7863681e412) #1 <null> <null> (libtsan.so.2+0x3a9a9) (BuildId: c214510b223ec7832bd9e42f5d3d7a068e0cc5ae) Previous read of size 4 at 0x7ffff7fc7a90 by main thread: #0 gdb_agent_init /data/vries/gdb/src/gdbserver/tracepoint.cc:7296 (libinproctrace.so+0x58f1) (BuildId: 6c13e370f9e1c8cc0c77b4dabce7a7863681e412) #1 initialize_tracepoint_ftlib /data/vries/gdb/src/gdbserver/tracepoint.cc:7333 (libinproctrace.so+0x5944) (BuildId: 6c13e370f9e1c8cc0c77b4dabce7a7863681e412) #2 call_init /usr/src/debug/glibc-2.31-150300.86.3.x86_64/elf/dl-init.c:72 (ld-linux-x86-64.so.2+0x115e9) (BuildId: 06cbd3d888bf0102f92e9b87f8a1847c5fb4ae47) Location is global 'gdb_agent_helper_thread_id' of size 4 at 0x7ffff7fc7a90 (libinproctrace.so+0x23a90) Thread T1 (tid=16420, running) created by main thread at: #0 pthread_create <null> (libtsan.so.2+0x40356) (BuildId: c214510b223ec7832bd9e42f5d3d7a068e0cc5ae) #1 gdb_agent_init /data/vries/gdb/src/gdbserver/tracepoint.cc:7287 (libinproctrace.so+0x58c3) (BuildId: 6c13e370f9e1c8cc0c77b4dabce7a7863681e412) #2 initialize_tracepoint_ftlib /data/vries/gdb/src/gdbserver/tracepoint.cc:7333 (libinproctrace.so+0x5944) (BuildId: 6c13e370f9e1c8cc0c77b4dabce7a7863681e412) #3 call_init /usr/src/debug/glibc-2.31-150300.86.3.x86_64/elf/dl-init.c:72 (ld-linux-x86-64.so.2+0x115e9) (BuildId: 06cbd3d888bf0102f92e9b87f8a1847c5fb4ae47) SUMMARY: ThreadSanitizer: data race /data/vries/gdb/src/gdbserver/tracepoint.cc:7165 in gdb_agent_helper_thread ================== ... Todo: reproduce with -O0.
(In reply to Tom de Vries from comment #0) > Todo: reproduce with -O0. Confirmed, also reproduces with gcc 13, -fsanitize=thread and -O0.
The race on helper_thread_id is this: ... gdb_agent_helper_thread (void *arg) ... if (helper_thread_id == 0) helper_thread_id = syscall (SYS_gettid); ... vs: ... gdb_agent_init (void) ... while (helper_thread_id == 0) usleep (1); ... Using a pthread barrier instead of a busy wait works fine, but not reliably with -fsanitize=thread, presumably because it messes with signals. Perhaps part of the problem is that there are two processes being sanitized in parallel: gdb, and libipa which is linked into the inferior.