review request Bug 17116 - StackTrace::SlowUnwindStack dead locked
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Sep 11 04:13:02 PDT 2013
Now we've got some allocations without stack traces, and it makes LSan sad.
One of those is from after the AsanThread object is destroyed:
#2 0x000000000044593f in __interceptor_malloc () at
../projects/compiler-rt/lib/asan/asan_malloc_linux.cc:74
#3 0x0000000000459fc6 in key_destructor (arg=<optimized out>)
at /code/llvm2/projects/compiler-rt/lib/lsan/lit_tests/TestCases/disabler_in_tsd_destructor.cc:17
#4 0x00007ffff7bc4c83 in __nptl_deallocate_tsd () at pthread_create.c:156
#5 0x00007ffff7bc4ea8 in start_thread (arg=0x7ffff2fff700) at
pthread_create.c:315
#6 0x00007ffff6cd3ccd in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:112
Attached patch makes LSan consider any such allocation reachable.
I'll wait for Sergey to comment on this.
On Wed, Sep 11, 2013 at 5:42 AM, 林作健 <manjian2006 at gmail.com> wrote:
> Please review it.
>
>
> Index: lib/asan/asan_thread.h
> ===================================================================
> --- lib/asan/asan_thread.h (revision 190475)
> +++ lib/asan/asan_thread.h (working copy)
> @@ -86,12 +86,19 @@
> UnmapOrDie(fake_stack_, sizeof(FakeStack));
> }
> FakeStack *fake_stack() { return fake_stack_; }
> + bool isStacktracing() const {
> + return stacktracing;
> + }
> + void setStacktracing(bool b) {
> + stacktracing = b;
> + }
>
> AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_;
> }
> AsanStats &stats() { return stats_; }
>
> private:
> - AsanThread() {}
> + AsanThread()
> + : stacktracing(false) {}
> void SetThreadStackAndTls();
> void ClearShadowForThreadStackAndTLS();
> AsanThreadContext *context_;
> @@ -105,8 +112,23 @@
> FakeStack *fake_stack_;
> AsanThreadLocalMallocStorage malloc_storage_;
> AsanStats stats_;
> + bool stacktracing;
> };
>
> +// ScopedStacktracing is a scope for stacktracing member of a context
> +class ScopedStacktracing {
> + public:
> + ScopedStacktracing (AsanThread * t)
> + : thread(t) {
> + t->setStacktracing(true);
> + }
> + ~ScopedStacktracing() {
> + thread->setStacktracing(false);
> + }
> + private:
> + AsanThread * thread;
> +};
> +
> struct CreateThreadContextArgs {
> AsanThread *thread;
> StackTrace *stack;
> Index: lib/asan/asan_stack.h
> ===================================================================
> --- lib/asan/asan_stack.h (revision 190475)
> +++ lib/asan/asan_stack.h (working copy)
> @@ -36,14 +36,16 @@
> #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
> StackTrace stack; \
> { \
> - uptr stack_top = 0, stack_bottom = 0; \
> AsanThread *t; \
> - if (asan_inited && (t = GetCurrentThread())) { \
> - stack_top = t->stack_top(); \
> - stack_bottom = t->stack_bottom(); \
> + stack.size = 0; \
> + if (asan_inited && (t = GetCurrentThread()) \
> + && !t->isStacktracing()) { \
> + uptr stack_top = t->stack_top(); \
> + uptr stack_bottom = t->stack_bottom(); \
> + ScopedStacktracing sink(t); \
> + GetStackTrace(&stack, max_s, pc, bp, \
> + stack_top, stack_bottom, fast); \
> } \
> - GetStackTrace(&stack, max_s, pc, bp, \
> - stack_top, stack_bottom, fast); \
> }
> #endif // SANITIZER_WINDOWS
>
>
>
>
> 2013/9/10 Evgeniy Stepanov <eugeni.stepanov at gmail.com>
>>
>> On Mon, Sep 9, 2013 at 2:09 PM, 林作健 <manjian2006 at gmail.com> wrote:
>> > Index: lib/asan/asan_thread.h
>> > ===================================================================
>> > --- lib/asan/asan_thread.h (revision 190121)
>> > +++ lib/asan/asan_thread.h (working copy)
>> > @@ -36,10 +36,12 @@
>> > explicit AsanThreadContext(int tid)
>> > : ThreadContextBase(tid),
>> > announced(false),
>> > + stacktracing(false),
>> > thread(0) {
>> > internal_memset(&stack, 0, sizeof(stack));
>> > }
>> > bool announced;
>> > + bool stacktracing;
>>
>> Thread context objects live forever. Please move this to AsanThread.
>>
>> > StackTrace stack;
>> > AsanThread *thread;
>> >
>> > @@ -86,6 +88,12 @@
>> > UnmapOrDie(fake_stack_, sizeof(FakeStack));
>> > }
>> > FakeStack *fake_stack() { return fake_stack_; }
>> > + bool isStacktracing() {
>> > + if (context()) {
>> > + return context()->stacktracing;
>> > + }
>> > + return false;
>> > + }
>> >
>> > AsanThreadLocalMallocStorage &malloc_storage() { return
>> > malloc_storage_;
>> > }
>> > AsanStats &stats() { return stats_; }
>> > @@ -107,6 +115,24 @@
>> > AsanStats stats_;
>> > };
>> >
>> > +// AsanStacktracingSink is a sink for stacktracing member of a context
>> > +class AsanStacktracingSink {
>>
>> Please call it ScopedSomething. M/b ScopedInStackTrace or
>> ScopedStacktracing.
>>
>> > + public:
>> > + AsanStacktracingSink(AsanThread * t)
>> > + : thread(t) {
>> > + if(t->context()) {
>> > + t->context()->stacktracing = true;
>> > + }
>> > + }
>> > + ~AsanStacktracingSink() {
>> > + if(thread->context()) {
>> > + thread->context()->stacktracing = false;
>> > + }
>> > + }
>> > + private:
>> > + AsanThread * thread;
>> > +};
>> > +
>> > struct CreateThreadContextArgs {
>> > AsanThread *thread;
>> > StackTrace *stack;
>> > Index: lib/asan/asan_stack.h
>> > ===================================================================
>> > --- lib/asan/asan_stack.h (revision 190121)
>> > +++ lib/asan/asan_stack.h (working copy)
>> > @@ -36,14 +36,16 @@
>> > #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
>> > StackTrace stack; \
>> > { \
>> > - uptr stack_top = 0, stack_bottom = 0; \
>> > AsanThread *t; \
>> > - if (asan_inited && (t = GetCurrentThread())) { \
>> > - stack_top = t->stack_top(); \
>> > - stack_bottom = t->stack_bottom(); \
>> > + stack.size = 0; \
>> > + if (asan_inited && (t = GetCurrentThread()) \
>> > + && !t->isStacktracing()) { \
>> > + uptr stack_top = t->stack_top(); \
>> > + uptr stack_bottom = t->stack_bottom(); \
>> > + AsanStacktracingSink sink(t); \
>> > + GetStackTrace(&stack, max_s, pc, bp, \
>> > + stack_top, stack_bottom, fast); \
>> > } \
>> > - GetStackTrace(&stack, max_s, pc, bp, \
>> > - stack_top, stack_bottom, fast); \
>> > }
>> > #endif // SANITIZER_WINDOWS
>> >
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> >
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.patch
Type: application/octet-stream
Size: 4279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130911/56814c2b/attachment.obj>
More information about the llvm-commits
mailing list