Skip to content

Commit 76c1c1d

Browse files
jhuber6tstellar
authored andcommitted
[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 fceea4e)
1 parent 588b95a commit 76c1c1d

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,17 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
661661
}
662662
}
663663

664+
void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
665+
const ArgList &Args,
666+
ArgStringList &CmdArgs) {
667+
// Default to clang lib / lib64 folder, i.e. the same location as device
668+
// runtime.
669+
SmallString<256> DefaultLibPath =
670+
llvm::sys::path::parent_path(TC.getDriver().Dir);
671+
llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
672+
CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
673+
}
674+
664675
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
665676
ArgStringList &CmdArgs) {
666677
// Enable -frtlib-add-rpath by default for the case of VE.
@@ -720,6 +731,7 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
720731

721732
if (RTKind == Driver::OMPRT_OMP)
722733
addOpenMPRuntimeSpecificRPath(TC, Args, CmdArgs);
734+
addOpenMPRuntimeLibraryPath(TC, Args, CmdArgs);
723735

724736
return true;
725737
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ void addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
111111
llvm::opt::ArgStringList &CmdArgs);
112112
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
113113
llvm::opt::ArgStringList &CmdArgs);
114+
void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
115+
const llvm::opt::ArgList &Args,
116+
llvm::opt::ArgStringList &CmdArgs);
114117
/// Returns true, if an OpenMP runtime has been added.
115118
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
116119
const llvm::opt::ArgList &Args,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -fopenmp=libomp --target=x86_64-linux-gnu -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin %s 2>&1 | FileCheck %s
2+
3+
void foo() {}
4+
5+
// CHECK: -L{{.*}}Inputs{{.*}}basic_linux_tree

0 commit comments

Comments
 (0)