From: Dean Michael Berris Date: Fri, 10 Nov 2017 05:50:13 +0000 (+0000) Subject: [XRay][darwin] Initial XRay in Darwin Support X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d2e3c60e65e302d47594038d19135211ce182e1;p=clang [XRay][darwin] Initial XRay in Darwin Support Summary: This change implements the changes required in both clang and compiler-rt to allow building XRay-instrumented binaries in Darwin. For now we limit this to x86_64. We also start building the XRay runtime library in compiler-rt for osx. A caveat to this is that we don't have the tests set up and running yet, which we'll do in a set of follow-on changes. This patch uses the monorepo layout for the coordinated change across multiple projects. Reviewers: kubamracek Subscribers: mgorny, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D39114 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317875 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/XRayArgs.h b/include/clang/Driver/XRayArgs.h index 83210d100a..01ad6b047f 100644 --- a/include/clang/Driver/XRayArgs.h +++ b/include/clang/Driver/XRayArgs.h @@ -30,6 +30,7 @@ public: 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; + bool needsXRayRt() const { return XRayInstrument; } }; } // namespace driver diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 39c4525f84..e689d4fa44 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -18,6 +18,7 @@ #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" +#include "clang/Driver/XRayArgs.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/Path.h" @@ -1098,6 +1099,11 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, if (Sanitize.needsEsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, "esan"); + const XRayArgs& XRay = getXRayArgs(); + if (XRay.needsXRayRt() && isTargetMacOS()) { + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.xray_osx.a", RLO_AlwaysLink); + } + // Otherwise link libSystem, then the dynamic runtime library, and finally any // target specific static runtime library. CmdArgs.push_back("-lSystem"); diff --git a/lib/Driver/XRayArgs.cpp b/lib/Driver/XRayArgs.cpp index 8d68a8432d..f0dfb66812 100644 --- a/lib/Driver/XRayArgs.cpp +++ b/lib/Driver/XRayArgs.cpp @@ -51,6 +51,15 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { D.Diag(diag::err_drv_clang_unsupported) << (std::string(XRayInstrumentOption) + " on " + Triple.str()); } + else if (Triple.getOS() == llvm::Triple::Darwin) + // Experimental support for macos. + switch (Triple.getArch()) { + case llvm::Triple::x86_64: + break; + default: + D.Diag(diag::err_drv_clang_unsupported) + << (std::string(XRayInstrumentOption) + " on " + Triple.str()); + } else D.Diag(diag::err_drv_clang_unsupported) << (std::string(XRayInstrumentOption) + " on non-Linux target OS");