[PATCH] Allow to use different prefixes for jemalloc-specific functions and libc functions
jasone at canonware.com
Mon Mar 12 11:44:41 PDT 2012
On Mar 12, 2012, at 2:49 AM, Mike Hommey wrote:
> On Thu, Mar 01, 2012 at 05:49:33PM -0800, Jason Evans wrote:
>> On Mar 1, 2012, at 6:44 AM, Mike Hommey wrote:
>>> On Wed, Feb 29, 2012 at 04:15:37PM -0800, Jason Evans wrote:
>>>> On Feb 23, 2012, at 3:23 AM, Mike Hommey wrote:
>>>>> From: Mike Hommey <mh at glandium.org>
>>>>> In some cases, it can be interesting to use different prefixes for
>>>>> the "standard" libc malloc functions and for jemalloc specific
>>>>> functions. One such case is to use the "__wrap_" prefix on libc
>>>>> malloc functions (for use with ld's --wrap option) and no prefix or
>>>>> "je_" for jemalloc functions.
>>>>> In such cases, it can also me interesting not to exclude memalign
>>>>> and valloc, so this change also adds an option not to omit them when
>>>>> the prefix is set.
>>>> Do you have a practical use case that makes this a compelling feature?
>>>> I'm reluctant to hard-code the set of JEMALLOC_LIBC() functions to
>>>> make distinct from JEMALLOC_P() functions, because it may vary by
>>>> operating system.
>>> The exact one that is in the patch message: on android, we use ld's
>>> --wrap option to wrap the "standard" libc functions. It is cumbersome
>>> to have to use --wrap for jemalloc-specific functions as well.
>>> Arguably, we could probably use symbol aliases when linking the library
>>> containing jemalloc.
>> I went a slightly different direction with this and added --with-mangling:
>> Please let me know if this fails to meet your needs for some reason.
> The fact that --with-jemalloc-prefix overrides anything set with
> --with-mangling makes it unconvenient for our usecase, where we want to
> prefix with je_ except a few functions we want to either not prefix (on
> desktop) or wrap (on android). Sure, we can use --with-mangling to set
> the je_ prefix, but that won't cover new APIs when they appear.
The name mangling that is specified via --with-mangling overrides --with-jemalloc-prefix, so I thought this would do what you want.
./autogen.sh --enable-cc-silence --enable-prof --enable-debug --with-mangling=malloc:__wrap_malloc,calloc:__wrap_calloc,realloc:__wrap_realloc,free:__wrap_free --with-jemalloc-prefix=je_
nm -a lib/libjemalloc.so.1 |grep ' [TBD] '
0000000000006dfc T __wrap_calloc
000000000000797d T __wrap_free
00000000000065d4 T __wrap_malloc
00000000000071e3 T __wrap_realloc
000000000002f398 T _fini
0000000000002ed0 T _init
0000000000007dc4 T je_allocm
0000000000008a73 T je_dallocm
0000000000007c0a T je_mallctl
0000000000007c9b T je_mallctlbymib
0000000000007c5c T je_mallctlnametomib
0000000000249e20 B je_malloc_conf
0000000000239a48 D je_malloc_message
0000000000007be3 T je_malloc_stats_print
0000000000007b16 T je_malloc_usable_size
0000000000007ab1 T je_memalign
0000000000008be2 T je_nallocm
0000000000006dd0 T je_posix_memalign
0000000000008293 T je_rallocm
0000000000008958 T je_sallocm
0000000000007ae5 T je_valloc
Do you get different behavior on your system?
More information about the jemalloc-discuss