[llvm-branch-commits] [clang] 76c1c1d - [OpenMP] Fix library path missing when using OpenMP

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu May 19 18:31:05 PDT 2022


Author: Joseph Huber
Date: 2022-05-19T16:12:56-07:00
New Revision: 76c1c1dd2a01fa2b2511cd0da3ec71d03addb107

URL: https://github.com/llvm/llvm-project/commit/76c1c1dd2a01fa2b2511cd0da3ec71d03addb107
DIFF: https://github.com/llvm/llvm-project/commit/76c1c1dd2a01fa2b2511cd0da3ec71d03addb107.diff

LOG: [OpenMP] Fix library path missing when using OpenMP

The changes in D122444 caused OpenMP programs built with the
LLVM_ENABLE_RUNTIMES options to stop finding the libraries. We generally
expect to link against the libraries associated with the clang
installation itself but we no longer implicitly included that directory.
This patch adds in the include path of the clang installations library
to ensure we can find them.

Reviewed By: jdoerfert, MaskRay

Differential Revision: https://reviews.llvm.org/D122592

(cherry picked from commit fceea4e11028f4bfbafbd6893ddeb319420107d9)

Added: 
    clang/test/Driver/openmp-library-path.c

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    clang/lib/Driver/ToolChains/CommonArgs.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index dfcef2304040e..8f9244cae8dbc 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -661,6 +661,17 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
   }
 }
 
+void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
+                                        const ArgList &Args,
+                                        ArgStringList &CmdArgs) {
+  // Default to clang lib / lib64 folder, i.e. the same location as device
+  // runtime.
+  SmallString<256> DefaultLibPath =
+      llvm::sys::path::parent_path(TC.getDriver().Dir);
+  llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
+  CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+}
+
 void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
                                  ArgStringList &CmdArgs) {
   // Enable -frtlib-add-rpath by default for the case of VE.
@@ -720,6 +731,7 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
 
   if (RTKind == Driver::OMPRT_OMP)
     addOpenMPRuntimeSpecificRPath(TC, Args, CmdArgs);
+  addOpenMPRuntimeLibraryPath(TC, Args, CmdArgs);
 
   return true;
 }

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h
index 23012dc247e41..2bba1ee285e62 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -111,6 +111,9 @@ void addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
                                    llvm::opt::ArgStringList &CmdArgs);
 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
                           llvm::opt::ArgStringList &CmdArgs);
+void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
+                                 const llvm::opt::ArgList &Args,
+                                 llvm::opt::ArgStringList &CmdArgs);
 /// Returns true, if an OpenMP runtime has been added.
 bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
                       const llvm::opt::ArgList &Args,

diff  --git a/clang/test/Driver/openmp-library-path.c b/clang/test/Driver/openmp-library-path.c
new file mode 100644
index 0000000000000..e7aad339ced49
--- /dev/null
+++ b/clang/test/Driver/openmp-library-path.c
@@ -0,0 +1,5 @@
+// RUN: %clang -### -fopenmp=libomp --target=x86_64-linux-gnu -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin %s 2>&1 | FileCheck %s
+
+void foo() {}
+
+// CHECK: -L{{.*}}Inputs{{.*}}basic_linux_tree


        


More information about the llvm-branch-commits mailing list