mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Difference in pthread behavior between glibc and musl
@ 2023-07-11 19:19 Appelmans, Madeleine
  2023-07-11 19:42 ` Markus Wichmann
  2023-07-12  2:48 ` Rich Felker
  0 siblings, 2 replies; 8+ messages in thread
From: Appelmans, Madeleine @ 2023-07-11 19:19 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 818 bytes --]

Hello,

There seems to be a difference in pthread behavior when compiling with glibc and using the musl-gcc wrapper. The attached snippet of code creates a destructor attribute which deletes a pthread key. The code never actually creates the pthread key. This code segfaults when compiled using musl-gcc, and does not segfault when compiled with gcc.

Best guess at what is going on: When creating a pthread key, musl initializes a field called tsd<https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_key_create.c#n37>. When deleting a key, musl assumes that initialization has been done, and dereferences tsd without checking that it exists: see here<https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_key_create.c#n65>. This dereference may be the source of the segfault.

Thanks,
Madeleine

[-- Attachment #1.2: Type: text/html, Size: 2894 bytes --]

[-- Attachment #2: pthread_test.c --]
[-- Type: application/octet-stream, Size: 217 bytes --]

#include <pthread.h>

static pthread_key_t per_thread_key;

static void __attribute__((destructor)) key_cleanup(void)
{
    pthread_key_delete(per_thread_key);
}

int main(int argc, char **argv)
{
    // Do nothing
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-13 18:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-11 19:19 [musl] Difference in pthread behavior between glibc and musl Appelmans, Madeleine
2023-07-11 19:42 ` Markus Wichmann
2023-07-12  2:48 ` Rich Felker
2023-07-13  1:00   ` Gabriel Ravier
2023-07-13  1:50     ` Rich Felker
2023-07-13  2:02       ` Gabriel Ravier
2023-07-13 16:27         ` Markus Wichmann
2023-07-13 18:49           ` Gabriel Ravier

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).