Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 2013 18:58:58 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Jeremie Le Hen <jlh@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, Marcel Moolenaar <marcel@FreeBSD.org>, src-committers@FreeBSD.org
Subject:   Re: svn commit: r250991 - in head: contrib/jemalloc/include/jemalloc include lib/libc/stdlib/jemalloc
Message-ID:  <20130604181934.R1018@besplex.bde.org>
In-Reply-To: <20130531064239.GF70224@caravan.chchile.org>
References:  <201305251859.r4PIxChc053341@svn.freebsd.org> <20130531064239.GF70224@caravan.chchile.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130604181934.R1018>