svn commit: r250991 - in head: contrib/jemalloc/include/jemalloc include lib/libc/stdlib/jemalloc

Bruce Evans brde at optusnet.com.au
Tue Jun 4 08:59:11 UTC 2013


On Fri, 31 May 2013, Jeremie Le Hen wrote:

> On Sat, May 25, 2013 at 06:59:12PM +0000, Marcel Moolenaar wrote:
>> ...
>> Log:
>>   Make the malloc(3) family of functions weak and make their non-weak
>>   implementations visible for use by applications. The functions $F that
>>   are now weak symbols are:
>>   	allocm, calloc, dallocm, free, malloc, malloc_usable_size,
>>   	nallocm, posix_memalign, rallocm, realloc, sallocm
>> ..
> I don't understand what this brings.

It apparently brings (exposes) lots of bugs :-).

> If an application want to override
> malloc() et al., it can just do it and the dynamic linker won't look up
> the libc's version.

This doesn't work for static linkage.  Static linkage is non-broken, and
doesn't allow replacing 1 symbol in an object file without replacing all
of them, except possibly for weak symbols.

Not replacing all of the symbols, by using the dynamic linkage bug or
weak symbols, is very fragile.  A program might replace malloc() and
free() but not bother replacing calloc() because it doesn't use it.
But a library might use it.  The program shouldn't omit repacing
calloc().  calloc() is a well-known public part of malloc() so it is
easy to know that it needs to be replaced.  But it is hard to know all
the implementation details that need replacing.

> Would you mind giving an example of what is now possible with this
> change?

I hope it will make it possible to replace malloc() so that small
statically linked programs take 1K text again like they did in
FreeBSD-3.  In FreeBSD-4, malloc() now adds 360K to this in programs
that don't want to use malloc() or stdio, because (poorly implemented)
constructors reference it, and it references stdio (at least in the
non-production version).  Replacing it is difficult because of the
complex dependencies of symbols.  The first reference to it in a
constructor was in atexit in FreeBSD-4, then malloc() only added 10K
and was easy to replace.

Bruce


More information about the svn-src-all mailing list