libprofile_rt may be installed as a dylib on Darwin.

If we cannot find the static library, use the dylib instead.

llvm-svn: 133926
This commit is contained in:
Bill Wendling 2011-06-27 19:15:03 +00:00
parent b5ee311602
commit 087605809a
1 changed files with 30 additions and 19 deletions

View File

@ -155,19 +155,30 @@ static bool isObjCAutoRefCount(const ArgList &Args) {
} }
static void addProfileRT(const ToolChain &TC, const ArgList &Args, static void addProfileRT(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) { ArgStringList &CmdArgs,
if (Args.hasArg(options::OPT_fprofile_arcs) || llvm::Triple Triple) {
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
Args.hasArg(options::OPT_fprofile_generate) || Args.hasArg(options::OPT_fprofile_generate) ||
Args.hasArg(options::OPT_fcreate_profile) || Args.hasArg(options::OPT_fcreate_profile) ||
Args.hasArg(options::OPT_coverage)) { Args.hasArg(options::OPT_coverage)))
// GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov return;
// 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 // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to
// syntax, but that is not supported by old linkers. // the link line. We cannot do the same thing because unlike gcov there is a
const char *lib = Args.MakeArgString(TC.getDriver().Dir + "/../lib/" + // libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is
"libprofile_rt.a"); // not supported by old linkers.
CmdArgs.push_back(lib); 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, void Clang::AddPreprocessingOptions(const Driver &D,
@ -3241,7 +3252,7 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
// endfile_spec is empty. // 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_T_Group);
Args.AddAllArgs(CmdArgs, options::OPT_F); Args.AddAllArgs(CmdArgs, options::OPT_F);
@ -3400,7 +3411,7 @@ void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().GetFilePath("crtend.o"))); getToolChain().GetFilePath("crtend.o")));
} }
addProfileRT(getToolChain(), Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec = const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld")); Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@ -3708,7 +3719,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
"crtn.o"))); "crtn.o")));
} }
addProfileRT(getToolChain(), Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec = const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld")); Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@ -3863,7 +3874,7 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
"crtn.o"))); "crtn.o")));
} }
addProfileRT(getToolChain(), Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(), const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
ToolTriple.getTriple(), 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)) { if (Args.hasArg(options::OPT_use_gold_plugin)) {
CmdArgs.push_back("-plugin"); CmdArgs.push_back("-plugin");
@ -4171,7 +4182,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
"/usr/gnu/lib/libend.a"))); "/usr/gnu/lib/libend.a")));
} }
addProfileRT(getToolChain(), Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec = const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld")); 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"))); getToolChain().GetFilePath("crtn.o")));
} }
addProfileRT(getToolChain(), Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
const char *Exec = const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld")); Args.MakeArgString(getToolChain().GetProgramPath("ld"));