diff options
| author | Justin Bogner <mail@justinbogner.com> | 2015-05-12 00:31:33 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2015-05-12 00:31:33 +0000 |
| commit | f44ddae71e6464851dbafba0e40c66f9db9db4cf (patch) | |
| tree | 43663af11218265bdf36b066009856dc31ea2de0 /clang/lib/Driver | |
| parent | 18bbe191cdfe1b1bb64fc0d80ee5113f9cd56e4d (diff) | |
| download | bcm5719-llvm-f44ddae71e6464851dbafba0e40c66f9db9db4cf.tar.gz bcm5719-llvm-f44ddae71e6464851dbafba0e40c66f9db9db4cf.zip | |
Driver: Make profiling flags work with -nostdlib on Darwin
Compiler-rt's Profiling library isn't part of the stdlib, so -nostdlib
shouldn't prevent it from being linked. This makes Darwin behave like
other toolchains, and link in the profile runtime irrespective of
-nostdlib, since the resulting program can't be run unless you link
this.
I've also added a test to show that other toolchains already behave
like this.
llvm-svn: 237074
Diffstat (limited to 'clang/lib/Driver')
| -rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 34 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains.h | 5 | ||||
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 5 |
3 files changed, 30 insertions, 14 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 0d9e2120396..a4f56c7e29b 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -326,6 +326,26 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, } } +void MachO::addProfileRTLibs(const ArgList &Args, + ArgStringList &CmdArgs) const { + if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, + false) || + Args.hasArg(options::OPT_fprofile_generate) || + Args.hasArg(options::OPT_fprofile_instr_generate) || + Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || + Args.hasArg(options::OPT_fcreate_profile) || + Args.hasArg(options::OPT_coverage))) + return; + + // Select the appropriate runtime library for the target. + if (isTargetIOSBased()) + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", + /*AlwaysLink*/ true); + else + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", true, + /*AlwaysLink*/ true); +} + void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer) const { @@ -376,20 +396,6 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, return; } - // If we are building profile support, link that library in. - if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, - false) || - Args.hasArg(options::OPT_fprofile_generate) || - Args.hasArg(options::OPT_fprofile_instr_generate) || - Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || - Args.hasArg(options::OPT_fcreate_profile) || - Args.hasArg(options::OPT_coverage)) { - // Select the appropriate runtime library for the target. - if (isTargetIOSBased()) - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a"); - else - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a"); - } const SanitizerArgs &Sanitize = getSanitizerArgs(); diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 456bf77c289..d2865ec16f0 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -239,6 +239,11 @@ public: bool IsEmbedded = false, bool AddRPath = false) const; + /// Add any profiling runtime libraries that are needed. This is essentially a + /// MachO specific version of addProfileRT in Tools.cpp. + void addProfileRTLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; + /// } /// @name ToolChain Implementation /// { diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index e215b6eed5c..c1b51583a30 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -6328,6 +6328,11 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_fnested_functions)) CmdArgs.push_back("-allow_stack_execute"); + // TODO: It would be nice to use addProfileRT() here, but darwin's compiler-rt + // paths are different enough from other toolchains that this needs a fair + // amount of refactoring done first. + getMachOToolChain().addProfileRTLibs(Args, CmdArgs); + if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (getToolChain().getDriver().CCCIsCXX()) |

