[OpenMP] Fix library path missing when using OpenMP
authorJoseph Huber <jhuber6@vols.utk.edu>
Mon, 28 Mar 2022 16:23:21 +0000 (12:23 -0400)
committerJoseph Huber <jhuber6@vols.utk.edu>
Mon, 28 Mar 2022 18:30:35 +0000 (14:30 -0400)
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

clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/test/Driver/openmp-library-path.c [new file with mode: 0644]

index b9efb6b77f0747d4ed32c5e7ebdbc4521d998185..eaab356a008f253803a3bf76c0719213413c587f 100644 (file)
@@ -668,6 +668,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.
@@ -727,6 +738,7 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
 
   if (RTKind == Driver::OMPRT_OMP)
     addOpenMPRuntimeSpecificRPath(TC, Args, CmdArgs);
+  addOpenMPRuntimeLibraryPath(TC, Args, CmdArgs);
 
   return true;
 }
index 23012dc247e416ad848225aaa42f01d8322c6107..2bba1ee285e62b8ed8881dac20fb5d7adfd7ee05 100644 (file)
@@ -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 (file)
index 0000000..e7aad33
--- /dev/null
@@ -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