]> granicus.if.org Git - clang/commitdiff
Create undef reference to profile hook symbol
authorXinliang David Li <davidxl@google.com>
Tue, 27 Oct 2015 05:15:35 +0000 (05:15 +0000)
committerXinliang David Li <davidxl@google.com>
Tue, 27 Oct 2015 05:15:35 +0000 (05:15 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251385 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h

index e8a2d833d3cb1568568992325c0b7cee024e9ce1..d0f4dac3e13d425d0c0e8c0ba50b6c9302b1441d 100644 (file)
@@ -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,
index 01ff32877983467d076b6af8389d934915d75c7e..fcb7561b1ff9f1841623ee34a90c0fb4e4297f6d 100644 (file)
@@ -744,6 +744,8 @@ public:
       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<std::string> ExtraOpts;