diff options
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 283d7ee..139fcea 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" @@ -238,8 +239,9 @@ static void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, // LIBRARY_PATH - included following the user specified library paths. // and only supported on native toolchains. - if (!TC.isCrossCompiling()) + if (!TC.isCrossCompiling()) { addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); + } } /// Add OpenMP linker script arguments at the end of the argument list so that @@ -2000,6 +2002,19 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, } } +static void addArchSpecificRPath(const ToolChain &TC, const ArgList &Args, + ArgStringList &CmdArgs) { + // In the cross-compilation case, arch-specific library path is likely + // unavailable at runtime. + if (TC.isCrossCompiling()) return; + + std::string CandidateRPath = TC.getArchSpecificLibPath(); + if (TC.getVFS().exists(CandidateRPath)) { + CmdArgs.push_back("-rpath"); + CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str())); + } +} + static void addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC, const ArgList &Args) { if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, @@ -2020,6 +2035,8 @@ static void addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC, // Already diagnosed. break; } + + addArchSpecificRPath(TC, Args, CmdArgs); } static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, @@ -2030,6 +2047,10 @@ static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, if (IsWhole) CmdArgs.push_back("-whole-archive"); CmdArgs.push_back(TC.getCompilerRTArgString(Args, Sanitizer, IsShared)); if (IsWhole) CmdArgs.push_back("-no-whole-archive"); + + if (IsShared) { + addArchSpecificRPath(TC, Args, CmdArgs); + } } // Tries to use a file with the list of dynamic symbols that need to be exported @@ -9002,6 +9023,8 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, } if (JA.isHostOffloading(Action::OFK_OpenMP)) CmdArgs.push_back("-lomptarget"); + + addArchSpecificRPath(ToolChain, Args, CmdArgs); } AddRunTimeLibs(ToolChain, D, CmdArgs, Args); |