https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86257
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code, wrong-debug Target| |x86_64-*-* Status|UNCONFIRMED |NEW Last reconfirmed| |2018-06-21 Version|4.4.7 |8.1.1 Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Testcase from stackoverflow #include <pthread.h> #include <stdlib.h> #include <stdio.h> #define MAX_NUMBER_OF_THREADS 2 struct mystruct { int x; int y; }; __thread struct mystruct obj; void* threadMain(void *args) { obj.x = 1; obj.y = 2; printf("obj.x = %d\n", obj.x); printf("obj.y = %d\n", obj.y); return NULL; } int main(int argc, char *arg[]) { pthread_t tid[MAX_NUMBER_OF_THREADS]; int i = 0; for(i = 0; i < MAX_NUMBER_OF_THREADS; i++) { pthread_create(&tid[i], NULL, threadMain, NULL); } for(i = 0; i < MAX_NUMBER_OF_THREADS; i++) { pthread_join(tid[i], NULL); } return 0; } and my reproduction with GCC 8: > gcc-8 t.c -g -lpthread -fPIC > gdb ./a.out GNU gdb (GDB; devel:gcc) 8.1 Copyright (C) 2018 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-suse-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://bugs.opensuse.org/>. 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...done. (gdb) b threadMain Breakpoint 1 at 0x4006cf: file t.c, line 15. (gdb) r Starting program: /tmp/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7ffff781d700 (LWP 12830)] [New Thread 0x7ffff701c700 (LWP 12831)] [Switching to Thread 0x7ffff781d700 (LWP 12830)] Thread 2 "a.out" hit Breakpoint 1, threadMain (args=0x0) at t.c:15 15 obj.x = 1; (gdb) p obj.x $1 = 0 (gdb) n Thread 2 "a.out" received signal SIGSEGV, Segmentation fault. threadMain (args=0x0) at t.c:15 15 obj.x = 1;