CMake: from LLVM 7, also copy xray-basic, xray-fdr, and xray-profiling clang runtime libraries.

This commit is contained in:
Johan Engelen 2019-01-17 01:22:17 +01:00
parent 070fd639b4
commit 82dccbab23
2 changed files with 57 additions and 21 deletions

View file

@ -61,6 +61,8 @@ private:
virtual void addCppStdlibLinkFlags(const llvm::Triple &triple);
virtual void addProfileRuntimeLinkFlags(const llvm::Triple &triple);
virtual void addXRayLinkFlags(const llvm::Triple &triple);
virtual bool addWholeRTLinkFlags(llvm::StringRef baseName,
const llvm::Triple &triple);
virtual void addLinker();
virtual void addUserSwitches();
@ -336,30 +338,49 @@ void ArgsBuilder::addFuzzLinkFlags(const llvm::Triple &triple) {
// Adds all required link flags for -fxray-instrument when the xray library is
// found.
void ArgsBuilder::addXRayLinkFlags(const llvm::Triple &triple) {
const auto searchPaths = getFullCompilerRTLibPathCandidates("xray", triple);
bool linkerDarwin = triple.isOSDarwin();
if (!triple.isOSLinux())
warning(Loc(), "XRay is not (fully) supported on non-Linux target OS.");
warning(Loc(), "XRay may not be fully supported on non-Linux target OS.");
for (const auto &filepath : searchPaths) {
if (!linkerDarwin)
addLdFlag("--whole-archive");
args.push_back(filepath);
if (!linkerDarwin)
addLdFlag("--no-whole-archive");
#if LDC_LLVM_VER < 700
// Before LLVM 7, XRay requires the C++ std library (but not on Darwin).
// Only link with the C++ stdlib when the XRay library was found.
if (!linkerDarwin)
addCppStdlibLinkFlags(triple);
#endif
return;
bool libraryFoundAndLinked = addWholeRTLinkFlags("xray", triple);
#if LDC_LLVM_VER >= 700
// Since LLVM 7, each XRay mode was split into its own library.
if (libraryFoundAndLinked) {
addWholeRTLinkFlags("xray-basic", triple);
addWholeRTLinkFlags("xray-fdr", triple);
}
#else
// Before LLVM 7, XRay requires the C++ std library (but not on Darwin).
// Only link with the C++ stdlib when the XRay library was found.
if (libraryFoundAndLinked && !triple.isOSDarwin())
addCppStdlibLinkFlags(triple);
#endif
}
// Returns true if library was found and added to link flags.
bool ArgsBuilder::addWholeRTLinkFlags(llvm::StringRef baseName,
const llvm::Triple &triple) {
const bool linkerDarwin = triple.isOSDarwin();
const auto searchPaths = getFullCompilerRTLibPathCandidates(baseName, triple);
for (const auto &filepath : searchPaths) {
IF_LOG Logger::println("Searching runtime library: %s", filepath.c_str());
if (llvm::sys::fs::exists(filepath) &&
!llvm::sys::fs::is_directory(filepath)) {
if (!linkerDarwin)
addLdFlag("--whole-archive");
IF_LOG Logger::println("Found, linking with %s",
filepath.c_str());
args.push_back(filepath);
if (!linkerDarwin)
addLdFlag("--no-whole-archive");
return true;
}
}
return false;
}
void ArgsBuilder::addCppStdlibLinkFlags(const llvm::Triple &triple) {