https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86370
Bug ID: 86370 Summary: try/catch exception in thread cause segmentation fault Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: airbak.li at huawei dot com Target Milestone: --- 1. Code: #include <stdio.h> #include <pthread.h> #include <unistd.h> #include <stdlib.h> void* func(void *arg) { try { int error = *(int *)arg; printf("thread error start:\n"); throw error; printf("thread error:\n"); } catch(int error) { printf("catch error:%d\n",error); } printf("catch finish\n"); } int main() { pthread_t thread1; int a =1; if(pthread_create(&thread1,NULL,func,&a) != 0) { printf("create thread failed\n"); return -1; } sleep(10); return 0; } 2. Compile: arm-linux-g++ threadcatch.cpp -std=c++11 -pthread -static 3. Segmentation fault. Thread 2 "a.out" received signal SIGSEGV, Segmentation fault. [Switching to LWP 1480] __cxxabiv1::__cxa_throw (obj=0xb60014f8, tinfo=0xae484 <typeinfo for int>, dest=0x0) at ../../../../gcc-6.2/libstdc++-v3/libsupc++/eh_throw.cc:66 66 ../../../../gcc-6.2/libstdc++-v3/libsupc++/eh_throw.cc: No such file or directory. (gdb) bt #0 __cxxabiv1::__cxa_throw (obj=0xb60014f8, tinfo=0xae484 <typeinfo for int>, dest=0x0) at ../../../../gcc-6.2/libstdc++-v3/libsupc++/eh_throw.cc:66 #1 0x00010534 in func(void*) () #2 0x0001fa54 in start_thread (arg=0xb69fc300) at pthread_create.c:335 #3 0x0003e410 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:86 4. This bug also in gcc-6.2.1 + glibc-2.3 gcc-6.3.1 + glibc-2.3 gcc-6.4.1 + glibc-2.3 5. We found it has been solved in gcc-7.1.1 + glibc-2.5 6. Request: I'm not sure this bug is caused by gcc or glibc, Please give me some advice, thanks.