Should malloc-related functions be weak?

Florian Weimer fweimer@redhat.com
Mon Aug 1 11:08:00 GMT 2016


On 08/01/2016 01:04 PM, Pedro Alves wrote:
> On 08/01/2016 11:39 AM, Florian Weimer wrote:
>> On 08/01/2016 12:25 PM, Pedro Alves wrote:
>
>>> Are these other symbols meant be overridden?
>>
>> These symbols (__malloc_fork_lock_parent etc.) are not supposed to be
>> overridden, they are entirely internal to glibc and its malloc
>> implementation.  If the glibc malloc is interposed, these functions
>> should not do anything.
>
> Hmm, doesn't an interposing malloc need to worry about the same
> scenarios these hooks were invented for?

Yes and no.  For multi-threaded programs, preserving heap consistency 
across fork is optional.  glibc malloc provides a working malloc after 
fork as an extension over POSIX.

> Say I copy glibc malloc to my project, and tweak it somehow for my
> workloads.  How can I make my copy work just as correctly as the
> builtin one?

You can't.  You will have to change the algorithm, use the existing fork 
handlers framework, or drop the POSIX extension.

Florian



More information about the Libc-alpha mailing list