[PATCH] D52160: [Driver] Support XRay on Fuchsia

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 16 18:00:19 PDT 2018


phosek created this revision.
phosek added reviewers: mcgrathr, dberris.
Herald added a reviewer: javed.absar.
Herald added a subscriber: cfe-commits.

This enables support for XRay in Fuchsia Clang driver.


Repository:
  rC Clang

https://reviews.llvm.org/D52160

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/XRayArgs.cpp
  clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.xray-basic.a
  clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.xray.a
  clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.xray-basic.a
  clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.xray.a
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===================================================================
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -135,6 +135,24 @@
 // CHECK-SCUDO-SHARED: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo.so"
 
+// RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN:     -fxray-instrument -fxray-modes=xray-basic \
+// RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:     -fuse-ld=lld 2>&1 \
+// RUN:     | FileCheck %s -check-prefix=CHECK-XRAY-X86
+// CHECK-XRAY-X86: "-fxray-instrument"
+// CHECK-XRAY-X86: "{{.*[/\\]}}libclang_rt.xray.a"
+// CHECK-XRAY-X86: "{{.*[/\\]}}libclang_rt.xray-basic.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN:     -fxray-instrument -fxray-modes=xray-basic \
+// RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:     -fuse-ld=lld 2>&1 \
+// RUN:     | FileCheck %s -check-prefix=CHECK-XRAY-AARCH64
+// CHECK-XRAY-AARCH64: "-fxray-instrument"
+// CHECK-XRAY-AARCH64: "{{.*[/\\]}}libclang_rt.xray.a"
+// CHECK-XRAY-AARCH64: "{{.*[/\\]}}libclang_rt.xray-basic.a"
+
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN:     -O3 -flto -mcpu=cortex-a53 2>&1 \
 // RUN:     -fuse-ld=lld \
Index: clang/lib/Driver/XRayArgs.cpp
===================================================================
--- clang/lib/Driver/XRayArgs.cpp
+++ clang/lib/Driver/XRayArgs.cpp
@@ -58,6 +58,15 @@
         D.Diag(diag::err_drv_clang_unsupported)
             << (std::string(XRayInstrumentOption) + " on " + Triple.str());
       }
+    } else if (Triple.getOS() == llvm::Triple::Fuchsia) {
+      switch (Triple.getArch()) {
+      case llvm::Triple::x86_64:
+      case llvm::Triple::aarch64:
+        break;
+      default:
+        D.Diag(diag::err_drv_clang_unsupported)
+            << (std::string(XRayInstrumentOption) + " on " + Triple.str());
+      }
     } else {
       D.Diag(diag::err_drv_clang_unsupported)
           << (std::string(XRayInstrumentOption) + " on " + Triple.str());
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -106,8 +106,8 @@
                   D.getLTOMode() == LTOK_Thin);
   }
 
-  addSanitizerRuntimes(ToolChain, Args, CmdArgs);
-
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
   ToolChain.addProfileRTLibs(Args, CmdArgs);
 
@@ -128,6 +128,12 @@
       CmdArgs.push_back("-lm");
     }
 
+    if (NeedsSanitizerDeps)
+      linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
+
+    if (NeedsXRayDeps)
+      linkXRayRuntimeDeps(ToolChain, CmdArgs);
+
     AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
     if (Args.hasArg(options::OPT_pthread) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52160.165706.patch
Type: text/x-patch
Size: 2986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180917/3e6f4e2a/attachment-0001.bin>


More information about the cfe-commits mailing list