@@ -1185,29 +1185,6 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
1185
1185
Args.MakeArgString (Twine (PluginOptPrefix) + " -implicit-mapsyms" ));
1186
1186
}
1187
1187
1188
- std::string tools::FindDebugPerfInLibraryPath (const std::string &RLib) {
1189
- const char *DirList = ::getenv (" LIBRARY_PATH" );
1190
- if (!DirList)
1191
- return " " ;
1192
- StringRef Dirs (DirList);
1193
- if (Dirs.empty ()) // Empty string should not add '.'.
1194
- return " " ;
1195
-
1196
- StringRef::size_type Delim;
1197
- while ((Delim = Dirs.find (llvm::sys::EnvPathSeparator)) != StringRef::npos) {
1198
- if (Delim != 0 ) { // Leading colon.
1199
- if (Dirs.substr (0 , Delim).ends_with (RLib))
1200
- return Dirs.substr (0 , Delim).str ();
1201
- }
1202
- Dirs = Dirs.substr (Delim + 1 );
1203
- }
1204
- if (!Dirs.empty ()) {
1205
- if (Dirs.ends_with (RLib))
1206
- return Dirs.str ();
1207
- }
1208
- return " " ;
1209
- }
1210
-
1211
1188
void tools::addOpenMPRuntimeSpecificRPath (const ToolChain &TC,
1212
1189
const ArgList &Args,
1213
1190
ArgStringList &CmdArgs) {
@@ -1223,9 +1200,17 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
1223
1200
if (TC.getSanitizerArgs (Args).needsAsanRt ())
1224
1201
LibSuffix.append (" /asan" );
1225
1202
}
1226
- std::string CandidateRPath = FindDebugPerfInLibraryPath (LibSuffix);
1227
- if (CandidateRPath.empty ())
1228
- CandidateRPath = D.Dir + " /../" + LibSuffix;
1203
+
1204
+ // Check if the device library can be found in
1205
+ // one of the LIBRARY_PATH directories.
1206
+ ArgStringList EnvLibraryPaths;
1207
+ addDirectoryList (Args, EnvLibraryPaths, " " , " LIBRARY_PATH" );
1208
+ for (auto &EnvLibraryPath : EnvLibraryPaths) {
1209
+ if (llvm::sys::fs::exists (EnvLibraryPath)) {
1210
+ CmdArgs.push_back (" -rpath" );
1211
+ CmdArgs.push_back (Args.MakeArgString (EnvLibraryPath));
1212
+ }
1213
+ }
1229
1214
1230
1215
if (Args.hasFlag (options::OPT_fopenmp_implicit_rpath,
1231
1216
options::OPT_fno_openmp_implicit_rpath, true )) {
@@ -1239,13 +1224,31 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
1239
1224
CmdArgs.push_back (Args.MakeArgString (TC.getCompilerRTPath ()));
1240
1225
}
1241
1226
1227
+ // In case LibSuffix was not built, try lib
1228
+ std::string CandidateRPath_suf = D.Dir + " /../" + LibSuffix;
1242
1229
CmdArgs.push_back (" -rpath" );
1243
- CmdArgs.push_back (Args.MakeArgString (CandidateRPath.c_str ()));
1244
- std::string rocmPath = Args.getLastArgValue (clang::driver::options::OPT_rocm_path_EQ).str ();
1245
- if (rocmPath.size () != 0 ){
1246
- rocmPath = rocmPath + " /lib" ;
1230
+ CmdArgs.push_back (Args.MakeArgString (CandidateRPath_suf.c_str ()));
1231
+
1232
+ // Add lib directory in case LibSuffix does not exist
1233
+ std::string CandidateRPath_lib = D.Dir + " /../lib" ;
1234
+ if ((!llvm::sys::fs::exists (CandidateRPath_suf)) &&
1235
+ (llvm::sys::fs::exists (CandidateRPath_lib))) {
1247
1236
CmdArgs.push_back (" -rpath" );
1248
- CmdArgs.push_back (Args.MakeArgString (rocmPath.c_str ()));
1237
+ CmdArgs.push_back (Args.MakeArgString (CandidateRPath_lib.c_str ()));
1238
+ }
1239
+
1240
+ std::string rocmPath =
1241
+ Args.getLastArgValue (clang::driver::options::OPT_rocm_path_EQ).str ();
1242
+ if (rocmPath.size () != 0 ) {
1243
+ std::string rocmPath_lib = rocmPath + " /lib" ;
1244
+ std::string rocmPath_suf = rocmPath + " /" + LibSuffix;
1245
+ if (llvm::sys::fs::exists (rocmPath_suf)) {
1246
+ CmdArgs.push_back (" -rpath" );
1247
+ CmdArgs.push_back (Args.MakeArgString (rocmPath_suf.c_str ()));
1248
+ } else if (llvm::sys::fs::exists (rocmPath_lib)) {
1249
+ CmdArgs.push_back (" -rpath" );
1250
+ CmdArgs.push_back (Args.MakeArgString (rocmPath_lib.c_str ()));
1251
+ }
1249
1252
}
1250
1253
if (llvm::find_if (CmdArgs, [](StringRef str) {
1251
1254
return !str.compare (" --enable-new-dtags" );
0 commit comments