Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Get rid of obsolete addProfileRT(), generalize the relevant addProfil…
Browse files Browse the repository at this point in the history
…eRTLinux() to all OS

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201789 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Alexey Samsonov committed Feb 20, 2014
1 parent a9e178a commit 43ad7ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
46 changes: 15 additions & 31 deletions lib/Driver/Tools.cpp
Expand Up @@ -225,26 +225,6 @@ static bool isObjCRuntimeLinked(const ArgList &Args) {
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.
Expand Down Expand Up @@ -1779,6 +1759,10 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC) {
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.
Expand All @@ -1797,7 +1781,7 @@ static void addClangRTLinux(
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) ||
Expand All @@ -1806,11 +1790,11 @@ static void addProfileRTLinux(
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));
Expand Down Expand Up @@ -5440,7 +5424,7 @@ void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA,
}
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"));
Expand Down Expand Up @@ -5552,7 +5536,7 @@ void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().GetFilePath("crtend.o")));
}

addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
addProfileRT(getToolChain(), Args, CmdArgs);

const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
Expand Down Expand Up @@ -6129,7 +6113,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
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"));
Expand Down Expand Up @@ -6378,7 +6362,7 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
"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));
Expand Down Expand Up @@ -6777,7 +6761,7 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
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) &&
Expand Down Expand Up @@ -6891,7 +6875,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,

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)) {
Expand Down Expand Up @@ -7093,7 +7077,7 @@ void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().GetFilePath("crtn.o")));
}

addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
addProfileRT(getToolChain(), Args, CmdArgs);

const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
Expand Down
9 changes: 9 additions & 0 deletions test/Driver/coverage-ld.c
Expand Up @@ -17,3 +17,12 @@
//
// CHECK-LINUX-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
// CHECK-LINUX-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
//
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
// RUN: -target x86_64-unknown-freebsd --coverage \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_freebsd64_tree \
// RUN: | FileCheck --check-prefix=CHECK-FREEBSD-X86-64 %s
//
// CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
// CHECK-FREEBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}freebsd{{/|\\\\}}libclang_rt.profile-x86_64.a"

0 comments on commit 43ad7ad

Please sign in to comment.