dberris created this revision.
dberris added reviewers: dblaikie, echristo.

This is related to http://llvm.org/PR32274.

When building with XRay, always depend on a C++ standard library.

We're doing this to automate the linking of the C++ ABI functionality
that the modes use by default. In particular, we depend on some
function-local static initialisation.

The alternative change here is to re-write the modes to only use
libc/pthreads functionality. We're choosing to do this instead as it's
minimally invasive. In the future we can revisit this when we have a
better idea as to why not depending on the C++ ABI functionality is a
better solution.


https://reviews.llvm.org/D46998

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/test/xray/TestCases/Posix/c-test.cc


Index: compiler-rt/test/xray/TestCases/Posix/c-test.cc
===================================================================
--- /dev/null
+++ compiler-rt/test/xray/TestCases/Posix/c-test.cc
@@ -0,0 +1,4 @@
+// RUN: %clang_xray -g -o %t %s
+// REQUIRES: x86_64-target-arch
+// REQUIRES: built-in-llvm-tree
+int main() {}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -713,7 +713,8 @@
   return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
 }
 
-bool tools::addXRayRuntime(const ToolChain&TC, const ArgList &Args, 
ArgStringList &CmdArgs) {
+bool tools::addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+                           ArgStringList &CmdArgs) {
   if (Args.hasArg(options::OPT_shared))
     return false;
 
@@ -723,6 +724,11 @@
     for (const auto &Mode : TC.getXRayArgs().modeList())
       CmdArgs.push_back(TC.getCompilerRTArgString(Args, Mode, false));
     CmdArgs.push_back("-no-whole-archive");
+
+    // If we're linking a non-C++ application, we'd need to link in the C++
+    // runtime.
+    if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
+      TC.AddCXXStdlibLibArgs(Args, CmdArgs);
     return true;
   }
 


Index: compiler-rt/test/xray/TestCases/Posix/c-test.cc
===================================================================
--- /dev/null
+++ compiler-rt/test/xray/TestCases/Posix/c-test.cc
@@ -0,0 +1,4 @@
+// RUN: %clang_xray -g -o %t %s
+// REQUIRES: x86_64-target-arch
+// REQUIRES: built-in-llvm-tree
+int main() {}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -713,7 +713,8 @@
   return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
 }
 
-bool tools::addXRayRuntime(const ToolChain&TC, const ArgList &Args, ArgStringList &CmdArgs) {
+bool tools::addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+                           ArgStringList &CmdArgs) {
   if (Args.hasArg(options::OPT_shared))
     return false;
 
@@ -723,6 +724,11 @@
     for (const auto &Mode : TC.getXRayArgs().modeList())
       CmdArgs.push_back(TC.getCompilerRTArgString(Args, Mode, false));
     CmdArgs.push_back("-no-whole-archive");
+
+    // If we're linking a non-C++ application, we'd need to link in the C++
+    // runtime.
+    if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
+      TC.AddCXXStdlibLibArgs(Args, CmdArgs);
     return true;
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to