This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: some question about malloc_hook


On Wed, Aug 3, 2016 at 4:56 PM, yoma sophian <sophian.yoma@gmail.com> wrote:
> hi all:
> When I check below manual, it shows we can use  __malloc_hook and
> __realloc_hook debug programsthat use dynamic memory allocation.
> http://www.gnu.org/software/libc/manual/pdf/libc.pdf
>
> But when I copy the sample code and try to compile for running.
> it say
> malloc_hook.c:12:1: warning: ‘__malloc_hook’ is deprecated (declared
> at /media/sdb2/toolchain/arm/gcc-linaro-arm-linux-gnueabihf-4.9-2014.08_linux/arm-linux-gnueabihf/libc/usr/include/malloc.h:153)
> [-Wdeprecated-declarations]
>
> if __malloc_hook and __realloc_hook are really deprecated,
> is there similar methods we can use to hook malloc, realloc instead?
>
> appreciate your kind help in advance,

There are several ways to wrap or hook up malloc family of functions.

1) Obviously it is a linker warning and you can choose to ignore it ;).
2) RTFM LD's -wrap option. You can wrap real malloc and call the
original malloc.
3) If you want to completely overwrite glibc version of malloc, please
note that malloc is defined as weak symbol in glibc.
4) If your application is dynamic executable using so's, You can use
dlsym(RTLD_NEXT, "malloc") and use the original glibc malloc as
__libc_malloc()
5) If it is a PIC executable, you can alter the GOT entry for malloc
routine to jump to your hook.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]