Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[Driver] Support XRay on Fuchsia
Browse files Browse the repository at this point in the history
This enables support for XRay in Fuchsia Clang driver.

Differential Revision: https://reviews.llvm.org/D52160

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347444 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
petrhosek committed Nov 22, 2018
1 parent ac3d152 commit 7805aba
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmake/caches/Fuchsia-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ set(LLVM_TOOLCHAIN_TOOLS
llvm-size
llvm-strip
llvm-symbolizer
llvm-xray
opt
sancov
CACHE STRING "")
Expand Down
8 changes: 6 additions & 2 deletions lib/Driver/ToolChains/Fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
D.getLTOMode() == LTOK_Thin);
}

bool NeedSanitizerDeps = 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);

Expand All @@ -133,9 +134,12 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}

if (NeedSanitizerDeps)
if (NeedsSanitizerDeps)
linkSanitizerRuntimeDeps(ToolChain, CmdArgs);

if (NeedsXRayDeps)
linkXRayRuntimeDeps(ToolChain, CmdArgs);

AddRunTimeLibs(ToolChain, D, CmdArgs, Args);

if (Args.hasArg(options::OPT_pthread) ||
Expand Down
9 changes: 9 additions & 0 deletions lib/Driver/XRayArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
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());
Expand Down
20 changes: 20 additions & 0 deletions test/Driver/fuchsia.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@
// CHECK-SCUDO-SHARED: "-fsanitize=safe-stack,scudo"
// CHECK-SCUDO-SHARED: "[[RESOURCE_DIR]]{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}lib{{/|\\\\}}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: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-XRAY-X86: "-fxray-instrument"
// CHECK-XRAY-X86: "[[RESOURCE_DIR]]{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}lib{{/|\\\\}}libclang_rt.xray.a"
// CHECK-XRAY-X86: "[[RESOURCE_DIR]]{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}lib{{/|\\\\}}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: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-XRAY-AARCH64: "-fxray-instrument"
// CHECK-XRAY-AARCH64: "[[RESOURCE_DIR]]{{/|\\\\}}aarch64-fuchsia{{/|\\\\}}lib{{/|\\\\}}libclang_rt.xray.a"
// CHECK-XRAY-AARCH64: "[[RESOURCE_DIR]]{{/|\\\\}}aarch64-fuchsia{{/|\\\\}}lib{{/|\\\\}}libclang_rt.xray-basic.a"

// RUN: %clang %s -### --target=aarch64-fuchsia \
// RUN: -O3 -flto -mcpu=cortex-a53 2>&1 \
// RUN: -fuse-ld=lld \
Expand Down

0 comments on commit 7805aba

Please sign in to comment.