This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Refactor stacktrace and symbolizing functions from TSan into sanitizer_common
AbandonedPublic

Authored by kubamracek on Nov 14 2014, 12:43 PM.

Details

Reviewers
dvyukov
samsonov
Summary

This is a refactor patch that moves a couple of stacktrace taking and/or symbolizer-related functions from TSan, makes them generic and moves them into sanitizer_common. This is to prepare the functions for an upcoming patch implementing issue suppression mechanism into ASan. NFC intented.

There is a couple of subtle changes, that I'd like to make sure we're fine with:

  • The #ifdef TSAN_GO changes into #ifdef SANITIZER_GO in the appropriate places.
  • The internal_alloc(MBlockReportStack, sizeof(ReportStack)); becomes InternalAlloc(sizeof(ReportStack));, not sure if the MBlockReportStack is used for anything important.
  • stack->pc to stack->info.address, how could this event work before???
  • bool strip_main argument to SymbolizeStack whether it should try to strip the main function from the stack trace

Diff Detail

Event Timeline

kubamracek retitled this revision from to [compiler-rt] Refactor stacktrace and symbolizing functions from TSan into sanitizer_common.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added subscribers: Unknown Object (MLST), kcc, samsonov and 2 others.

Sorry for the delay, I've seen the patch (and the following one, about
supressions), but wasn't able to review it yet.

Probably, I should have started with your patch for suppression support in ASan to see what you actually need there :) Anyway, it's too late now.
I think that this patch is way too gross and should be significantly modified before it can go in.

  1. __tsan::SymbolizeStack() used to call __tsan::SymbolizeCode(), which does its kExternalPCBit magic. But now this function is unused, as __sanitizer::SymbolizeStack() will never call it.
  2. stack->pc didn't break because DPrintf() arguments are compiled out of regular build. There's a comment which tells why this should be a DPrintf(), not a Printf(). Note that we don't have DPrint() in sanitizer_common. Thanks for pointing at it, I'll fix this right away.
  3. StackStripMain is completely TSan-specific, it has hardcoded Linux function names and even names from TSan runtime.
  4. ReportStack::suppressable is TSan-specific, and in retrospect looks like a weird idea - ReportStack represents a single frame stack trace, while "suppressable" is the flag that should be attached to the whole stack trace.

ReportStack probably makes sense for TSan, as it used to be a class in its report generation machinery, but if we want to make it generally usable, we should use smth. like SymbolizedStackFrame.

If we want to run a useful refactoring, I *think* we can try something like this: remove the proliferation of AddressInfo class and gradually replace it with SymbolizedStackFrame. In particular, we can make Symbolizer::SymbolizePC() just return a pointer to a newly-allocated SymbolizedStackFrame object, and save the users from the effort of allocating/deallocating arrays of AddressInfo structures. We will be able to generalize the code between __tsan::SymbolizeCode() and StackTrace::Print() (see sanitizer_stacktrace_libcdep.cc).

Also, it's not a coincidence that we used to have a symbolization inside the function that prints the stacktrace, and it's more or less a design choice of ASan: when we print an error report, a program can be in a terrible state, so we're interested in printing the data as soon as we obtain it. We don't want to spend time and resources trying to symbolize 100-frame stack trace, and then print it all. Instead, we want to have a symbolize-print loop to produce at least some information if the program is killed while we're doing it.

dvyukov edited edge metadata.Nov 20 2014, 8:33 PM

s/TSAN_GO/SANITIZER_GO/ is perfectly OK. These macros are just a way to detect that we are building Go runtime. There is no difference between using one or another.

kubamracek abandoned this revision.Dec 2 2014, 10:17 AM