@@ -965,6 +965,15 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
965965 getPlatformNameForTriple (TC.getTriple ()));
966966}
967967
968+ static void getClangLibraryPathOnDarwin (SmallVectorImpl<char > &libPath,
969+ const ArgList &args,
970+ const ToolChain &TC) {
971+ getRuntimeLibraryPath (libPath, args, TC);
972+ // Remove platform name.
973+ llvm::sys::path::remove_filename (libPath);
974+ llvm::sys::path::append (libPath, " clang" , " lib" , " darwin" );
975+ }
976+
968977// / Get the runtime library link path for static linking,
969978// / which is platform-specific and found relative to the compiler.
970979static void getRuntimeStaticLibraryPath (SmallVectorImpl<char > &runtimeLibPath,
@@ -1025,16 +1034,31 @@ getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple) {
10251034 llvm_unreachable (" Unsupported Darwin platform" );
10261035}
10271036
1037+ static std::string
1038+ getSanitizerRuntimeLibNameForDarwin (StringRef Sanitizer, const llvm::Triple &Triple) {
1039+ return (Twine (" libclang_rt." )
1040+ + Sanitizer + " _"
1041+ + getDarwinLibraryNameSuffixForTriple (Triple) + " _dynamic.dylib" ).str ();
1042+ }
1043+
1044+ bool toolchains::Darwin::sanitizerRuntimeLibExists (
1045+ const ArgList &args, StringRef sanitizer) const {
1046+ SmallString<128 > sanitizerLibPath;
1047+ getClangLibraryPathOnDarwin (sanitizerLibPath, args, *this );
1048+ llvm::sys::path::append (sanitizerLibPath,
1049+ getSanitizerRuntimeLibNameForDarwin (sanitizer, this ->getTriple ()));
1050+ return llvm::sys::fs::exists (sanitizerLibPath.str ());
1051+ }
1052+
1053+
10281054static void
10291055addLinkRuntimeLibForDarwin (const ArgList &Args, ArgStringList &Arguments,
10301056 StringRef DarwinLibName, bool AddRPath,
10311057 const ToolChain &TC) {
1032- SmallString<128 > Dir;
1033- getRuntimeLibraryPath (Dir, Args, TC);
1034- // Remove platform name.
1035- llvm::sys::path::remove_filename (Dir);
1036- llvm::sys::path::append (Dir, " clang" , " lib" , " darwin" );
1037- SmallString<128 > P (Dir);
1058+ SmallString<128 > ClangLibraryPath;
1059+ getClangLibraryPathOnDarwin (ClangLibraryPath, Args, TC);
1060+
1061+ SmallString<128 > P (ClangLibraryPath);
10381062 llvm::sys::path::append (P, DarwinLibName);
10391063 Arguments.push_back (Args.MakeArgString (P));
10401064
@@ -1053,7 +1077,7 @@ addLinkRuntimeLibForDarwin(const ArgList &Args, ArgStringList &Arguments,
10531077 // Add the path to the resource dir to rpath to support using the dylib
10541078 // from the default location without copying.
10551079 Arguments.push_back (" -rpath" );
1056- Arguments.push_back (Args.MakeArgString (Dir ));
1080+ Arguments.push_back (Args.MakeArgString (ClangLibraryPath ));
10571081 }
10581082}
10591083
@@ -1068,10 +1092,8 @@ addLinkSanitizerLibArgsForDarwin(const ArgList &Args,
10681092 Arguments.push_back (" -lc++abi" );
10691093
10701094 addLinkRuntimeLibForDarwin (Args, Arguments,
1071- (Twine (" libclang_rt." ) + Sanitizer + " _" +
1072- getDarwinLibraryNameSuffixForTriple (TC.getTriple ()) +
1073- " _dynamic.dylib" ).str (),
1074- /* AddRPath*/ true , TC);
1095+ getSanitizerRuntimeLibNameForDarwin (Sanitizer, TC.getTriple ()),
1096+ /* AddRPath=*/ true , TC);
10751097}
10761098
10771099ToolChain::InvocationInfo
0 commit comments