diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h --- a/clang/lib/Driver/ToolChains/CommonArgs.h +++ b/clang/lib/Driver/ToolChains/CommonArgs.h @@ -73,6 +73,10 @@ const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); +void addOpenMPRuntimeSpecificRPath(const ToolChain &TC, + const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs); + void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); /// Returns true, if an OpenMP runtime has been added. diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -645,6 +645,17 @@ /*IsLTO=*/true); } +void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC, + const ArgList &Args, + ArgStringList &CmdArgs) { + const Driver &D = TC.getDriver(); + std::string CandidateRPath = D.Dir + "/../lib" CLANG_LIBDIR_SUFFIX; + if (TC.getVFS().exists(CandidateRPath)) { + CmdArgs.push_back("-rpath"); + CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str())); + } +} + void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { // Enable -frtlib-add-rpath by default for the case of VE. @@ -697,6 +708,9 @@ if (RTKind == Driver::OMPRT_GOMP && GompNeedsRT) CmdArgs.push_back("-lrt"); + if (RTKind == Driver::OMPRT_OMP) + addOpenMPRuntimeSpecificRPath(TC, Args, CmdArgs); + if (IsOffloadingHost) CmdArgs.push_back("-lomptarget"); @@ -1686,6 +1700,12 @@ llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX); LibraryPaths.emplace_back(DefaultLibPath.c_str()); + // Add path to runtimes binary folder, used by ENABLE_RUNTIMES build + SmallString<256> RuntimesBinPath = llvm::sys::path::parent_path(D.Dir); + llvm::sys::path::append(RuntimesBinPath, + "runtimes/runtimes-bins/openmp/libomptarget"); + LibraryPaths.emplace_back(RuntimesBinPath.c_str()); + OptSpecifier LibomptargetBCPathOpt = Triple.isAMDGCN() ? options::OPT_libomptarget_amdgcn_bc_path_EQ : options::OPT_libomptarget_nvptx_bc_path_EQ; diff --git a/clang/tools/amdgpu-arch/CMakeLists.txt b/clang/tools/amdgpu-arch/CMakeLists.txt --- a/clang/tools/amdgpu-arch/CMakeLists.txt +++ b/clang/tools/amdgpu-arch/CMakeLists.txt @@ -14,4 +14,6 @@ add_clang_tool(amdgpu-arch AMDGPUArch.cpp) +set_target_properties(amdgpu-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON) + clang_target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64) diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp --- a/openmp/libomptarget/src/rtl.cpp +++ b/openmp/libomptarget/src/rtl.cpp @@ -73,13 +73,24 @@ return; } + std::string full_plugin_name; + void *handle = dlopen("libomptarget.so", RTLD_NOW); + if (!handle) + DP("dlopen() failed: %s\n", dlerror()); + char *libomptarget_dir_name = new char[256]; + if (dlinfo(handle, RTLD_DI_ORIGIN, libomptarget_dir_name) == -1) + DP("RTLD_DI_ORIGIN failed: %s\n", dlerror()); + DP("Loading RTLs...\n"); // Attempt to open all the plugins and, if they exist, check if the interface // is correct and if they are supporting any devices. for (auto *Name : RTLNames) { DP("Loading library '%s'...\n", Name); - void *dynlib_handle = dlopen(Name, RTLD_NOW); + + full_plugin_name.assign(libomptarget_dir_name).append("/").append(Name); + DP("Loading library '%s'...\n", full_plugin_name.c_str()); + void *dynlib_handle = dlopen(full_plugin_name.c_str(), RTLD_NOW); if (!dynlib_handle) { // Library does not exist or cannot be found. diff --git a/openmp/libomptarget/test/lit.cfg b/openmp/libomptarget/test/lit.cfg --- a/openmp/libomptarget/test/lit.cfg +++ b/openmp/libomptarget/test/lit.cfg @@ -70,14 +70,10 @@ config.test_flags += " -Wl,-rpath," + config.library_dir config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory else: # Unices - append_dynamic_library_path('LD_LIBRARY_PATH', config.library_dir, ":") - append_dynamic_library_path('LD_LIBRARY_PATH', \ - config.omp_host_rtl_directory, ":") + config.test_flags += " -Wl,-rpath," + config.library_dir + config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory if config.cuda_libdir: - append_dynamic_library_path('LD_LIBRARY_PATH', config.cuda_libdir, ":") - append_dynamic_library_path('LIBRARY_PATH', config.library_dir, ":") - append_dynamic_library_path('LIBRARY_PATH', \ - config.omp_host_rtl_directory, ":") + config.test_flags += " -Wl,-rpath," + config.cuda_libdir # substitutions # - for targets that exist in the system create the actual command. @@ -182,7 +178,8 @@ config.substitutions.append(("%clangxx", config.test_cxx_compiler)) config.substitutions.append(("%clang", config.test_c_compiler)) config.substitutions.append(("%openmp_flags", config.test_openmp_flags)) -if config.cuda_path: + +if config.cuda_path and config.cuda_path != 'CUDA_TOOLKIT_ROOT_DIR-NOTFOUND': config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path)) else: config.substitutions.append(("%cuda_flags", ""))