Skip to content

Commit 1977404

Browse files
authored
[OpenMP] Respect LLVM per-target install directories (#83282)
Summary: One recurring problem we have with the OpenMP libraries is that they are potentially conflicting with ones found on the system, this occurs when there are two copies and one is used for linking that it not attached to the correspoding clang compiler. LLVM already uses target specific directories for this, like with libc++, which are always searched first. This patch changes the install directory to be `lib/x86_64-unknown-linux-gnu` for example. Notable changes would be that users will need to change their LD_LIBRARY_PATH settings optionally, or use default rt-rpath options. This should fix problems were users are linking the wrong versions of static libraries
1 parent caca8d3 commit 1977404

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,13 +2763,13 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
27632763
const llvm::opt::ArgList &DriverArgs,
27642764
llvm::opt::ArgStringList &CC1Args,
27652765
StringRef BitcodeSuffix,
2766-
const llvm::Triple &Triple) {
2766+
const llvm::Triple &Triple,
2767+
const ToolChain &HostTC) {
27672768
SmallVector<StringRef, 8> LibraryPaths;
27682769

2769-
// Add path to clang lib / lib64 folder.
2770-
SmallString<256> DefaultLibPath = llvm::sys::path::parent_path(D.Dir);
2771-
llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
2772-
LibraryPaths.emplace_back(DefaultLibPath.c_str());
2770+
// Check all of the standard library search paths used by the compiler.
2771+
for (const auto &LibPath : HostTC.getFilePaths())
2772+
LibraryPaths.emplace_back(LibPath);
27732773

27742774
// Add user defined library paths from LIBRARY_PATH.
27752775
std::optional<std::string> LibPath =

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
214214

215215
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
216216
llvm::opt::ArgStringList &CC1Args,
217-
StringRef BitcodeSuffix, const llvm::Triple &Triple);
217+
StringRef BitcodeSuffix, const llvm::Triple &Triple,
218+
const ToolChain &HostTC);
218219

219220
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
220221
const llvm::opt::ArgList &Args,

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ void CudaToolChain::addClangTargetOptions(
903903
return;
904904

905905
addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
906-
getTriple());
906+
getTriple(), HostTC);
907907
}
908908
}
909909

openmp/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ if (OPENMP_STANDALONE_BUILD)
4646
set(CMAKE_CXX_EXTENSIONS NO)
4747
else()
4848
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
49-
# If building in tree, we honor the same install suffix LLVM uses.
50-
set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING
51-
"Path where built OpenMP libraries should be installed.")
49+
50+
# When building in tree we install the runtime according to the LLVM settings.
51+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
52+
set(OPENMP_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
53+
"Path where built openmp libraries should be installed.")
54+
else()
55+
set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING
56+
"Path where built OpenMP libraries should be installed.")
57+
endif()
5258

5359
if (NOT MSVC)
5460
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)

0 commit comments

Comments
 (0)