diff options
-rw-r--r-- | clang/include/clang/Basic/LangOptions.h | 7 | ||||
-rw-r--r-- | clang/include/clang/Basic/XRayLists.h | 3 | ||||
-rw-r--r-- | clang/include/clang/Driver/Options.td | 8 | ||||
-rw-r--r-- | clang/include/clang/Driver/XRayArgs.h | 1 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Basic/XRayLists.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Driver/XRayArgs.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 1 | ||||
-rw-r--r-- | clang/test/CodeGen/xray-always-instrument.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGen/xray-attr-list.cpp | 19 | ||||
-rw-r--r-- | clang/test/CodeGen/xray-imbue-arg1.cpp | 9 | ||||
-rw-r--r-- | clang/test/CodeGen/xray-never-instrument.cpp | 24 | ||||
-rw-r--r-- | llvm/docs/XRay.rst | 21 | ||||
-rw-r--r-- | llvm/docs/XRayExample.rst | 14 |
14 files changed, 139 insertions, 20 deletions
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 905f60ad552..debf80d1bbf 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -148,13 +148,20 @@ public: /// \brief Paths to the XRay "always instrument" files specifying which /// objects (files, functions, variables) should be imbued with the XRay /// "always instrument" attribute. + /// WARNING: This is a deprecated field and will go away in the future. std::vector<std::string> XRayAlwaysInstrumentFiles; /// \brief Paths to the XRay "never instrument" files specifying which /// objects (files, functions, variables) should be imbued with the XRay /// "never instrument" attribute. + /// WARNING: This is a deprecated field and will go away in the future. std::vector<std::string> XRayNeverInstrumentFiles; + /// \brief Paths to the XRay attribute list files, specifying which objects + /// (files, functions, variables) should be imbued with the appropriate XRay + /// attribute(s). + std::vector<std::string> XRayAttrListFiles; + clang::ObjCRuntime ObjCRuntime; std::string ObjCConstantStringClass; diff --git a/clang/include/clang/Basic/XRayLists.h b/clang/include/clang/Basic/XRayLists.h index 8cfea70e280..244b1d533b7 100644 --- a/clang/include/clang/Basic/XRayLists.h +++ b/clang/include/clang/Basic/XRayLists.h @@ -26,12 +26,13 @@ namespace clang { class XRayFunctionFilter { std::unique_ptr<llvm::SpecialCaseList> AlwaysInstrument; std::unique_ptr<llvm::SpecialCaseList> NeverInstrument; + std::unique_ptr<llvm::SpecialCaseList> AttrList; SourceManager &SM; public: XRayFunctionFilter(ArrayRef<std::string> AlwaysInstrumentPaths, ArrayRef<std::string> NeverInstrumentPaths, - SourceManager &SM); + ArrayRef<std::string> AttrListPaths, SourceManager &SM); enum class ImbueAttribute { NONE, diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9367634d8af..58b5341b348 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1095,11 +1095,15 @@ def fxray_instruction_threshold_ : def fxray_always_instrument : JoinedOrSeparate<["-"], "fxray-always-instrument=">, Group<f_Group>, Flags<[CC1Option]>, - HelpText<"Filename defining the whitelist for imbuing the 'always instrument' XRay attribute.">; + HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'always instrument' XRay attribute.">; def fxray_never_instrument : JoinedOrSeparate<["-"], "fxray-never-instrument=">, Group<f_Group>, Flags<[CC1Option]>, - HelpText<"Filename defining the whitelist for imbuing the 'never instrument' XRay attribute.">; + HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'never instrument' XRay attribute.">; +def fxray_attr_list : + JoinedOrSeparate<["-"], "fxray-attr-list=">, + Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Filename defining the list of functions/types for imbuing XRay attributes.">; def fxray_always_emit_customevents : Flag<["-"], "fxray-always-emit-customevents">, Group<f_Group>, Flags<[CC1Option]>, diff --git a/clang/include/clang/Driver/XRayArgs.h b/clang/include/clang/Driver/XRayArgs.h index 8eedd1dba1d..535c030e8c5 100644 --- a/clang/include/clang/Driver/XRayArgs.h +++ b/clang/include/clang/Driver/XRayArgs.h @@ -21,6 +21,7 @@ class ToolChain; class XRayArgs { std::vector<std::string> AlwaysInstrumentFiles; std::vector<std::string> NeverInstrumentFiles; + std::vector<std::string> AttrListFiles; std::vector<std::string> ExtraDeps; bool XRayInstrument = false; int InstructionThreshold = 200; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 79ac53cde23..4b095ce45ab 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -788,7 +788,8 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts), SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)), XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles, - LangOpts.XRayNeverInstrumentFiles, SM)), + LangOpts.XRayNeverInstrumentFiles, + LangOpts.XRayAttrListFiles, SM)), PrintingPolicy(LOpts), Idents(idents), Selectors(sels), BuiltinInfo(builtins), DeclarationNames(*this), Comments(SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts), LastSDM(nullptr, 0) { diff --git a/clang/lib/Basic/XRayLists.cpp b/clang/lib/Basic/XRayLists.cpp index 462777d5340..ad331899d2e 100644 --- a/clang/lib/Basic/XRayLists.cpp +++ b/clang/lib/Basic/XRayLists.cpp @@ -16,24 +16,32 @@ using namespace clang; XRayFunctionFilter::XRayFunctionFilter( ArrayRef<std::string> AlwaysInstrumentPaths, - ArrayRef<std::string> NeverInstrumentPaths, SourceManager &SM) + ArrayRef<std::string> NeverInstrumentPaths, + ArrayRef<std::string> AttrListPaths, SourceManager &SM) : AlwaysInstrument( llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), - SM(SM) {} + AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), 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. + // TODO: Remove these as they're deprecated; use the AttrList exclusively. if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName, - "arg1")) + "arg1") || + AttrList->inSection("always", "fun", FunctionName, "arg1")) return ImbueAttribute::ALWAYS_ARG1; if (AlwaysInstrument->inSection("xray_always_instrument", "fun", - FunctionName)) + FunctionName) || + AttrList->inSection("always", "fun", FunctionName)) return ImbueAttribute::ALWAYS; - if (NeverInstrument->inSection("xray_never_instrument", "fun", FunctionName)) + + if (NeverInstrument->inSection("xray_never_instrument", "fun", + FunctionName) || + AttrList->inSection("never", "fun", FunctionName)) return ImbueAttribute::NEVER; + return ImbueAttribute::NONE; } @@ -41,10 +49,12 @@ XRayFunctionFilter::ImbueAttribute XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, StringRef Category) const { if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, - Category)) + Category) || + AttrList->inSection("always", "src", Filename, Category)) return ImbueAttribute::ALWAYS; if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, - Category)) + Category) || + AttrList->inSection("never", "src", Filename, Category)) return ImbueAttribute::NEVER; return ImbueAttribute::NONE; } diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp index e151cb907cd..cc109d10cf3 100644 --- a/clang/lib/Driver/XRayArgs.cpp +++ b/clang/lib/Driver/XRayArgs.cpp @@ -99,6 +99,15 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { } else D.Diag(clang::diag::err_drv_no_such_file) << Filename; } + + for (const auto &Filename : + Args.getAllArgValues(options::OPT_fxray_attr_list)) { + if (llvm::sys::fs::exists(Filename)) { + AttrListFiles.push_back(Filename); + ExtraDeps.push_back(Filename); + } else + D.Diag(clang::diag::err_drv_no_such_file) << Filename; + } } } @@ -127,6 +136,12 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args, CmdArgs.push_back(Args.MakeArgString(NeverInstrumentOpt)); } + for (const auto&AttrFile : AttrListFiles) { + SmallString<64> AttrListFileOpt("-fxray-attr-list="); + AttrListFileOpt += AttrFile; + CmdArgs.push_back(Args.MakeArgString(AttrListFileOpt)); + } + for (const auto &Dep : ExtraDeps) { SmallString<64> ExtraDepOpt("-fdepfile-entry="); ExtraDepOpt += Dep; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 1a3b67f0968..687dc688e1d 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2640,6 +2640,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Args.getAllArgValues(OPT_fxray_always_instrument); Opts.XRayNeverInstrumentFiles = Args.getAllArgValues(OPT_fxray_never_instrument); + Opts.XRayAttrListFiles = Args.getAllArgValues(OPT_fxray_attr_list); // -fallow-editor-placeholders Opts.AllowEditorPlaceholders = Args.hasArg(OPT_fallow_editor_placeholders); diff --git a/clang/test/CodeGen/xray-always-instrument.cpp b/clang/test/CodeGen/xray-always-instrument.cpp index 60d85956995..fb6690577f5 100644 --- a/clang/test/CodeGen/xray-always-instrument.cpp +++ b/clang/test/CodeGen/xray-always-instrument.cpp @@ -1,6 +1,14 @@ // RUN: echo "fun:*foo*" > %t.always-instrument // RUN: echo "src:*xray-always-instrument.cpp" >> %t.always-instrument -// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s +// RUN: echo "[always]" > %t.xray-attrlist +// RUN: echo "fun:*foo*" >> %t.xray-attrlist +// RUN: echo "src:*xray-always-instrument.cpp" >> %t.xray-attrlist +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-attr-list=%t.xray-attrlist -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s void foo() {} diff --git a/clang/test/CodeGen/xray-attr-list.cpp b/clang/test/CodeGen/xray-attr-list.cpp new file mode 100644 index 00000000000..f2e48773e41 --- /dev/null +++ b/clang/test/CodeGen/xray-attr-list.cpp @@ -0,0 +1,19 @@ +// RUN: echo "[always]" > %t.xray-attrlist +// RUN: echo "fun:*always*" >> %t.xray-attrlist +// RUN: echo "[never]" >> %t.xray-attrlist +// RUN: echo "fun:*never*" >> %t.xray-attrlist +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-attr-list=%t.xray-attrlist -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s + +void always() {} +void never() {} +[[clang::xray_never_instrument]] void alwaysNever() {} +[[clang::xray_always_instrument]] void neverAlways() {} + +// CHECK: define void @_Z6alwaysv() #[[ALWAYSATTR:[0-9]+]] { +// CHECK: define void @_Z5neverv() #[[NEVERATTR:[0-9]+]] { +// CHECK: define void @_Z11alwaysNeverv() #[[NEVERATTR]] { +// CHECK: define void @_Z11neverAlwaysv() #[[ALWAYSATTR]] { +// CHECK: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}} +// CHECK: attributes #[[NEVERATTR]] = {{.*}} "function-instrument"="xray-never" {{.*}} diff --git a/clang/test/CodeGen/xray-imbue-arg1.cpp b/clang/test/CodeGen/xray-imbue-arg1.cpp index eb272b97eaf..083099ce582 100644 --- a/clang/test/CodeGen/xray-imbue-arg1.cpp +++ b/clang/test/CodeGen/xray-imbue-arg1.cpp @@ -1,5 +1,12 @@ // RUN: echo "fun:*arg1*=arg1" >> %t.always-instrument -// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s +// RUN: echo "[always]" > %t.xray-attrlist +// RUN: echo "fun:*arg1*=arg1" >> %t.xray-attrlist +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-attr-list=%t.xray-attrlist -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s void foo() {} diff --git a/clang/test/CodeGen/xray-never-instrument.cpp b/clang/test/CodeGen/xray-never-instrument.cpp new file mode 100644 index 00000000000..4b20edc6ad6 --- /dev/null +++ b/clang/test/CodeGen/xray-never-instrument.cpp @@ -0,0 +1,24 @@ +// RUN: echo "fun:*foo*" > %t.never-instrument +// RUN: echo "src:*xray-never-instrument.cpp" >> %t.never-instrument +// RUN: echo "[never]" > %t.xray-attrlist +// RUN: echo "fun:*foo*" >> %t.xray-attrlist +// RUN: echo "src:*xray-never-instrument.cpp" >> %t.xray-attrlist +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-never-instrument=%t.never-instrument -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 \ +// RUN: -fxray-attr-list=%t.xray-attrlist -emit-llvm -o - %s \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck %s + +void foo() {} + +[[clang::xray_always_instrument]] void bar() {} + +void baz() {} + +// CHECK: define void @_Z3foov() #[[NEVERATTR:[0-9]+]] { +// CHECK: define void @_Z3barv() #[[ALWAYSATTR:[0-9]+]] { +// CHECK: define void @_Z3bazv() #[[NEVERATTR:[0-9]+]] { +// CHECK: attributes #[[NEVERATTR]] = {{.*}} "function-instrument"="xray-never" {{.*}} +// CHECK: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}} + diff --git a/llvm/docs/XRay.rst b/llvm/docs/XRay.rst index 314d7787e91..01b595d302e 100644 --- a/llvm/docs/XRay.rst +++ b/llvm/docs/XRay.rst @@ -117,6 +117,27 @@ it gets instrumented. ; ... } +Special Case File +----------------- + +Attributes can be imbued through the use of special case files instead of +adding them to the original source files. You can use this to mark certain +functions and classes to be never, always, or instrumented with first-argument +logging from a file. The file's format is described below: + +.. code-block:: bash + + # Comments are supported + [always] + fun:always_instrument + fun:log_arg1=arg1 # Log the first argument for the function + + [never] + fun:never_instrument + +These files can be provided through the ``-fxray-attr-list=`` flag to clang. +You may have multiple files loaded through multiple instances of the flag. + XRay Runtime Library -------------------- diff --git a/llvm/docs/XRayExample.rst b/llvm/docs/XRayExample.rst index f8e7d943fed..eefb8cc8a43 100644 --- a/llvm/docs/XRayExample.rst +++ b/llvm/docs/XRayExample.rst @@ -178,22 +178,22 @@ add the attribute to the source. To use this feature, you can define one file for the functions to always instrument, and another for functions to never instrument. The format of these files are exactly the same as the SanitizerLists files that control similar -things for the sanitizer implementations. For example, we can have two -different files like below: +things for the sanitizer implementations. For example: :: - # always-instrument.txt + # xray-attr-list.txt # always instrument functions that match the following filters: + [always] fun:main - # never-instrument.txt # never instrument functions that match the following filters: + [never] fun:__cxx_* -Given the above two files we can re-build by providing those two files as -arguments to clang as ``-fxray-always-instrument=always-instrument.txt`` or -``-fxray-never-instrument=never-instrument.txt``. +Given the file above we can re-build by providing it to the +``-fxray-attr-list=`` flag to clang. You can have multiple files, each defining +different sets of attribute sets, to be combined into a single list by clang. The XRay stack tool ------------------- |