Bug 219156

Summary: Valgrind does not handle statically linked malloc or other malloc lib (e.g. tcmalloc)
Product: [Developer tools] valgrind Reporter: Alexander Potapenko <glider>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: wishlist CC: egmkang, philippe.waroquiers, zjp0109
Priority: NOR    
Version: 3.5 SVN   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: A patch that add the necessary interceptors to Coregrind (applies to r10880)
redirects for tcmalloc (gperftools)
clo option to allow replacement for an alternate shared lib or for a statically linked lib

Description Alexander Potapenko 2009-12-18 11:01:37 UTC
Created attachment 39138 [details]
A patch that add the necessary interceptors to Coregrind (applies to r10880)

It would be nice if Valgrind handled custom (i.e. non-libc) allocation/deallocation functions, like those in TCMalloc.

The proposed patch adds the support for custom malloc/free/new/delete methods, allowing Valgrind to find memory problems in the programs that use custom allocation libraries.

The patch also fixes a problem with Bash induced by intercepting custom malloc/free functions. Bash has sh_malloc/sh_free as well as malloc/free, and those are sometimes used inconsistently (e.g. sh_free after malloc). To fix this, we should intercept sh_malloc/sh_free as well.

The third type of interceptors added by the patch is for Python's PyObject_Malloc, PyObject_Free and PyObject_Realloc. Currently Memcheck reports many errors in these functions. To deal with them, the developers usually make suppressions and even build custom Python packages without PyObject_*, whereas the correct solution is to intercept these functions inside Valgrind.
Comment 1 Philippe Waroquiers 2012-03-10 08:05:34 UTC
Created attachment 69443 [details]
redirects for tcmalloc (gperftools)

This patch (derived from patch 1) allows memcheck to intercept malloc/free/...
in the various tcmalloc shared libraries (libtcmalloc.so, libtcmalloc_minimal.so, ...)

Reg Tested on deb6/amd64.
Checked that it finds leaks with libtcmalloc on f12/x86 and deb6/amd64.
Comment 2 Philippe Waroquiers 2012-05-06 20:13:54 UTC
Created attachment 70904 [details]
clo option to allow replacement for an alternate shared lib or for a statically linked lib

E.g. to have memcheck&massif properly working with tcmalloc; give:
   --soname-syns=somalloc=*tcmalloc*

for a statically linked library; use
    -soname-syns=somalloc=NONE
Comment 3 Philippe Waroquiers 2012-05-11 19:37:23 UTC
Fixed in revision 12559.
(main difference compared to previous patch is --soname-syns renamed to --soname-synonyms)
Comment 4 Philippe Waroquiers 2012-07-06 21:11:23 UTC
*** Bug 302800 has been marked as a duplicate of this bug. ***
Comment 5 Philippe Waroquiers 2012-08-09 06:52:50 UTC
*** Bug 304346 has been marked as a duplicate of this bug. ***