Skip to content

Commit fceea4e

Browse files
committed
[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
1 parent 7c38fd6 commit fceea4e

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
@@ -668,6 +668,17 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
668668
}
669669
}
670670

671+
void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
672+
const ArgList &Args,
673+
ArgStringList &CmdArgs) {
674+
// Default to clang lib / lib64 folder, i.e. the same location as device
675+
// runtime.
676+
SmallString<256> DefaultLibPath =
677+
llvm::sys::path::parent_path(TC.getDriver().Dir);
678+
llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
679+
CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
680+
}
681+
671682
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
672683
ArgStringList &CmdArgs) {
673684
// Enable -frtlib-add-rpath by default for the case of VE.
@@ -727,6 +738,7 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
727738

728739
if (RTKind == Driver::OMPRT_OMP)
729740
addOpenMPRuntimeSpecificRPath(TC, Args, CmdArgs);
741+
addOpenMPRuntimeLibraryPath(TC, Args, CmdArgs);
730742

731743
return true;
732744
}

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)