]> granicus.if.org Git - clang/commitdiff
libprofile_rt may be installed as a dylib on Darwin.
authorBill Wendling <isanbard@gmail.com>
Mon, 27 Jun 2011 19:15:03 +0000 (19:15 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 27 Jun 2011 19:15:03 +0000 (19:15 +0000)
If we cannot find the static library, use the dylib instead.

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

lib/Driver/Tools.cpp

index 542c150983c636dc3b0e66e4ccbe7a373e311640..705b8779df70376ee7f7c50a7474f74e90ff50a8 100644 (file)
@@ -155,19 +155,30 @@ static bool isObjCAutoRefCount(const ArgList &Args) {
 }
 
 static void addProfileRT(const ToolChain &TC, const ArgList &Args,
-                         ArgStringList &CmdArgs) {
-  if (Args.hasArg(options::OPT_fprofile_arcs) ||
-      Args.hasArg(options::OPT_fprofile_generate) ||
-      Args.hasArg(options::OPT_fcreate_profile) ||
-      Args.hasArg(options::OPT_coverage)) {
-    // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov
-    // to the link line. We cannot do the same thing because unlike gcov
-    // there is a libprofile_rt.so. We used to use the -l:libprofile_rt.a
-    // syntax, but that is not supported by old linkers.
-    const char *lib = Args.MakeArgString(TC.getDriver().Dir + "/../lib/" +
-                                         "libprofile_rt.a");
-    CmdArgs.push_back(lib);
+                         ArgStringList &CmdArgs,
+                         llvm::Triple Triple) {
+  if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
+        Args.hasArg(options::OPT_fprofile_generate) ||
+        Args.hasArg(options::OPT_fcreate_profile) ||
+        Args.hasArg(options::OPT_coverage)))
+    return;
+
+  // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to
+  // the link line. We cannot do the same thing because unlike gcov there is a
+  // libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is
+  // not supported by old linkers.
+  llvm::Twine ProfileRT =
+    llvm::Twine(TC.getDriver().Dir) + "/../lib/" + "libprofile_rt.a";
+
+  if (Triple.getOS() == llvm::Triple::Darwin) {
+    // On Darwin, if the static library doesn't exist try the dylib.
+    bool Exists;
+    if (llvm::sys::fs::exists(ProfileRT.str(), Exists) || !Exists)
+      ProfileRT =
+        llvm::Twine(TC.getDriver().Dir) + "/../lib/" + "libprofile_rt.dylib";
   }
+
+  CmdArgs.push_back(Args.MakeArgString(ProfileRT));
 }
 
 void Clang::AddPreprocessingOptions(const Driver &D,
@@ -3241,7 +3252,7 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
     // endfile_spec is empty.
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
   Args.AddAllArgs(CmdArgs, options::OPT_F);
@@ -3400,7 +3411,7 @@ void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA,
                                 getToolChain().GetFilePath("crtend.o")));
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@@ -3708,7 +3719,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
                                                                     "crtn.o")));
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@@ -3863,7 +3874,7 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
                                                                     "crtn.o")));
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
                                                       ToolTriple.getTriple(),
@@ -4087,7 +4098,7 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
     }
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   if (Args.hasArg(options::OPT_use_gold_plugin)) {
     CmdArgs.push_back("-plugin");
@@ -4171,7 +4182,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
                                               "/usr/gnu/lib/libend.a")));
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
@@ -4328,7 +4339,7 @@ void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA,
                               getToolChain().GetFilePath("crtn.o")));
   }
 
-  addProfileRT(getToolChain(), Args, CmdArgs);
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath("ld"));