[PATCH v3] malloc: Improve malloc initialization
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri May 9 10:10:55 GMT 2025
Hi Florian,
>>>> Move malloc initialization to __libc_early_init. Use a hidden __ptmalloc_init
>>>> for initialization and a weak call to avoid pulling in the system malloc in a
>>>> static binary. All previous initialization checks can now be removed.
>>>>
>>>> Passes regress, OK for commit?
>>>
>>> Can't you remove __malloc_initialized altogether? And find some way
>>> to avoid the fork lock in case of interposed malloc?
>>
>> Yes, we can remove the __malloc_initialized global - vfork only uses
>> the callback if multithreaded, at which point you likely used malloc
>> somewhere already.
>
> We still need to make sure that the built-in fork handler works with
> with an uninitialized malloc, in case glibc's malloc has been
> interposed and cannot piggyback on the malloc call from
> pthread_create.
The initialization is done unconditionally startup, so when the vfork callback
is used, malloc will always be initialized even if interposed.
Cheers,
Wilco
More information about the Libc-alpha
mailing list