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() {}