From: =?gb18030?B?zcPX09bt?= <3264430019@qq.com>
To: =?gb18030?B?bXVzbA==?= <musl@lists.openwall.com>
Subject: [musl][PATCH]fix tsd's issue
Date: Tue, 14 Feb 2023 15:25:23 +0800 [thread overview]
Message-ID: <tencent_EA207C332C3F691FF207DFE6DB8F7B9DD807@qq.com> (raw)
[-- 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();
next reply other threads:[~2023-02-14 7:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 7:25 =?gb18030?B?zcPX09bt?= [this message]
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?=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_EA207C332C3F691FF207DFE6DB8F7B9DD807@qq.com \
--to=3264430019@qq.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).