diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-06-27 19:15:03 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-06-27 19:15:03 +0000 |
commit | 3f4be6fb8872942f567166ab8d99c89885f26103 (patch) | |
tree | 7cffed4d0a5a3f352ec75a37e78846143a008b45 /lib/Driver/Tools.cpp | |
parent | 7e47e1e7e6a2b83d903c97129f27e92f584c3dc2 (diff) |
libprofile_rt may be installed as a dylib on Darwin.
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
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r-- | lib/Driver/Tools.cpp | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 542c150983..705b8779df 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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")); |