Get rid of obsolete addProfileRT(), generalize the relevant addProfileRTLinux() to all OS
llvm-svn: 201789
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index c866992..f014822 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -225,26 +225,6 @@
return Args.hasArg(options::OPT_fobjc_link_runtime);
}
-static void addProfileRT(const ToolChain &TC, const ArgList &Args,
- ArgStringList &CmdArgs,
- llvm::Triple Triple) {
- if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
- Args.hasArg(options::OPT_fprofile_generate) ||
- Args.hasArg(options::OPT_fprofile_instr_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.
- std::string ProfileRT =
- std::string(TC.getDriver().Dir) + "/../lib/libprofile_rt.a";
-
- CmdArgs.push_back(Args.MakeArgString(ProfileRT));
-}
-
static bool forwardToGCC(const Option &O) {
// Don't forward inputs from the original command line. They are added from
// InputInfoList.
@@ -1779,6 +1759,10 @@
return TC.getArchName();
}
+static StringRef getOSNameForCompilerRTLib(const ToolChain &TC) {
+ return TC.getOS();
+}
+
// This adds the static libclang_rt.arch.a directly to the command line
// FIXME: Make sure we can also emit shared objects if they're requested
// and available, check for possible errors, etc.
@@ -1797,7 +1781,7 @@
CmdArgs.push_back("-lgcc_eh");
}
-static void addProfileRTLinux(
+static void addProfileRT(
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
Args.hasArg(options::OPT_fprofile_generate) ||
@@ -1806,11 +1790,11 @@
Args.hasArg(options::OPT_coverage)))
return;
- // The profile runtime is located in the Linux library directory and has name
- // "libclang_rt.profile-<ArchName>.a".
+ // The profile runtime is located in the OS-specific resource directory and
+ // has name "libclang_rt.profile-<ArchName>.a".
SmallString<128> LibProfile(TC.getDriver().ResourceDir);
llvm::sys::path::append(
- LibProfile, "lib", "linux",
+ LibProfile, "lib", getOSNameForCompilerRTLib(TC),
Twine("libclang_rt.profile-") + getArchNameForCompilerRTLib(TC) + ".a");
CmdArgs.push_back(Args.MakeArgString(LibProfile));
@@ -5440,7 +5424,7 @@
}
CmdArgs.push_back(Args.MakeArgString(LibPath + "crtn.o"));
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
+ addProfileRT(getToolChain(), Args, CmdArgs);
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@@ -5552,7 +5536,7 @@
getToolChain().GetFilePath("crtend.o")));
}
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
+ addProfileRT(getToolChain(), Args, CmdArgs);
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
@@ -6129,7 +6113,7 @@
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
- addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple());
+ addProfileRT(ToolChain, Args, CmdArgs);
const char *Exec =
Args.MakeArgString(ToolChain.GetProgramPath("ld"));
@@ -6378,7 +6362,7 @@
"crtn.o")));
}
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
+ addProfileRT(getToolChain(), Args, CmdArgs);
const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
@@ -6777,7 +6761,7 @@
addDfsanRTLinux(getToolChain(), Args, CmdArgs);
// The profile runtime also needs access to system libraries.
- addProfileRTLinux(getToolChain(), Args, CmdArgs);
+ addProfileRT(getToolChain(), Args, CmdArgs);
if (D.CCCIsCXX() &&
!Args.hasArg(options::OPT_nostdlib) &&
@@ -6891,7 +6875,7 @@
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
+ addProfileRT(getToolChain(), Args, CmdArgs);
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
@@ -7093,7 +7077,7 @@
getToolChain().GetFilePath("crtn.o")));
}
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
+ addProfileRT(getToolChain(), Args, CmdArgs);
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));