Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Issue 3120017: Keep shadow stacks to help heap checker unwind without frame pointers (Closed)

Created:
10 years, 4 months ago by Alexander Potapenko
Modified:
9 years, 6 months ago
CC:
chromium-reviews, brettw-cc_chromium.org
Visibility:
Public.

Description

This CL introduces the stack shadowing mechanism that should help TCMalloc's heap leak checker to unwind the memory allocation stacks better. Currently, if a memory region is allocated from a library built without frame pointers heapchecker is unable to unwind the stack and records only the top frame. This is inconvenient, because: -- several leaks from different places are treated as leaks from the same source -- it's hard to suppress such leaks, because a one-line suppression is uninformative linux_shadow_stacks.cc keeps the threads' IP and SP values in thread-local stacks upon each function entry/exit using gcc function instrumentation (-finstrument-functions). The GetStackTrace routine from stacktrace_shadow-inl.h unwinds the stack as usual (using frame pointers), but then updates the result with the shadow stack frames which SP values are below the bottom frame of the unwind result. Note that -finstrument-functions affects only Chromium code, not the libraries. This means that we cannot get more than one library function frame at the top of the stack. For example, consider a libfoo library that has a public foo_do_something() routine which allocates memory via foo_alloc(). If Chromium calls foo_do_something() from ChromeCallFoo(), then the following call chain effectively happens: main -> ChromeCallFoo -> foo_do_something -> foo_alloc If libfoo is built with -fomit-frame-pointers, heapcheck can unwind only the last stack frame: foo_alloc On the other hand, the shadow stack at the allocation site contains everything below the libfoo calls: main -> ChromeCallFoo As a result the following allocation stack is recorded: main -> ChromeCallFoo -> foo_alloc This is enough to distinguish between e.g. ChromeCallFoo1 and ChromeCallFoo2 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=57658

Patch Set 1 #

Total comments: 1

Patch Set 2 : '' #

Total comments: 10

Patch Set 3 : '' #

Patch Set 4 : '' #

Patch Set 5 : '' #

Total comments: 1

Patch Set 6 : '' #

Patch Set 7 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+212 lines, -0 lines) Patch
M base/allocator/allocator.gyp View 1 2 3 4 5 6 1 chunk +11 lines, -0 lines 0 comments Download
M build/common.gypi View 1 2 3 4 5 6 2 chunks +8 lines, -0 lines 0 comments Download
A third_party/tcmalloc/chromium/src/linux_shadow_stacks.h View 5 1 chunk +20 lines, -0 lines 0 comments Download
A third_party/tcmalloc/chromium/src/linux_shadow_stacks.cc View 1 2 3 4 5 6 1 chunk +128 lines, -0 lines 0 comments Download
M third_party/tcmalloc/chromium/src/stacktrace_x86-inl.h View 2 3 4 5 6 4 chunks +45 lines, -0 lines 0 comments Download

Messages

Total messages: 17 (0 generated)
Alexander Potapenko
Folks, could you please take a look? This code is to be used for heapcheck ...
10 years, 4 months ago (2010-08-19 14:33:29 UTC) #1
Alexander Potapenko
Please refer to http://code.google.com/p/chromium/issues/detail?id=51988 for the problem discussion and the stacktrace samples.
10 years, 4 months ago (2010-08-19 14:35:18 UTC) #2
willchan no longer on Chromium
Why aren't we just using libunwind for this? On Thu, Aug 19, 2010 at 7:33 ...
10 years, 4 months ago (2010-08-19 14:35:37 UTC) #3
Alexander Potapenko
Unfortunately libunwind cannot be used together with perftools. As far as I know, it relies ...
10 years, 4 months ago (2010-08-19 14:48:27 UTC) #4
willchan no longer on Chromium
Ah yes, that's right. I forgot that, thanks for reminding me! Is this a change ...
10 years, 4 months ago (2010-08-19 14:57:29 UTC) #5
Alexander Potapenko
On 2010/08/19 14:57:29, willchan wrote: > Ah yes, that's right. I forgot that, thanks for ...
10 years, 4 months ago (2010-08-19 15:00:28 UTC) #6
willchan no longer on Chromium
Which file did you branch stacktrace_shadow-inl.h from? I want to run a diff so I ...
10 years, 4 months ago (2010-08-19 15:34:25 UTC) #7
Alexander Potapenko
It's stacktrace_x86-inl.h In fact I can just change it under #ifdef without forking if necessary ...
10 years, 4 months ago (2010-08-19 15:40:29 UTC) #8
willchan no longer on Chromium
There doesn't seem to be a resolution on this approach on the google-perftools thread. Do ...
10 years, 4 months ago (2010-08-22 16:30:46 UTC) #9
Alexander Potapenko
> > http://codereview.chromium.org/3120017/diff/1/3 > File build/common.gypi (right): > > http://codereview.chromium.org/3120017/diff/1/3#newcode840 > build/common.gypi:840: '-finstrument-functions', > Why ...
10 years, 4 months ago (2010-08-23 13:35:00 UTC) #10
Alexander Potapenko
On 2010/08/22 16:30:46, willchan wrote: > There doesn't seem to be a resolution on this ...
10 years, 4 months ago (2010-08-23 13:40:24 UTC) #11
willchan no longer on Chromium
Functionally the code looks good to me. I only have stylistic nits. http://codereview.chromium.org/3120017/diff/14001/15004 File third_party/tcmalloc/chromium/src/stacktrace_x86-inl.h ...
10 years, 4 months ago (2010-08-24 15:20:36 UTC) #12
Alexander Potapenko
http://codereview.chromium.org/3120017/diff/14001/15004 File third_party/tcmalloc/chromium/src/stacktrace_x86-inl.h (right): http://codereview.chromium.org/3120017/diff/14001/15004#newcode328 third_party/tcmalloc/chromium/src/stacktrace_x86-inl.h:328: int shadow_index = stack_size-1; On 2010/08/24 15:20:36, willchan wrote: ...
10 years, 4 months ago (2010-08-25 10:01:18 UTC) #13
Alexander Potapenko
PTAL (Patch Set 4) Fixed some nits in linux_shadow_stacks.cc (Patch Set 5) Added linux_shadow_stacks.h (sorry ...
10 years, 4 months ago (2010-08-25 10:17:22 UTC) #14
willchan no longer on Chromium
LGTM http://codereview.chromium.org/3120017/diff/22002/25004 File third_party/tcmalloc/chromium/src/linux_shadow_stacks.h (right): http://codereview.chromium.org/3120017/diff/22002/25004#newcode8 third_party/tcmalloc/chromium/src/linux_shadow_stacks.h:8: #define NO_INSTRUMENT __attribute__((no_instrument_function)) You should #undef this afterward.
10 years, 4 months ago (2010-08-25 16:16:31 UTC) #15
Alexander Potapenko
> http://codereview.chromium.org/3120017/diff/22002/25004#newcode8 > third_party/tcmalloc/chromium/src/linux_shadow_stacks.h:8: #define NO_INSTRUMENT > __attribute__((no_instrument_function)) > You should #undef this afterward. Fixed. ...
10 years, 4 months ago (2010-08-26 10:44:55 UTC) #16
willchan no longer on Chromium
10 years, 4 months ago (2010-08-26 14:35:00 UTC) #17
On Thu, Aug 26, 2010 at 6:44 AM, <glider@chromium.org> wrote:

> http://codereview.chromium.org/3120017/diff/22002/25004#newcode8
>> third_party/tcmalloc/chromium/src/linux_shadow_stacks.h:8: #define
>>
> NO_INSTRUMENT
>
>> __attribute__((no_instrument_function))
>> You should #undef this afterward.
>>
>
> Fixed.
>
> Yet again: is it ok to put non-3rd party code into third_party/?
>

I view this as totally fine.  We've added extra files for TCMalloc plenty of
times.


> And is it ok to reuse a piece of code from perftools in that non-3rd party
> code?
> (I assume this won't violate any policies. Anyway, we're going to upstream
> that
> change)


Yeah, I think this is fine too.  You should copy the file comment block into
the place where you use it, since it says that redistributions and use in
source must include the comment block.


>
>
> http://codereview.chromium.org/3120017/show
>

Powered by Google App Engine
This is Rietveld 408576698