From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13581 Path: news.gmane.org!.POSTED!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: pthread_key_create bug? Date: Mon, 7 Jan 2019 18:13:28 +0100 Message-ID: <20190107171327.GD29911@voyager> References: <84B22C11-AA93-47FD-8352-A4F18B19F689@gmail.com> <5c1d9cf6-1b53-7082-5dee-8673ed4c55e9@adelielinux.org> <20190107021128.GW23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" X-Trace: blaine.gmane.org 1546881125 16307 195.159.176.226 (7 Jan 2019 17:12:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 7 Jan 2019 17:12:05 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-13597-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 07 18:12:01 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ggYRV-00048O-4S for gllmg-musl@m.gmane.org; Mon, 07 Jan 2019 18:12:01 +0100 Original-Received: (qmail 30321 invoked by uid 550); 7 Jan 2019 17:14:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30303 invoked from network); 7 Jan 2019 17:14:10 -0000 Content-Disposition: inline In-Reply-To: <20190107021128.GW23599@brightrain.aerifal.cx> X-Provags-ID: V03:K1:iUWcgbeZ2VKv4RAgg66rUGfzqDFtmXnWsY2wJ4vAj343ANBvGWi jAxHWTuutD+oWENMO7/YaOdkpth720u9zwTcmP0cdXaTq7ReAnEn+WCmf0dXMzqQBm0O+a5 bkKiCb2WjS4V9PneNmooiRP+8XH98tHm8i6bTHsD0mbhtXpSixVSWphugxgX2jFb9O4N0/+ DzBNVvjKzE0ZKZpobRC1Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:54EtCAMSHdY=:hZVLflji4XE2EjLRpWrQN0 VqtTrRMmkj+k8O8flsYqcBFEvJr84hvRoea56ihIrjLGoK2DTHL/nKuqn/EjWwA14kIM0F9/k 5SSKMz+tx9ivZ2sZ489MDS2T7o52KWE8nWsEH/cgAPCPRaZbdvwtxlqB3k6ffSXdnDw8xKPWV VsDMG4IJxR8xYJIq887AvrGMeEudZrc2v/CjBUY/g99my3kmFlUpY+ceEHB0Qb9pBNTOpI876 9rO+Hs9Hmoh+RO38yeKzg7jDZUoFPOTSgzg582CgAicwOYVN29dU1o1F0L1Igk1KWlOzyZdIA CPu6/S6HMMRjhdiX/BUbn9Jljq4lR/DG80UwybffEx1u1wJdbyV8xyZNMG6WjGz+EXuz1dReS 2QRacsZG7Ju7GEMYvNq2ydLFybL8RgwR+4bO1jzi7f4+gHCk9qJZl2uX4D8ksI6urhxcXuzKX 5qKpSvEgdiuIrV4btiUwij8WSKz1Ai5hLOtVFPP2M9oofpkbv6fUEfWF960ohUd3wPkNLiL68 U5A4lJXQs9mDfCECuh2SgQaU/wzfh4Vsp2QYCbAiWwgNd8LmZ8oBttWG5Oj/8ftR4360tGgYA MNKZjsDto/CCXKlhGyfgCsMuaGVk6nBzEBQ9GrVqZTV1OpfcPUkMwhlGbh9wVZhM7pKL/92oM /GtjnQ5WnjQ3zfGP+0nILQDszd1rStbbXr3N25ptbaYAR79XM++hVQyh907304s1mDB2DNOYt /6rGu6retzrfCxGDD2G3LSJy2aikg78SfF+xLEn8zQww0YZmoq6Vh1e9akCJ+pfPq8RwjzAH Xref: news.gmane.org gmane.linux.lib.musl.general:13581 Archived-At: --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --ZPt4rx8FFjLCG7dd Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0004-Add-weak-reference-to-reduce-static-size.patch" >From 851f8bb89d9fae664a0d6018fce251ab64d737b7 Mon Sep 17 00:00:00 2001 From: Markus Wichmann 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 --ZPt4rx8FFjLCG7dd--