mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl][PATCH]fix tsd's issue
@ 2023-02-14  7:25 =?gb18030?B?zcPX09bt?=
  2023-02-14 12:05 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: =?gb18030?B?zcPX09bt?= @ 2023-02-14  7:25 UTC (permalink / raw)
  To: =?gb18030?B?bXVzbA==?=


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1: Type: text/plain; charset="gb18030", Size: 492 bytes --]

Currently, I am trying to port jemalloc to musl, I have found a issue "the return value of pthread_getspecific is not correct". The reasons are as follows:
1, Jemalloc uses pthread_key_t to implement cache feature, if codes call malloc, pthread_create_key will called and tsd will be initizlized.
2, Musl calls malloc before updating TLS size in dl stage 3.
3, New created initial_tls doesn't carry builtin_tls's tsd.


The attached patch could fix this issue, please review it, thanks.

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

[-- Attachment #2: fix_tsd_issue.patch --]
[-- Type: application/octet-stream, Size: 662 bytes --]

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 09f3b0a8..94b8c776 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -2024,9 +2024,12 @@ void __dls3(size_t *sp, size_t *auxv)
 	/* Actual copying to new TLS needs to happen after relocations,
 	 * since the TLS images might have contained relocated addresses. */
 	if (initial_tls != builtin_tls) {
-		if (__init_tp(__copy_tls(initial_tls)) < 0) {
+        pthread_t self = __pthread_self();
+        phtread_t td = __copy_tls(initial_tls);
+		if (__init_tp(td) < 0) {
 			a_crash();
 		}
+        td->tsd = self->tsd;
 	} else {
 		size_t tmp_tls_size = libc.tls_size;
 		pthread_t self = __pthread_self();

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

end of thread, other threads:[~2023-02-15  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14  7:25 [musl][PATCH]fix tsd's issue =?gb18030?B?zcPX09bt?=
2023-02-14 12:05 ` Rich Felker
2023-02-14 13:44   ` Rich Felker
2023-02-15  1:45     ` [musl] =?gb18030?B?u9i4tKO6IFttdXNsXVtQQVRDSF1maXggdHNkJ3MgaXNzdWU=?= =?gb18030?B?zcPX09bt?=

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).