-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XRay] Add -fxray-{always,never}-instrument= flags to clang
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. Reviewers: rsmith, chandlerc Subscribers: jfb, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D30388 llvm-svn: 299041
- Loading branch information
1 parent
2ccbac3
commit 835832d
Showing
20 changed files
with
367 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===--- XRayLists.h - XRay automatic attribution ---------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// User-provided filters for always/never XRay instrumenting certain functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CLANG_BASIC_XRAYLISTS_H | ||
#define LLVM_CLANG_BASIC_XRAYLISTS_H | ||
|
||
#include "clang/Basic/LLVM.h" | ||
#include "clang/Basic/SourceLocation.h" | ||
#include "clang/Basic/SourceManager.h" | ||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/SpecialCaseList.h" | ||
#include <memory> | ||
|
||
namespace clang { | ||
|
||
class XRayFunctionFilter { | ||
std::unique_ptr<llvm::SpecialCaseList> AlwaysInstrument; | ||
std::unique_ptr<llvm::SpecialCaseList> NeverInstrument; | ||
SourceManager &SM; | ||
|
||
public: | ||
XRayFunctionFilter(ArrayRef<std::string> AlwaysInstrumentPaths, | ||
ArrayRef<std::string> NeverInstrumentPaths, | ||
SourceManager &SM); | ||
|
||
enum class ImbueAttribute { | ||
NONE, | ||
ALWAYS, | ||
NEVER, | ||
}; | ||
|
||
ImbueAttribute shouldImbueFunction(StringRef FunctionName) const; | ||
|
||
ImbueAttribute | ||
shouldImbueFunctionsInFile(StringRef Filename, | ||
StringRef Category = StringRef()) const; | ||
|
||
ImbueAttribute shouldImbueLocation(SourceLocation Loc, | ||
StringRef Category = StringRef()) const; | ||
}; | ||
|
||
} // namespace clang | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===--- XRayArgs.h - Arguments for XRay ------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CLANG_DRIVER_XRAYARGS_H | ||
#define LLVM_CLANG_DRIVER_XRAYARGS_H | ||
|
||
#include "clang/Driver/Types.h" | ||
#include "llvm/Option/Arg.h" | ||
#include "llvm/Option/ArgList.h" | ||
|
||
namespace clang { | ||
namespace driver { | ||
|
||
class ToolChain; | ||
|
||
class XRayArgs { | ||
std::vector<std::string> AlwaysInstrumentFiles; | ||
std::vector<std::string> NeverInstrumentFiles; | ||
std::vector<std::string> ExtraDeps; | ||
bool XRayInstrument = false; | ||
int InstructionThreshold = 200; | ||
|
||
public: | ||
/// Parses the XRay arguments from an argument list. | ||
XRayArgs(const ToolChain &TC, const llvm::opt::ArgList &Args); | ||
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, | ||
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; | ||
}; | ||
|
||
} // namespace driver | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_DRIVER_XRAYARGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ add_clang_library(clangBasic | |
VersionTuple.cpp | ||
VirtualFileSystem.cpp | ||
Warnings.cpp | ||
XRayLists.cpp | ||
${version_inc} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===--- XRayFunctionFilter.cpp - XRay automatic-attribution --------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// User-provided filters for always/never XRay instrumenting certain functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "clang/Basic/XRayLists.h" | ||
|
||
using namespace clang; | ||
|
||
XRayFunctionFilter::XRayFunctionFilter( | ||
ArrayRef<std::string> AlwaysInstrumentPaths, | ||
ArrayRef<std::string> NeverInstrumentPaths, SourceManager &SM) | ||
: AlwaysInstrument( | ||
llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), | ||
NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), | ||
SM(SM) {} | ||
|
||
XRayFunctionFilter::ImbueAttribute | ||
XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const { | ||
// First apply the always instrument list, than if it isn't an "always" see | ||
// whether it's treated as a "never" instrument function. | ||
if (AlwaysInstrument->inSection("fun", FunctionName)) | ||
return ImbueAttribute::ALWAYS; | ||
if (NeverInstrument->inSection("fun", FunctionName)) | ||
return ImbueAttribute::NEVER; | ||
return ImbueAttribute::NONE; | ||
} | ||
|
||
XRayFunctionFilter::ImbueAttribute | ||
XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, | ||
StringRef Category) const { | ||
if (AlwaysInstrument->inSection("src", Filename, Category)) | ||
return ImbueAttribute::ALWAYS; | ||
if (NeverInstrument->inSection("src", Filename, Category)) | ||
return ImbueAttribute::NEVER; | ||
return ImbueAttribute::NONE; | ||
} | ||
|
||
XRayFunctionFilter::ImbueAttribute | ||
XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, | ||
StringRef Category) const { | ||
if (!Loc.isValid()) | ||
return ImbueAttribute::NONE; | ||
return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), | ||
Category); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.