[PATCH] D38226: [XRay][Driver] Do not link in XRay runtime in shared libs

Dean Michael Berris via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 05:04:57 PDT 2017

dberris created this revision.

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.



Index: test/Driver/XRay/xray-shared-noxray.cpp
--- /dev/null
+++ test/Driver/XRay/xray-shared-noxray.cpp
@@ -0,0 +1,14 @@
+// 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-}}
+int foo() { return 42; }
+#ifdef MAIN
+int main() { return foo(); }
Index: lib/Driver/ToolChains/Gnu.cpp
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -206,13 +206,18 @@
 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(TC.getCompilerRTArgString(Args, "xray", false));
     return true;
   return false;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38226.116494.patch
Type: text/x-patch
Size: 1485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170925/109eb238/attachment-0001.bin>

More information about the cfe-commits mailing list