If the LLVM is shared, add its lib dir to the hardcoded list used for library lookups

When looking up the LTO linker plugin and compiler-rt libraries.
This commit is contained in:
Martin Kinkelin 2021-02-20 13:14:42 +01:00
parent 01555c47d5
commit 282ade3e31
2 changed files with 21 additions and 1 deletions

View file

@ -486,6 +486,10 @@ append("-DLDC_LLVM_VER=${LDC_LLVM_VER}" LDC_CXXFLAGS)
append("\"-DLDC_LIBDIR_SUFFIX=R\\\"(${LIB_SUFFIX})\\\"\"" LDC_CXXFLAGS)
append("-DLDC_HOST_${D_COMPILER_ID}=1" LDC_CXXFLAGS)
append("-DLDC_HOST_FE_VER=${D_COMPILER_FE_VERSION}" LDC_CXXFLAGS)
# If the LLVM is shared, add its lib dir to the hardcoded list used for library lookups.
if(LLVM_IS_SHARED)
append("\"-DLDC_LLVM_LIBDIR=R\\\"(${LLVM_LIBRARY_DIRS})\\\"\"" LDC_CXXFLAGS)
endif()
#
# LLD integration (requires headers & libs)

View file

@ -101,6 +101,9 @@ std::string getLTOGoldPluginPath() {
exe_path::prependLibDir("LLVMgold-ldc.so"),
// Perhaps the user copied the plugin to LDC's lib dir.
exe_path::prependLibDir("LLVMgold.so"),
#ifdef LDC_LLVM_LIBDIR
LDC_LLVM_LIBDIR "/LLVMgold.so",
#endif
#if __LP64__
"/usr/local/lib64/LLVMgold.so",
#endif
@ -162,6 +165,12 @@ std::string getLTOdylibPath() {
if (llvm::sys::fs::exists(searchPath))
return searchPath;
#ifdef LDC_LLVM_LIBDIR
searchPath = LDC_LLVM_LIBDIR "/libLTO.dylib";
if (llvm::sys::fs::exists(searchPath))
return searchPath;
#endif
return "";
}
}
@ -247,14 +256,21 @@ std::string getRelativeClangCompilerRTLibPath(const llvm::Twine &name,
void appendFullLibPathCandidates(std::vector<std::string> &paths,
const llvm::Twine &filename) {
llvm::SmallString<128> candidate;
for (const char *dir : ConfigFile::instance.libDirs()) {
llvm::SmallString<128> candidate(dir);
candidate = dir;
llvm::sys::path::append(candidate, filename);
paths.emplace_back(candidate.data(), candidate.size());
}
// for backwards compatibility
paths.push_back(exe_path::prependLibDir(filename));
#ifdef LDC_LLVM_LIBDIR
candidate = LDC_LLVM_LIBDIR;
llvm::sys::path::append(candidate, filename);
paths.emplace_back(candidate.data(), candidate.size());
#endif
}
// Returns candidates of full paths to a compiler-rt lib.