From 3d6b342fee947f19830af2267263e710d90c8a01 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Tue, 26 Sep 2017 03:18:11 +0000 Subject: [PATCH] [XRay][Driver] Do not link in XRay runtime in shared libs Summary: This change ensures that we don't link in the XRay runtime when building shared libraries with clang. This doesn't prevent us from building shared libraris tht have XRay instrumentation sleds, but it does prevent us from linking in the static XRay runtime into a shared library. The XRay runtime currently doesn't support dynamic registration of instrumentation sleds in shared objects, which we'll start enabling in the future. That work has to happen in the back-end and in the runtime. Reviewers: rnk, pelikan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38226 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314188 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Gnu.cpp | 5 +++++ test/Driver/XRay/lit.local.cfg | 19 +++++++++++++++++++ test/Driver/XRay/xray-shared-noxray.cpp | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 test/Driver/XRay/xray-shared-noxray.cpp diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index aa8276c1fa..757ebda46d 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -206,6 +206,10 @@ void tools::gcc::Linker::RenderExtraToolArgs(const JobAction &JA, static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { + // Do not add the XRay runtime to shared libraries. + if (Args.hasArg(options::OPT_shared)) + return false; + if (Args.hasFlag(options::OPT_fxray_instrument, options::OPT_fnoxray_instrument, false)) { CmdArgs.push_back("-whole-archive"); @@ -213,6 +217,7 @@ static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args, CmdArgs.push_back("-no-whole-archive"); return true; } + return false; } diff --git a/test/Driver/XRay/lit.local.cfg b/test/Driver/XRay/lit.local.cfg index 34040d2261..56420cfecc 100644 --- a/test/Driver/XRay/lit.local.cfg +++ b/test/Driver/XRay/lit.local.cfg @@ -1,2 +1,21 @@ target_triple_components = config.target_triple.split('-') config.available_features.update(target_triple_components) + +# Only run the tests in platforms where XRay instrumentation is supported. +supported_targets = [ + 'amd64', 'x86_64', 'x86_64h', 'arm', 'aarch64', 'arm64', 'powerpc64le', + 'mips', 'mipsel', 'mips64', 'mips64el' +] + +# Only on platforms we support. +supported_oses = [ + 'linux' +] + +triple_set = set(target_triple_components) +if len(triple_set.intersection(supported_targets)) == 0: + config.unsupported = True + +# Do not run for 'android' despite being linux. +if len(triple_set.intersection(supported_oses)) == 0 or 'android' in triple_set: + config.unsupported = True diff --git a/test/Driver/XRay/xray-shared-noxray.cpp b/test/Driver/XRay/xray-shared-noxray.cpp new file mode 100644 index 0000000000..564df88c4e --- /dev/null +++ b/test/Driver/XRay/xray-shared-noxray.cpp @@ -0,0 +1,16 @@ +// RUN: %clangxx -shared -fPIC -o /dev/null -v -fxray-instrument %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=SHARED +// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \ +// RUN: FileCheck %s --check-prefix=STATIC +// RUN: %clangxx -static -fPIE -o /dev/null -v -fxray-instrument %s 2>&1 \ +// RUN: -DMAIN | FileCheck %s --check-prefix=STATIC +// +// SHARED-NOT: {{clang_rt\.xray-}} +// STATIC: {{clang_rt\.xray-}} +// +// REQUIRES: linux +int foo() { return 42; } + +#ifdef MAIN +int main() { return foo(); } +#endif -- 2.50.0