This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] malloc: Perform full initialization before __malloc_check_init
- From: Florian Weimer <fweimer at redhat dot com>
- To: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>, "dj at redhat dot com" <dj at redhat dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Thu, 21 Sep 2017 21:27:12 +0200
- Subject: Re: [PATCH] malloc: Perform full initialization before __malloc_check_init
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 73DC43680B
- References: <DB6PR0801MB20538CD798C77046B743F7B083660@DB6PR0801MB2053.eurprd08.prod.outlook.com>
On 09/21/2017 08:15 PM, Wilco Dijkstra wrote:
Florian Weimer wrote:
Well it looks like the malloc initialization is insane. It sets default hooks for
malloc/realloc/etc which call ptmalloc_init, which is completely unguarded
from multi-threaded execution...
I have tried to explain repeatedly why this is not a problem:
pthread_create calls malloc before launching a new thread, so
ptmalloc_init is always run in single-thread mode.
Then it implicitly relies on have_fastchunks
being true (from zero-initialization of main_arena by inverting the meaning of
the flag), which should eventually result in a call to malloc_consolidate, which
assuming max_fast hasn't yet been set, finally calls malloc_init_state...
Sure, it's convoluted.
+ {
+ /* Perform full initialization. */
+ malloc_consolidate (&main_arena);
+ __malloc_check_init ();
+ }
That's an improvement but ptmalloc_init should call malloc_init_state (&main_arena)
in all cases. The check in malloc_consolidate should then be removed (no idea why
anyone would want to delay initialization to that point...). Interestingly malloc_init_state
is called for other arenas...
I didn't want to touch until we remove the hooks and have to overhaul
the initialization procedure anyway (i.e., detect whether malloc has
been interposed, and if not, perform malloc initialization during
process startup before calling ELF constructors and main).
Thanks,
Florian