From 7811d19515bc925e5d0040b8fadbdc079a20d282 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 20 Feb 2014 13:57:37 +0000 Subject: [PATCH] Get rid of obsolete addProfileRT(), generalize the relevant addProfileRTLinux() to all OS llvm-svn: 201789 --- clang/lib/Driver/Tools.cpp | 46 +++++++++++---------------------- clang/test/Driver/coverage-ld.c | 9 +++++++ 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index c86699261372..f014822fa41f 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -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/gcc/lib/gcc// -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 @@ 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. @@ -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) || @@ -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-.a". + // The profile runtime is located in the OS-specific resource directory and + // has name "libclang_rt.profile-.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 @@ 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")); @@ -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")); @@ -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")); @@ -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)); @@ -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) && @@ -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)) { @@ -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")); diff --git a/clang/test/Driver/coverage-ld.c b/clang/test/Driver/coverage-ld.c index cbb7dd472410..0e39249a2f3e 100644 --- a/clang/test/Driver/coverage-ld.c +++ b/clang/test/Driver/coverage-ld.c @@ -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"