Page MenuHomePhabricator

Introduce stats and stats_client libraries.
ClosedPublic

Authored by pcc on Jan 13 2016, 8:13 PM.

Details

Summary

This is part of a new statistics gathering feature for the sanitizers.
See clang/docs/SanitizerStats.rst for further info and docs.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 44831.Jan 13 2016, 8:13 PM
pcc retitled this revision from to Introduce stats and stats_client libraries..
pcc updated this object.
pcc added reviewers: kcc, eugenis.
pcc added a subscriber: llvm-commits.
pcc added a reviewer: krasin.Jan 14 2016, 10:45 AM
krasin1 added inline comments.
lib/sanitizer_common/sanitizer_flags.cc
51 ↗(On Diff #44831)

Are we restricted to use C++ strings here? The function is super scary right now.

98 ↗(On Diff #44831)

I don't think that the flag value is limited by kMaxPathLength. Can you please choose a better limit? Or somehow check that the value fits the buffer?

lib/stats/stats.cc
39 ↗(On Diff #44831)

s/unsigned/size_t/ maybe?

46 ↗(On Diff #44831)

Probably, it makes sense to check that start != NULL to fail cleanly if WriteModuleReport is called on an unregistered module.

eugenis added inline comments.Jan 14 2016, 11:51 AM
lib/stats/stats.cc
49 ↗(On Diff #44831)

This lazy file opening just complicates things. Maybe move to a separate function and call it from WriteFullReport ?

lib/stats/stats_client.cc
12 ↗(On Diff #44831)

Please mention that it is intended to be linked into each individual module, and that it can not use the sanitizer_common infrastructure.

94 ↗(On Diff #44831)

Why dlsym and not just declare an external function and call it directly?

test/cfi/stats.cpp
1 ↗(On Diff #44831)

Does this work with the cross-dso mode?

pcc updated this revision to Diff 44937.Jan 14 2016, 3:32 PM
  • Switch to an alternative in-memory representation that avoids the need for linker magic
pcc updated this revision to Diff 44942.Jan 14 2016, 4:21 PM
pcc marked 2 inline comments as done.
  • Address review comments
lib/stats/stats.cc
40 ↗(On Diff #44937)

It doesn't matter, this will never be more than 8.

47 ↗(On Diff #44937)

Added a CHECK.

lib/stats/stats_client.cc
80 ↗(On Diff #44937)

This won't work on Windows where DSOs can't directly call into the main executable.

test/cfi/stats.cpp
2 ↗(On Diff #44937)

Almost; this initially gave duplicate symbol errors. To avoid a combinatorial explosion in the number of static sanitizer libraries I decided to start improving how we link them. First step: link stats without -whole-archive, and use -u to pull in the stats runtime. Also added an integration test here.

pcc updated this revision to Diff 44943.Jan 14 2016, 4:26 PM
  • Add CHECK to SubstituteForFlagValue
lib/sanitizer_common/sanitizer_flags.cc
51 ↗(On Diff #44942)

I don't think we can use std::string here.

98 ↗(On Diff #44942)

kMaxPathLength is 4096, which is probably enough (we use it in a bunch of other places elsewhere). I don't think this code matters enough to worry about using a variable-size buffer.

I've added a CHECK to the above function.

krasin1 added inline comments.Jan 14 2016, 4:38 PM
lib/sanitizer_common/sanitizer_flags.cc
51 ↗(On Diff #44943)

why? not that I insist, I just probably don't understand the constraints and interested to learn about that.

pcc added inline comments.Jan 14 2016, 4:46 PM
lib/sanitizer_common/sanitizer_flags.cc
51 ↗(On Diff #44943)

If the C++ standard library is compiled with sanitizer instrumentation, we would have a circular dependency between sanitizer_common and the stdlib.

krasin accepted this revision.Jan 14 2016, 4:48 PM
krasin edited edge metadata.
krasin added inline comments.
lib/sanitizer_common/sanitizer_flags.cc
51 ↗(On Diff #44943)

You're right. Thank you for the reminder.

This revision is now accepted and ready to land.Jan 14 2016, 4:48 PM
eugenis added inline comments.Jan 15 2016, 11:02 AM
lib/stats/stats.cc
87 ↗(On Diff #44943)

There could be a data race if this is called from concurrent dlopen-ed module constructors.

pcc updated this revision to Diff 45020.Jan 15 2016, 12:17 PM
pcc edited edge metadata.
  • Add mutex to fix data race
eugenis accepted this revision.Jan 15 2016, 1:56 PM
eugenis edited edge metadata.

LGTM

This revision was automatically updated to reflect the committed changes.