[PATCH] D147666: [OPENMP] Adds <install_path>/lib to rpath to avoid need to set LD_LIBRARY_PATH to find plugins.

Greg Rodgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 5 15:26:05 PDT 2023


gregrodgers created this revision.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
gregrodgers requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Currently, The user of an OpenMP application needs to set LD_LIBRARY_PATH to the directory
that contains the offload plugins. This change adds the rpath for OpenMP applications.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147666

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -813,7 +813,9 @@
                                  ArgStringList &CmdArgs) {
   // Enable -frtlib-add-rpath by default for the case of VE.
   const bool IsVE = TC.getTriple().isVE();
-  bool DefaultValue = IsVE;
+  const bool IsOpenMP = (TC.getDriver().getOpenMPRuntime(Args)
+		  != Driver::OMPRT_Unknown);
+  bool DefaultValue = IsVE || IsOpenMP ;
   if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
                     options::OPT_fno_rtlib_add_rpath, DefaultValue))
     return;
@@ -822,6 +824,16 @@
   if (TC.getVFS().exists(CandidateRPath)) {
     CmdArgs.push_back("-rpath");
     CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
+  } else {
+    if (IsOpenMP) {
+      SmallString<256> TopLibPath =
+        llvm::sys::path::parent_path(TC.getDriver().Dir);
+      llvm::sys::path::append(TopLibPath, "lib");
+      if (TC.getVFS().exists(TopLibPath)) {
+        CmdArgs.push_back("-rpath");
+        CmdArgs.push_back(Args.MakeArgString(TopLibPath));
+      }
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147666.511223.patch
Type: text/x-patch
Size: 1209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230405/3ab685bc/attachment-0001.bin>


More information about the cfe-commits mailing list