anael-seghezzi / CToy

Interactive C live coding environment
Other
1.36k stars 71 forks source link

CToy crashes with SIGSEGV from libpthead.so, Arch Linux #14

Closed Smilex closed 4 years ago

Smilex commented 7 years ago

This wasn't an isssue on my machine with Ubuntu, but my laptop with Arch Linux. It's only relevant for the CToy executable. CToy_player does work, which makes sense because it doesn't compile with the thread stuff. What is the idea behind these two executables, CToy and CToy_player?

I upgraded my entire system, and I still get the error, meaning that this fails with libpthread version 2.25 and 2.26.

Thread 1 "CToy" received signal SIGSEGV, Segmentation fault. 0x00007ffff768d29e in pthread_join () from /usr/lib/libpthread.so.0 (gdb) bt

0 0x00007ffff768d29e in pthread_join () from /usr/lib/libpthread.so.0

1 0x000000000047b7f1 in thrd_join ()

2 0x0000000000464cbf in ctoy.src_thread_restart ()

3 0x000000000043c579 in main ()

anael-seghezzi commented 7 years ago

What is the version of libpthread in your Ubuntu ? Does it still crash if you run a version compiled on your Arch linux ?

CToy enables live coding, it recompiles when the source code is modified, that's what run in the thread. CToy_player just compiles at the beginning (no live coding).

Smilex commented 7 years ago

The ubuntu version is 2.23, and yes it still crashes with the same backtrace, when compiled on Arch

anael-seghezzi commented 7 years ago

I'm not sure but it's possible you may have to recompile libtcc.so too on Arch. It would be surprising if the bug is related to libpthead. Or the bug comes from the code running in the thread, or something related to libtcc and (maybe) the version of glibc used to compile libtcc.

anael-seghezzi commented 7 years ago

If the version of glibc used to commile libtcc.so on ubuntu is more recent than glibc used in Arch linux it could cause a crash on certain conditions (except if you already recompiled libtcc).

Smilex commented 7 years ago

Sorry about the delay. I compiled libtcc on this Arch laptop, and I still get the same issue with the same bt. However I do find the different versions of GLIBC mentioned in the following weird. Remember that ldd --version gives me 2.26, so these are 3 different versions where I would expect one.

[ian@arch MTCL]$ readelf -s CToy | grep pthread 6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_getspecific@GLIBC_2.2.5 (3) 9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_destroy@GLIBC_2.3.2 (4) 17: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_timedlock@GLIBC_2.2.5 (3) 21: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_setspecific@GLIBC_2.2.5 (3) 33: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_signal@GLIBC_2.3.2 (4) 38: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_destroy@GLIBC_2.2.5 (3) 55: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_timedwait@GLIBC_2.3.2 (4) 67: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_init@GLIBC_2.2.5 (3) 87: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_create@GLIBC_2.2.5 (3) 91: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_init@GLIBC_2.3.2 (4) 98: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_delete@GLIBC_2.2.5 (3) 106: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_self@GLIBC_2.2.5 (3) 107: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_join@GLIBC_2.2.5 (3) 109: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_trylock@GLIBC_2.2.5 (3) 115: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_exit@GLIBC_2.2.5 (3) 142: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_settype@GLIBC_2.2.5 (3) 163: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_wait@GLIBC_2.3.2 (4) 164: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_detach@GLIBC_2.2.5 (3) 192: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_lock@GLIBC_2.2.5 (3) 195: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_init@GLIBC_2.2.5 (3) 198: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_create@GLIBC_2.2.5 (3) 199: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_destroy@GLIBC_2.2.5 (3) 201: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_broadcast@GLIBC_2.3.2 (4) 207: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_unlock@GLIBC_2.2.5 (3) 350: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_getspecific@@GLIB 365: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_destroy@@GLI 477: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_timedlock@@ 655: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_setspecific@@GLIB 830: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_signal@@GLIB 906: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_destroy 1263: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_timedwait@@G 1389: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_init@@GLIBC 1769: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_create@@GLIBC_2.2 1793: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_condinit@@GLIBC 1929: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_delete@@GLIBC 2152: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_self@@GLIBC_2.2.5 2173: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_join@@GLIBC_2.2.5 2204: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_trylock@@GL 2326: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_exit@@GLIBC_2.2.5 2940: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_settype 3258: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_condwait@@GLIBC 3310: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_detach@@GLIBC_2.2 3827: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_lock@@GLIBC 3886: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutexattr_init@@G 3914: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_create@@GLIBC 3959: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_destroy@@GL 4010: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_broadcast@@G 4087: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_mutex_unlock@@GLI

anael-seghezzi commented 7 years ago

Ok, let's try to locate the bug more precisely. Try this two different things : A: Comment the code inside "ctoysrc_thread_init", does it still crash ? B: Comment the code inside "ctoyio_replace", does it still crash ?

I'm wondering if there is not a conflict between tinycthread.h and threads.h with the function name thrd_***. Check that everything is compiled in ANSI-C99 (no C11).

cwkx commented 6 years ago

also getting this, the crash can be preventing by commenting any of:

140: thrd_join(ctoysrc_thread_id, NULL); 146: ctoysrc_thread_destroy(); 541: ctoy__src_thread_restart();

do you need to call ctoy__src_thread_restart(); in line 541?

(edit: the live reloading also didn't seem to be working, unless I was doing it wrong)

anael-seghezzi commented 6 years ago

Are you also on Arch Linux ? What version of glibc is it bundled with ?

cwkx commented 6 years ago

yep, 2.26

anael-seghezzi commented 6 years ago

It may be caused by a glibc bug : https://sourceware.org/bugzilla/show_bug.cgi?id=20116