[cfe-commits] r133926 - /cfe/trunk/lib/Driver/Tools.cpp
Bill Wendling
isanbard at gmail.com
Mon Jun 27 12:15:03 PDT 2011
Author: void
Date: Mon Jun 27 14:15:03 2011
New Revision: 133926
URL: http://llvm.org/viewvc/llvm-project?rev=133926&view=rev
Log:
libprofile_rt may be installed as a dylib on Darwin.
If we cannot find the static library, use the dylib instead.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=133926&r1=133925&r2=133926&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Jun 27 14:15:03 2011
@@ -155,19 +155,30 @@
}
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 @@
// 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 @@
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 @@
"crtn.o")));
}
- addProfileRT(getToolChain(), Args, CmdArgs);
+ addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@@ -3863,7 +3874,7 @@
"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 @@
}
}
- 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 @@
"/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 @@
getToolChain().GetFilePath("crtn.o")));
}
- addProfileRT(getToolChain(), Args, CmdArgs);
+ addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
More information about the cfe-commits
mailing list