https://bugs.kde.org/show_bug.cgi?id=380269
--- Comment #4 from Louis Brunner <louis.brunner...@gmail.com> --- Created attachment 109303 --> https://bugs.kde.org/attachment.cgi?id=109303&action=edit Fix crash when using multithreading on Mac OS X >= 10.12 I have finally managed to fix the issue that made pthread SIGSEGV when starting a new thread. The issue was related to the TSD. In _pthread_body, an inline function called __pthread_add_thread is called, which locks a mutex using a os_unfair_lock_lock function from libplatform. These functions use the TSD while calling _os_lock_owner_get_self to retrieve the current the current MAC Thread using _os_tsd_get_direct(__TSD_MACH_THREAD_SELF). Looking at this last function will reveal a `__asm__("mov %%gs:%1, %0" : "=r" (ret) : "m" (*(void **)(slot * sizeof(void *))));`, knowing that __TSD_MACH_THREAD_SELF is 3, that outputs the `mov %gs:0x18,%ecx` that was causing problems. Now, I don't know why GS_CONST is suddenly 0 instead of the TSD address, but I found that pthread keeps the latter in its pthread_t structure and that it conveniently gives us the offset in an internal structure passed to bsdthread_register by _pthread_bsdthread_init (4th argument). In syswrap-darwin.c, we already store a few arguments passed to bsdthread_register, so I added a new one, which is the offset of the TSD member in the pthread_t structure. While starting the new thread in pthread_hijack, we can then set the value of GS_CONST to self (current pthread_t address) + pthread_tsd_offset. The program then executes normally when using pthread and multithreading. Note that a lot of programs (including yours Alexandru) still crash or malfunction (mismanagement of signals, ...) once they start running. However these issues seem unrelated to this particular pthread problem. -- You are receiving this mail because: You are watching all bug changes.