From 170cd100ed6f38ec5826dbd1bd6930ddfd3490a4 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Tue, 27 Oct 2015 05:15:35 +0000 Subject: [PATCH] Create undef reference to profile hook symbol Create undef reference to profile hook symbol when PGO instrumentation is turned on. This allows LLVM to omit emission of hook variable use method for every single module instrumented. llvm-svn: 251385 --- clang/lib/Driver/ToolChains.cpp | 13 +++++++++++++ clang/lib/Driver/ToolChains.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index e8a2d833d3cb1..d0f4dac3e13d4 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -25,6 +25,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" +#include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" @@ -3811,6 +3812,18 @@ SanitizerMask Linux::getSupportedSanitizers() const { return Res; } +void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + if (!needsProfileRT(Args)) return; + + // Add linker option -u__llvm_runtime_variable to cause runtime + // initialization module to be linked in. + if (!Args.hasArg(options::OPT_coverage)) + CmdArgs.push_back(Args.MakeArgString( + Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); + ToolChain::addProfileRTLibs(Args, CmdArgs); +} + /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 01ff328779834..fcb7561b1ff9f 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -744,6 +744,8 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { llvm::opt::ArgStringList &CC1Args) const override; bool isPIEDefault() const override; SanitizerMask getSupportedSanitizers() const override; + void addProfileRTLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; std::string Linker; std::vector ExtraOpts;