Bug 219156 - Valgrind does not handle statically linked malloc or other malloc lib (e.g. tcmalloc)
Summary: Valgrind does not handle statically linked malloc or other malloc lib (e.g. t...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.5 SVN
Platform: Unlisted Binaries Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
: 302800 304346 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-18 11:01 UTC by Alexander Potapenko
Modified: 2012-08-09 06:52 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
A patch that add the necessary interceptors to Coregrind (applies to r10880) (9.80 KB, patch)
2009-12-18 11:01 UTC, Alexander Potapenko
Details
redirects for tcmalloc (gperftools) (12.70 KB, text/plain)
2012-03-10 08:05 UTC, Philippe Waroquiers
Details
clo option to allow replacement for an alternate shared lib or for a statically linked lib (21.50 KB, text/plain)
2012-05-06 20:13 UTC, Philippe Waroquiers
Details

Note You need to log in before you can comment on or make changes to this bug.
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. ***