This is an archive of the discontinued LLVM Phabricator instance.

[XRay] Add -fxray-{always,never}-instrument= flags to clang
ClosedPublic

Authored by dberris on Feb 26 2017, 7:21 PM.

Details

Summary

The -fxray-always-instrument= and -fxray-never-instrument= flags take
filenames that are used to imbue the XRay instrumentation attributes
using a whitelist mechanism (similar to the sanitizer special cases
list). We use the same syntax and semantics as the sanitizer blacklists
files in the implementation.

As implemented, we respect the attributes that are already defined in
the source file (i.e. those that have the
[[clang::xray_{always,never}_instrument]] attributes) before applying
the always/never instrument lists.

Diff Detail

Repository
rL LLVM

Event Timeline

dberris created this revision.Feb 26 2017, 7:21 PM
dberris planned changes to this revision.Feb 26 2017, 7:24 PM

Need to undo some unnecessary formatting changes..

dberris updated this revision to Diff 89830.Feb 26 2017, 7:34 PM
  • fixup: undo clang-format on ASTContext.h
  • fixup: undo clang-formatting whole file
  • fixup: undo clang-format on file
rnk edited edge metadata.Mar 22 2017, 10:52 AM

I think you need some driver logic to make sure the xray lists show up in .d files so that modifications to them trigger rebuilds in most build systems. See the SanitizerArgs.cpp driver logic for this.

include/clang/Basic/XRayFunctionFilter.h
1 ↗(On Diff #89830)

Do you think XRayLists.h might be a better name for this header? It's analagous to SanitizerBlacklist.h, but it's not a "black" list.

rnk added inline comments.Mar 22 2017, 10:56 AM
lib/Basic/XRayFunctionFilter.cpp
21 ↗(On Diff #89830)

Hm, phab ate my comment about this. I don't think we should use this API in clang. Instead, we should use the ::create(...) version and issue a diagnostic similar to err_drv_malformed_sanitizer_blacklist from the caller of this function.

dberris updated this revision to Diff 92766.Mar 23 2017, 12:21 AM
dberris marked 2 inline comments as done.
  • fixup: address reviewer comments
In D30388#707719, @rnk wrote:

I think you need some driver logic to make sure the xray lists show up in .d files so that modifications to them trigger rebuilds in most build systems. See the SanitizerArgs.cpp driver logic for this.

Good catch -- yes, added.

Also took the opportunity to refactor the flag logic out into its own class (similar to how we do it with the sanitizers).

include/clang/Basic/XRayFunctionFilter.h
1 ↗(On Diff #89830)

Good idea -- although the names of the type defined doesn't have any resemblance to the lists. I suppose that's fine too.

lib/Basic/XRayFunctionFilter.cpp
21 ↗(On Diff #89830)

That's fair -- although I am just looking at what SanitizerLists already does. I've added the validation of the flags though at the driver level to ensure that we don't initialise this in a manner that's not valid.

rnk accepted this revision.Mar 29 2017, 5:09 PM

lgtm

include/clang/Driver/XRayArgs.h
22 ↗(On Diff #92766)

Any reason to omit the 't' in "InstrumentFiles"?

This revision is now accepted and ready to land.Mar 29 2017, 5:09 PM
This revision was automatically updated to reflect the committed changes.
dberris marked an inline comment as done.
dberris added inline comments.Mar 29 2017, 5:43 PM
include/clang/Driver/XRayArgs.h
22 ↗(On Diff #92766)

Wow, good catch -- no good reason, except for lack of a good spellcheck!

Hi, this breaks the android build due to use of std::to_string. llvm::to_string should be used instead. I would fix it myself, but don't have commit access. Thanks in advance!