|
From: Andres T. <and...@ta...> - 2015-03-30 18:10:38
|
I was making a tool for valgrind for measuring things related with threads. I made it work but for that, surprisingly I had to replace mallocs and frees with VG_(needs_malloc_replacement). If I don't do this I get a segmentation fault. In drd if I make that the tool doens't replace the mallocs and frees there is the same segmentation fault. I couldn't find any documentation about this, so I don't know if this is supposed to be like this or is a bug. Regard, Andres. |
|
From: Philippe W. <phi...@sk...> - 2015-03-30 18:26:20
|
On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: > I was making a tool for valgrind for measuring things related with threads. > I made it work but for that, surprisingly I had to replace mallocs and > frees with VG_(needs_malloc_replacement). > If I don't do this I get a segmentation fault. > > In drd if I make that the tool doens't replace the mallocs and frees > there is the same segmentation fault. > > I couldn't find any documentation about this, so I don't know if this > is supposed to be like this or is a bug. No, it is not mandatory to replace (client) malloc/free. There are several tools that do not replace malloc/free. E.g. cachegrind and callgrind are not replacing client malloc/free. Philippe |
|
From: Andres T. <and...@ta...> - 2015-03-31 18:28:48
|
But if you want to replace functions from pthread like helgrind and drd do you have to replace the client malloc/free I don't know why. 2015-03-30 15:26 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: >> I was making a tool for valgrind for measuring things related with threads. >> I made it work but for that, surprisingly I had to replace mallocs and >> frees with VG_(needs_malloc_replacement). >> If I don't do this I get a segmentation fault. >> >> In drd if I make that the tool doens't replace the mallocs and frees >> there is the same segmentation fault. >> >> I couldn't find any documentation about this, so I don't know if this >> is supposed to be like this or is a bug. > No, it is not mandatory to replace (client) malloc/free. > > There are several tools that do not replace malloc/free. > E.g. cachegrind and callgrind are not replacing client malloc/free. > > Philippe > > |
|
From: Philippe W. <phi...@sk...> - 2015-04-01 19:25:31
|
On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote: > But if you want to replace functions from pthread like helgrind and > drd do you have to replace the client malloc/free > I don't know why. To my knowledge, there is no need to replace malloc/free to have helgrind or drd working. A "proof" of that is that if you use an alternate malloc lib (e.g. tcmalloc) or a static malloc library, by default, no replacement will be done. Still these tools do not crash. So, the segv you are seeing is I believe not related to 'non replacement of malloc/free/...'. Replacing malloc might just by chance bypass the real underlying problem. Philippe > > 2015-03-30 15:26 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > > On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: > >> I was making a tool for valgrind for measuring things related with threads. > >> I made it work but for that, surprisingly I had to replace mallocs and > >> frees with VG_(needs_malloc_replacement). > >> If I don't do this I get a segmentation fault. > >> > >> In drd if I make that the tool doens't replace the mallocs and frees > >> there is the same segmentation fault. > >> > >> I couldn't find any documentation about this, so I don't know if this > >> is supposed to be like this or is a bug. > > No, it is not mandatory to replace (client) malloc/free. > > > > There are several tools that do not replace malloc/free. > > E.g. cachegrind and callgrind are not replacing client malloc/free. > > > > Philippe > > > > |
|
From: Andres T. <and...@ta...> - 2015-04-01 19:37:12
|
Actually they replace malloc(at least in valgrind 3.10.1). For example in the source of drd look at drd_malloc_wrappers.c 2015-04-01 16:25 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote: >> But if you want to replace functions from pthread like helgrind and >> drd do you have to replace the client malloc/free >> I don't know why. > To my knowledge, there is no need to replace malloc/free to have > helgrind or drd working. > > A "proof" of that is that if you use an alternate malloc lib (e.g. > tcmalloc) or a static malloc library, > by default, no replacement will be done. Still these tools do > not crash. > > So, the segv you are seeing is I believe not related to > 'non replacement of malloc/free/...'. > Replacing malloc might just by chance bypass the real underlying > problem. > > Philippe > > >> >> 2015-03-30 15:26 GMT-03:00 Philippe Waroquiers <phi...@sk...>: >> > On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: >> >> I was making a tool for valgrind for measuring things related with threads. >> >> I made it work but for that, surprisingly I had to replace mallocs and >> >> frees with VG_(needs_malloc_replacement). >> >> If I don't do this I get a segmentation fault. >> >> >> >> In drd if I make that the tool doens't replace the mallocs and frees >> >> there is the same segmentation fault. >> >> >> >> I couldn't find any documentation about this, so I don't know if this >> >> is supposed to be like this or is a bug. >> > No, it is not mandatory to replace (client) malloc/free. >> > >> > There are several tools that do not replace malloc/free. >> > E.g. cachegrind and callgrind are not replacing client malloc/free. >> > >> > Philippe >> > >> > > > |
|
From: Philippe W. <phi...@sk...> - 2015-04-01 20:10:43
|
On Wed, 2015-04-01 at 16:37 -0300, Andres Tiraboschi wrote: > Actually they replace malloc(at least in valgrind 3.10.1). For example > in the source of drd look at drd_malloc_wrappers.c No. They do something so that *potentially* malloc/free/... are replaced. But by default, the replacement will *not* happen for a static malloc or for a tcmalloc or any other alternate malloc library. So, that makes me believe there is no need to have malloc replaced to have this tools working (with reduced functionality of course, because they will not observe any malloc activity). So, I still believe the segv you are seeing is not related to 'non replacement of malloc/free/...' but that you have another problem. Philippe > > 2015-04-01 16:25 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > > On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote: > >> But if you want to replace functions from pthread like helgrind and > >> drd do you have to replace the client malloc/free > >> I don't know why. > > To my knowledge, there is no need to replace malloc/free to have > > helgrind or drd working. > > > > A "proof" of that is that if you use an alternate malloc lib (e.g. > > tcmalloc) or a static malloc library, > > by default, no replacement will be done. Still these tools do > > not crash. > > > > So, the segv you are seeing is I believe not related to > > 'non replacement of malloc/free/...'. > > Replacing malloc might just by chance bypass the real underlying > > problem. > > > > Philippe > > > > > >> > >> 2015-03-30 15:26 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > >> > On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: > >> >> I was making a tool for valgrind for measuring things related with threads. > >> >> I made it work but for that, surprisingly I had to replace mallocs and > >> >> frees with VG_(needs_malloc_replacement). > >> >> If I don't do this I get a segmentation fault. > >> >> > >> >> In drd if I make that the tool doens't replace the mallocs and frees > >> >> there is the same segmentation fault. > >> >> > >> >> I couldn't find any documentation about this, so I don't know if this > >> >> is supposed to be like this or is a bug. > >> > No, it is not mandatory to replace (client) malloc/free. > >> > > >> > There are several tools that do not replace malloc/free. > >> > E.g. cachegrind and callgrind are not replacing client malloc/free. > >> > > >> > Philippe > >> > > >> > > > > > |
|
From: Andres T. <and...@ta...> - 2015-04-01 20:23:33
|
But in drd_malloc_wrappers.c for example if you comment "VG_(needs_malloc_replacement)(drd_malloc, ..." in DRD_(register_malloc_wrappers) when pthread_create is called you'll have the following segmentation fault. --6540-- VG_USERREQ__CLIENT_CALL2: func=0x0 ==6540== ==6540== Process terminating with default action of signal 11 (SIGSEGV) . . . Segmentation fault (core dumped) This the same segmentation fault I was having and I solved replacing malloc/free. I have no idea why this. 2015-04-01 17:11 GMT-03:00 Philippe Waroquiers <phi...@sk...>: > On Wed, 2015-04-01 at 16:37 -0300, Andres Tiraboschi wrote: >> Actually they replace malloc(at least in valgrind 3.10.1). For example >> in the source of drd look at drd_malloc_wrappers.c > No. > They do something so that *potentially* malloc/free/... are replaced. > But by default, the replacement will *not* happen for a static malloc > or for a tcmalloc or any other alternate malloc library. > > So, that makes me believe there is no need to have malloc replaced > to have this tools working (with reduced functionality of course, > because they will not observe any malloc activity). > > So, I still believe the segv you are seeing is not related to > 'non replacement of malloc/free/...' but that you have another > problem. > > Philippe > >> >> 2015-04-01 16:25 GMT-03:00 Philippe Waroquiers <phi...@sk...>: >> > On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote: >> >> But if you want to replace functions from pthread like helgrind and >> >> drd do you have to replace the client malloc/free >> >> I don't know why. >> > To my knowledge, there is no need to replace malloc/free to have >> > helgrind or drd working. >> > >> > A "proof" of that is that if you use an alternate malloc lib (e.g. >> > tcmalloc) or a static malloc library, >> > by default, no replacement will be done. Still these tools do >> > not crash. >> > >> > So, the segv you are seeing is I believe not related to >> > 'non replacement of malloc/free/...'. >> > Replacing malloc might just by chance bypass the real underlying >> > problem. >> > >> > Philippe >> > >> > >> >> >> >> 2015-03-30 15:26 GMT-03:00 Philippe Waroquiers <phi...@sk...>: >> >> > On Mon, 2015-03-30 at 15:10 -0300, Andres Tiraboschi wrote: >> >> >> I was making a tool for valgrind for measuring things related with threads. >> >> >> I made it work but for that, surprisingly I had to replace mallocs and >> >> >> frees with VG_(needs_malloc_replacement). >> >> >> If I don't do this I get a segmentation fault. >> >> >> >> >> >> In drd if I make that the tool doens't replace the mallocs and frees >> >> >> there is the same segmentation fault. >> >> >> >> >> >> I couldn't find any documentation about this, so I don't know if this >> >> >> is supposed to be like this or is a bug. >> >> > No, it is not mandatory to replace (client) malloc/free. >> >> > >> >> > There are several tools that do not replace malloc/free. >> >> > E.g. cachegrind and callgrind are not replacing client malloc/free. >> >> > >> >> > Philippe >> >> > >> >> > >> > >> > > > |
|
From: Philippe W. <phi...@sk...> - 2015-04-01 20:43:20
|
On Wed, 2015-04-01 at 17:23 -0300, Andres Tiraboschi wrote: > But in drd_malloc_wrappers.c for example if you comment > "VG_(needs_malloc_replacement)(drd_malloc, ..." in > DRD_(register_malloc_wrappers) when pthread_create is called you'll > have the following segmentation fault. > > --6540-- VG_USERREQ__CLIENT_CALL2: func=0x0 > ==6540== > ==6540== Process terminating with default action of signal 11 (SIGSEGV) > . > . > . > Segmentation fault (core dumped) Yes. This is because you are now removing a *part* of the functionality needed to replace malloc. Then malloc replacement still happens, and then it segv, because the call to VG_(needs_malloc_replacement) is the one that provides some info needed when malloc replacement happens. Malloc replacement is activated by another mechanism (LD_PRELOAD of an .so with specially crafted function names that the Valgrind debug info reader recognises). Replacement/wrapping of functions in Valgrind is non trivial. What you do above just makes it crash, as you have then a partially implemented replacement. Philippe |
|
From: Julian S. <js...@ac...> - 2015-04-01 22:41:51
|
On 01/04/15 21:25, Philippe Waroquiers wrote: > On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote: >> But if you want to replace functions from pthread like helgrind and >> drd do you have to replace the client malloc/free >> I don't know why. > To my knowledge, there is no need to replace malloc/free to have > helgrind or drd working. Well, I think it is important, because both tools need to know when memory is freed and later re-allocated. Without that, they would report false races on memory that has been freed and then reallocated to a different thread. In effect the freeing marks the memory as un-tracked and causes them to "forget" what they know about it. Also, it helps generate better error messages. With malloc/free intercepting, we can generate address descriptions like "address X is N bytes inside a block of size M allocated at ..". J |
|
From: Philippe W. <phi...@sk...> - 2015-04-01 22:57:12
|
On Thu, 2015-04-02 at 00:41 +0200, Julian Seward wrote:
> On 01/04/15 21:25, Philippe Waroquiers wrote:
> > On Tue, 2015-03-31 at 15:28 -0300, Andres Tiraboschi wrote:
> >> But if you want to replace functions from pthread like helgrind and
> >> drd do you have to replace the client malloc/free
> >> I don't know why.
> > To my knowledge, there is no need to replace malloc/free to have
> > helgrind or drd working.
>
> Well, I think it is important, because both tools need to know when
> memory is freed and later re-allocated. Without that, they would report
> false races on memory that has been freed and then reallocated to a
> different thread. In effect the freeing marks the memory as un-tracked
> and causes them to "forget" what they know about it.
>
> Also, it helps generate better error messages. With malloc/free
> intercepting, we can generate address descriptions like "address X
> is N bytes inside a block of size M allocated at ..".
Yes for sure, for these tools to properly detect errors,
malloc replacement is highly recommended.
But the question discussed initially is: is it *mandatory*
to replace malloc/free/... if you want to wrap pthread functions
and not have a segmentation violation ?
I answered no, and "proved that" by telling that helgrind does
not crash when e.g. using it with tcmalloc and not using
--soname-synonyms=...
In such a case, malloc/tcmalloc is *not* replaced, but still
helgrind (or drd) will not crash.
So, in summary, the discussion status is:
1. it is not mandatory to replace malloc if you want to wrap
a pthread function
2. the segmentation violation encountered by Andres in
his small trial to wrap pthread is IMO not caused
by not replacing malloc. It is just that replacing malloc
bypasses the segv I believe.
Philippe
|