From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: pthread_key_create bug?
Date: Mon, 7 Jan 2019 18:13:28 +0100 [thread overview]
Message-ID: <20190107171327.GD29911@voyager> (raw)
In-Reply-To: <20190107021128.GW23599@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 1147 bytes --]
On Sun, Jan 06, 2019 at 09:11:28PM -0500, Rich Felker wrote:
> See commit 84d061d5a31c9c773e29e1e2b1ffe8cb9557bc58.
>
> Rich
Speaking of that commit: Am I missing something? The log message of that
commit says that pthread_key_delete was stuffed into another file to
avoid __synccall() being pulled into programs not referencing
pthread_key_delete(). Yet pthread_key_create.c contains
clean_dirty_tsd(), which contains a hard dependency on
__pthread_key_delete_synccall(), which will do the synccall, and thus
pull everything in.
I appreciate that the function in question can never be called unless
pthread_key_delete() is used, but the linker can't know that. The
compiler can't see code of the other compilation units and thus has to
generate code containing a reference to __pthread_key_delete_synccall(),
and the linker can't see that the reference is unreachable unless
__pthread_key_delete() is linked in...
Wait a minute. If we made that a weak reference, that would already
suffice. Wouldn't even necessarily need an alias, since it is
unreachable without pthread_key_delete() anyway.
Is the attached patch acceptable?
Ciao,
Markus
[-- Attachment #2: 0004-Add-weak-reference-to-reduce-static-size.patch --]
[-- Type: text/x-diff, Size: 1186 bytes --]
From 851f8bb89d9fae664a0d6018fce251ab64d737b7 Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
Date: Mon, 7 Jan 2019 18:07:34 +0100
Subject: [PATCH 4/4] Add weak reference to reduce static size.
Commit 84d061d5a31c9c773e29e1e2b1ffe8cb9557bc58 claimed to try and
reduce the static size for programs referencing pthread_key_create() but
not pthread_key_delete(). Unfortunately, the critical reference was
still strong, so the __synccall() mechanism was pulled in, anyway. This
commit makes the reference weak, so it is resolved to NULL if
pthread_key_delete() is not used, but in that case the function is
unreachable, anyway.
---
src/thread/pthread_key_create.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c
index e26f199c..31ed0826 100644
--- a/src/thread/pthread_key_create.c
+++ b/src/thread/pthread_key_create.c
@@ -35,6 +35,8 @@ static void clean_dirty_tsd_callback(void *p)
if (args->caller == self) args->ret = 0;
}
+extern hidden weak void __pthread_key_delete_synccall(void (*f)(void *), void *p);
+
static int clean_dirty_tsd(void)
{
struct cleanup_args args = {
--
2.19.1
next prev parent reply other threads:[~2019-01-07 17:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-06 14:35 Nathaniel Pierce
2019-01-06 14:50 ` A. Wilcox
2019-01-06 16:28 ` Szabolcs Nagy
2019-01-07 2:11 ` Rich Felker
2019-01-07 12:24 ` A. Wilcox
2019-01-07 14:12 ` Rich Felker
2019-01-07 17:13 ` Markus Wichmann [this message]
2019-01-08 0:00 ` Rich Felker
2019-01-08 8:43 ` u-uy74
2019-01-08 19:34 ` Markus Wichmann
2019-01-08 22:40 ` writeonce
2019-01-08 22:10 ` Markus Wichmann
2019-01-08 23:07 ` A. Wilcox
2019-01-09 0:29 ` Rich Felker
2019-01-09 11:45 ` Szabolcs Nagy
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=20190107171327.GD29911@voyager \
--to=nullplan@gmx.net \
--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).