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));
+      }
+    }
   }
 }
 


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));
+      }
+    }
   }
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to