This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Overriding malloc
- From: Will Newton <will dot newton at linaro dot org>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 1 Jul 2014 09:56:44 +0100
- Subject: Re: Overriding malloc
- Authentication-results: sourceware.org; auth=none
- References: <53B27135 dot 4040308 at redhat dot com>
On 1 July 2014 09:28, Florian Weimer <fweimer@redhat.com> wrote:
> We need to support overriding malloc through LD_PRELOAD and other forms of
> symbol interposition. Once you override malloc, you also have to override
> free, realloc and calloc at least.
>
> If the application (or one of its libraries) uses posix_memalign etc., these
> have to be overridden as well. Same for the malloc_usable_size.
>
> The question is if overriding those should is required even if the
> application does not call those fringe malloc-related functions, i.e. if
> glibc should behave as if it never calls them if malloc has been overridden.
>
> If yes, we should likely remove the remaining call to malloc_usable_size
> from the code base.
Are you referring to the assert in nis/nss_nis/nis-netgrp.c?
Those asserts look rather dubious to me anyway, is there some reason
why we should expect yp_match to be broken in that way?
IMO malloc_usable_size should not be called from within glibc because
it is almost always a sign of bad code. A good subset of the allocator
functions to require to be overridden would be the union of C90, C11
and POSIX:
ISO C90
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
ISO C11
void *aligned_alloc(size_t alignment, size_t size);
POSIX
int posix_memalign(void **memptr, size_t alignment, size_t size);
--
Will Newton
Toolchain Working Group, Linaro