Bug 355188 - valgrind should intercept all malloc related global functions by default
Summary: valgrind should intercept all malloc related global functions by default
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
: 368861 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-11-11 13:59 UTC by Mark Wielaard
Modified: 2016-09-15 19:28 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Intercept all global allocation functions by default (27.64 KB, patch)
2015-11-11 14:11 UTC, Mark Wielaard
Details
testcases for somalloc interception (5.35 KB, patch)
2015-11-12 22:09 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2015-11-11 13:59:25 UTC
Various programs use alternative allocation replacement libraries, either linked into the executable or through ELF symbol interposition in linked shared libraries. The user can use --soname-synonyms=somalloc=libraryname to indicate they want to use an alternative malloc implementation that valgrind should intercept. But this is easy to forget and figuring out the correct replacement pattern is not always immediately obvious. Instead valgrind should mimic ELF symbol interposition and intercept any public global allocation functions. And provide the user an option if they really don't want allocation functions to be intercepted. This is slightly different from making --soname-synonyms=somalloc=* the default, since that would also intercept local private allocation functions (because such private implementations, like in ld.so, are often written to explicitly not be used globally by the program).

Reproducible: Always
Comment 1 Mark Wielaard 2015-11-11 14:11:22 UTC
Created attachment 95440 [details]
Intercept all global allocation functions by default

This implements the interception of all globally public allocation functions by default. It works by adding a flag to the spec to say the interception only applies to global functions. Which is set for the somalloc spec and the librarypath to match is set to "*" unless the user overrides it. Then each DiSym keeps track of whether the symbol is local or global. For a spec which has isGlobal set only isGlobal symbols will match.

Note that because of padding to keep the addresses in DiSym aligned the addition of the extra bool isGlobal doesn't actually grow the struct. The comments explain how the struct could be made more compact on 32bit systems, but this isn't as easy on 64bit systems. So I didn't try to do that in this patch.

For ELF symbols keeping track of which are global is trivial. For pdb I had to guess and made only the "Public" symbols global. I don't know how/if macho keeps track of global symbols or not. For now I just mark all of them local (which just means things work as previously on patforms that use machos, no symbols are matches by default for somalloc unless the user explicitly says which library name to match).
Comment 2 Ivo Raisr 2015-11-11 15:49:08 UTC
Comment on attachment 95440 [details]
Intercept all global allocation functions by default

The patch looks feasible. Could you provide also a test case?
Comment 3 Mark Wielaard 2015-11-12 22:09:49 UTC
Created attachment 95471 [details]
testcases for somalloc interception

Two tests for interception somalloc functions that are interposed in a shared library and in the executable itself.
Comment 4 Philippe Waroquiers 2015-11-14 17:03:12 UTC
Patch looks ok to me.

Some minor comments about the doc part:
+      own versions.  Such replacements are normall done only in shared
normall -> normally

+      delete, etc.) Such allocation functions are interception by
are interception -> are intercepted

+          related functions in an specific alternate library with
an specific -> a specific

+	  none-existing library name).
none-existing -> non-existing
Comment 5 Mark Wielaard 2015-11-15 16:51:49 UTC
Thanks for the reviews. I fixed the documentation issues and added a NEWS entry.
Committed as valgrind svn r15726.
Comment 6 Mark Wielaard 2016-09-15 19:28:16 UTC
*** Bug 368861 has been marked as a duplicate of this bug. ***