This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Track external tags in thread traces
ClosedPublic

Authored by kubamracek on Apr 21 2017, 3:21 PM.

Details

Summary

To make the TSan external API work with Swift and other use cases, we need to track "tags" for individual memory accesses. Since there is no space to store this information in shadow cells, let's use the thread traces for that. This patch stores the tag as an extra frame in the stack traces (by calling FuncEntry and FuncExit with the address of a registered tag), this extra frame is then stripped before printing the backtrace to stderr.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek created this revision.Apr 21 2017, 3:21 PM
dvyukov added inline comments.Apr 25 2017, 5:21 AM
lib/tsan/rtl/tsan_rtl_report.cc
669 ↗(On Diff #96248)

I think it's better to separate stack and tag directly in ObtainCurrentStack and RestoreStack because:

  1. We will not need to copy traces here (which is ugly and confusing at first glance).
  2. No chance that the fake PCs pop up somewhere else because we forgot to remove them.
  3. Racy stacks will be more difficult to break (currently a future change to this function can lead to a situation when we remember a stripped stack but check against non-stripped).
  4. It will be easier to figure out report type without creating ScopedReport first and then fixing up the type with SetType.
672 ↗(On Diff #96248)

I wonder if we need ReportTypeExternalRace at all.
We could always use ReportTypeRace, but attach tag to the report instead of memory accesses. Then we don't need SetType and PrintReport will be able to specialize report header with e.g. "data race on curl handle", because then it will know that the whole report is about an external access.
What do you think?

kubamracek updated this revision to Diff 96627.Apr 25 2017, 1:51 PM

Updating patch.

kubamracek marked an inline comment as done.Apr 25 2017, 1:53 PM
kubamracek added inline comments.
lib/tsan/rtl/tsan_rtl_report.cc
669 ↗(On Diff #96248)

Done.

672 ↗(On Diff #96248)

I'd still like to keep it. There's at least the debugger support that needs to be able to distinguish an "external" race from a regular one.

dvyukov accepted this revision.Apr 29 2017, 12:52 PM

One last thing. Otherwise LGTM.

lib/tsan/rtl/tsan_rtl_report.cc
662 ↗(On Diff #96627)

Calculate typ before creating ScopedReport and remove SetType function. It feels clumsy that we can't figure out report type when we are creating it and add setters to patch it afterwards.

if (tags[0] != kExternalTagNone || tags[1] != kExternalTagNone)
  typ = ReportTypeExternalRace;
ScopedReport rep(typ);

will do.

This revision is now accepted and ready to land.Apr 29 2017, 12:52 PM
This revision was automatically updated to reflect the committed changes.