[PATCH] D45126: Xray, OpenBSD support

David CARLIER via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 31 10:44:48 PDT 2018


devnexen created this revision.
devnexen added a reviewer: brad.
Herald added subscribers: cfe-commits, krytarowski, dberris.

Enabling Xray in OpenBSD


Repository:
  rC Clang

https://reviews.llvm.org/D45126

Files:
  lib/Driver/ToolChains/OpenBSD.cpp
  lib/Driver/XRayArgs.cpp


Index: lib/Driver/XRayArgs.cpp
===================================================================
--- lib/Driver/XRayArgs.cpp
+++ lib/Driver/XRayArgs.cpp
@@ -49,7 +49,8 @@
         D.Diag(diag::err_drv_clang_unsupported)
             << (std::string(XRayInstrumentOption) + " on " + Triple.str());
       }
-    } else if (Triple.getOS() == llvm::Triple::FreeBSD) {
+    } else if (Triple.getOS() == llvm::Triple::FreeBSD ||
+              Triple.getOS() == llvm::Triple::OpenBSD) {
         if (Triple.getArch() != llvm::Triple::x86_64) {
           D.Diag(diag::err_drv_clang_unsupported)
               << (std::string(XRayInstrumentOption) + " on " + Triple.str());
Index: lib/Driver/ToolChains/OpenBSD.cpp
===================================================================
--- lib/Driver/ToolChains/OpenBSD.cpp
+++ lib/Driver/ToolChains/OpenBSD.cpp
@@ -22,6 +22,29 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+                           ArgStringList &CmdArgs) {
+  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");
+    CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false));
+    CmdArgs.push_back("-no-whole-archive");
+    return true;
+  }
+
+  return false;
+}
+
+static void linkXRayRuntimeDeps(const ToolChain &TC, const ArgList &Args,
+                                ArgStringList &CmdArgs) {
+  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back("-lm");
+  CmdArgs.push_back("-lpthread");
+}
+
 void openbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
                                       const InputInfo &Output,
                                       const InputInfoList &Inputs,
@@ -180,6 +203,7 @@
                             options::OPT_Z_Flag, options::OPT_r});
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -195,6 +219,10 @@
       CmdArgs.push_back(ToolChain.getCompilerRTArgString(Args, "builtins", false));
       linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
     }
+    if (NeedsXRayDeps) {
+      CmdArgs.push_back(ToolChain.getCompilerRTArgString(Args, "builtins", false));
+      linkXRayRuntimeDeps(ToolChain, Args, CmdArgs);
+    }
     // FIXME: For some reason GCC passes -lgcc before adding
     // the default system libraries. Just mimic this for now.
     CmdArgs.push_back("-lgcc");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45126.140550.patch
Type: text/x-patch
Size: 2754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180331/0fa90b7a/attachment.bin>


More information about the cfe-commits mailing list