This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation
AcceptedPublic

Authored by yln on Mar 1 2019, 6:08 PM.

Details

Summary

Cleanup ASan's __sanitizer::BufferedStackTrace::UnwindImpl (formerly
GetStackTrace) implementation. Start with ASan because it is the most
complex implementation.

GetStackTrace implementations seem to have started out as exact copies
of the original implementation in ASan, but have diverged in subtle
ways. My goal is to parameterize this algorithm (via templating or
callbacks) so we can share the implementation and get rid of the
inversed dependency (sanitizer_common depends on concrete
implementations in asan, ubsan, etc.). This should also help us to avoid
those pesky linker errors caused by undefined, duplicate, and weak
symbols on Windows.

Event Timeline

yln created this revision.Mar 1 2019, 6:08 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 1 2019, 6:08 PM
Herald added subscribers: llvm-commits, Restricted Project, jdoerfert, kubamracek. · View Herald Transcript
vitalybuka requested changes to this revision.Mar 1 2019, 6:53 PM

ways. My goal is to parameterize this algorithm (via templating or callbacks) so we can share the implementation and get rid of the inversed dependency (sanitizer_common depends on

concrete implementations in asan, ubsan, etc.). This should also help us to avoid those pesky linker errors caused by undefined, duplicate, and weak symbols on Windows.

I like what you have already done, but I don't think we are looking to remove inverse deps. Historically it's how compiler-rt was made, and fixing just unwinder will not make a difference.
Spreading this to other parts seems is a lot of work.

compiler-rt/lib/asan/asan_stack.cc
77

Originally the patch was reverted when IsValidFrame was added like this
https://reviews.llvm.org/D18690?vs=on&id=52346&whitespace=ignore-most#toc

Also given that you've commented out top/bottom checks r354718 I don't want to enabled IsValidFrame everywhere.
Could you please keep it for MIPS, and return to this later, if you still want this, after resolving r354718

81

misaligned

This revision now requires changes to proceed.Mar 1 2019, 6:53 PM
yln updated this revision to Diff 189068.Mar 2 2019, 10:51 PM

Put back special case for MIPS.

yln marked 2 inline comments as done.Mar 2 2019, 10:52 PM
vitalybuka added inline comments.Mar 3 2019, 8:38 PM
compiler-rt/lib/asan/asan_stack.cc
73

UNREACHABLE makes it not NFC

What about:

  if (t && !t->isUnwinding() && WillUseFastUnwind(request_fast)) {
    ScopedUnwinding unwind_scope(t);
    uptr top = t->stack_top();
    uptr bottom = t->stack_bottom();
    if (!SANITIZER_MIPS || IsValidFrame(bp, top, bottom)) {
      UnwindFast(pc, bp, top, bottom, max_depth);
      return;
    } 
  }

#if SANITIZER_CAN_SLOW_UNWIND
    UnwindSlowWithOptionalContext(pc, context, max_depth);
#endif
yln marked 2 inline comments as done.Mar 4 2019, 10:12 AM
yln added inline comments.
compiler-rt/lib/asan/asan_stack.cc
73

You are right, the patch is not strictly NFC:

  1. Scope was moved
  2. t->isUnwinding() also skips when slow unwinding

I think these are issues with the current implementation.
I will remove those changes to make this patch strictly NFC and provide separate patches with explanations.

Note that, UNREACHABLE is required for NFC. We are effectively inlining the old Unwind overload which has this code.

yln marked an inline comment as done.Mar 4 2019, 10:23 AM
yln updated this revision to Diff 189164.Mar 4 2019, 10:27 AM

Adopting Vitaly's suggestion

vitalybuka accepted this revision.Mar 4 2019, 2:40 PM
This revision is now accepted and ready to land.Mar 4 2019, 2:40 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka reopened this revision.Mar 4 2019, 6:36 PM

Reverted with r355369

This revision is now accepted and ready to land.Mar 4 2019, 6:36 PM
vitalybuka accepted this revision.Mar 4 2019, 10:00 PM
vitalybuka added inline comments.
lib/sanitizer_common/sanitizer_stacktrace.h
138 ↗(On Diff #189230)

Please use clang-format --style=file