diff options
author | Xinliang David Li <davidxl@google.com> | 2015-10-22 06:15:31 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-10-22 06:15:31 +0000 |
commit | 69306c08234ba591f4e2cb71ea33b671464d0035 (patch) | |
tree | a8ceb8dc174f4d5db7bba1e39cf45a41de0fc2d8 /clang/lib/Driver/Tools.cpp | |
parent | cfd53b4e999301c5d6c7785c34c49d4e952e8aa4 (diff) | |
download | bcm5719-llvm-69306c08234ba591f4e2cb71ea33b671464d0035.tar.gz bcm5719-llvm-69306c08234ba591f4e2cb71ea33b671464d0035.zip |
clang driver toolchain refactoring
In this patch, the file static method addProfileRT is
moved to be a virtual member function of base ToolChain class.
This allows derived toolchain to override the default behavior
easily and make it consistent with Darwin toolchain (a TODO was
added for this refactoring - now removed). A new helper method
is also introduced to test if instrumentation profile option
is turned on or not.
Differential Revision: http://reviews.llvm.org/D13326
llvm-svn: 250994
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 3596a6a031c..74a49580b0b 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2444,34 +2444,12 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, } } -static const char *getCompilerRTArgString(const ToolChain &TC, - const llvm::opt::ArgList &Args, - StringRef Component, - bool Shared = false) { - return Args.MakeArgString(TC.getCompilerRT(Args, Component, Shared)); -} - // This adds the static libclang_rt.builtins-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. static void addClangRT(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { - CmdArgs.push_back(getCompilerRTArgString(TC, Args, "builtins")); -} - -static void addProfileRT(const ToolChain &TC, const ArgList &Args, - ArgStringList &CmdArgs) { - if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, - false) || - Args.hasArg(options::OPT_fprofile_generate) || - Args.hasArg(options::OPT_fprofile_generate_EQ) || - 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; - - CmdArgs.push_back(getCompilerRTArgString(TC, Args, "profile")); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins")); } namespace { @@ -2550,11 +2528,9 @@ static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, bool IsShared) { // Static runtimes must be forced into executable, so we wrap them in // whole-archive. - if (!IsShared) - CmdArgs.push_back("-whole-archive"); - CmdArgs.push_back(getCompilerRTArgString(TC, Args, Sanitizer, IsShared)); - if (!IsShared) - CmdArgs.push_back("-no-whole-archive"); + if (!IsShared) CmdArgs.push_back("-whole-archive"); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, Sanitizer, IsShared)); + if (!IsShared) CmdArgs.push_back("-no-whole-archive"); } // Tries to use a file with the list of dynamic symbols that need to be exported @@ -6876,9 +6852,6 @@ void darwin::Linker::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) && @@ -7084,7 +7057,7 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, } CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); - addProfileRT(getToolChain(), Args, CmdArgs); + getToolChain().addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); @@ -7676,7 +7649,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); } - addProfileRT(ToolChain, Args, CmdArgs); + ToolChain.addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); @@ -7965,7 +7938,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } - addProfileRT(getToolChain(), Args, CmdArgs); + getToolChain().addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); @@ -8489,7 +8462,7 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); // The profile runtime also needs access to system libraries. - addProfileRT(getToolChain(), Args, CmdArgs); + getToolChain().addProfileRTLibs(Args, CmdArgs); if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { @@ -8800,7 +8773,7 @@ void minix::Linker::ConstructJob(Compilation &C, const JobAction &JA, AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); - addProfileRT(getToolChain(), Args, CmdArgs); + getToolChain().addProfileRTLibs(Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { @@ -8992,7 +8965,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } - addProfileRT(getToolChain(), Args, CmdArgs); + getToolChain().addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); @@ -9098,18 +9071,18 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, "asan_dynamic", "asan_dynamic_runtime_thunk", }; for (const auto &Component : CompilerRTComponents) - CmdArgs.push_back(getCompilerRTArgString(TC, Args, Component)); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, Component)); // Make sure the dynamic runtime thunk is not optimized out at link time // to ensure proper SEH handling. CmdArgs.push_back(Args.MakeArgString("-include:___asan_seh_interceptor")); } else if (DLL) { - CmdArgs.push_back(getCompilerRTArgString(TC, Args, "asan_dll_thunk")); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dll_thunk")); } else { static const char *const CompilerRTComponents[] = { "asan", "asan_cxx", }; for (const auto &Component : CompilerRTComponents) - CmdArgs.push_back(getCompilerRTArgString(TC, Args, Component)); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, Component)); } } |