|
From: Konstantin S. <kon...@gm...> - 2009-05-20 11:58:56
|
On Wed, May 20, 2009 at 12:07 PM, Tom Hughes <to...@co...> wrote: > Konstantin Serebryany wrote: > >> Memcheck, Helgrind and other valgrind tools use LD_PRELOAD to replace >> or wrap functions in the users code. > > It does use LD_PRELOAD but not in the normal way where the preloaded library > contains functions with the same name as the ones being replaced. > > Instead the preloaded library contains functions with special mangled names > which valgrind recognises and adds to it's internal redirection table so > that when it sees the relevant function it can redirect it. > >> This makes it impossible to use the tools on statically linked binaries. >> Meanwhile, PIN is capable of replacing/wrapping functions in static >> binaries, so it is at least theoretically possible to do the same in >> Valgrind. > > Indeed, and so long as the static binary has a symbol table it would already > work I think except that: > > (a) a statically linked binary won't use ld.so so won't process > the LD_PRELOAD at all. > > (b) the symbols in our preload libraries are deliberately designed > to only intercept symbols in the 'right' so's - so malloc will > only be intercepted in libc.so and so on. > > I think globally intercepting something like malloc (which would be needed > for a statically linked binary) could only ever be done on an > optional basis really but I guess we could support. > > I'm not sure how to get round the LD_PRELOAD issue though? > > At the end of the day the question may be one of how much work it is worth > doing to support something that is fairly uncommon these days. Static binaries are not that uncommon, at least in out environment. Quite often I get questions "what does this weird Memcheck/ThreadSanitizer report mean?" and the answer is "you are using it on a static binary". Can valgrind driver issue a warning and exit if requested to run on a static binary (only for those tools that use LD_PRELOAD)? This will at least avoid confusion... ? --kcc > > Tom > > -- > Tom Hughes (to...@co...) > http://www.compton.nu/ > |