mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 09:00:33 +03:00
Extend search logic for finding compiler RT libs. (ASan and libFuzzer) (#2345)
This should help find the compilerRT libs when LDC is installed in the system's usual dirs. With this change, the ASan and libFuzzer libs do not necessarily need to be copied as part of building LDC.
This commit is contained in:
parent
8e0e688f5b
commit
94c0d18d49
1 changed files with 37 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "driver/cl_options_instrumentation.h"
|
||||
#include "driver/cl_options_sanitizers.h"
|
||||
#include "driver/exe_path.h"
|
||||
#include "driver/ldc-version.h"
|
||||
#include "driver/tool.h"
|
||||
#include "gen/irstate.h"
|
||||
#include "gen/logger.h"
|
||||
|
@ -205,6 +206,36 @@ std::string getFullCompilerRTLibPath(const llvm::Triple &triple,
|
|||
}
|
||||
}
|
||||
|
||||
// Clang's RT libs are in a subdir of the lib dir.
|
||||
// Returns the libname as full path and with arch suffix and extension.
|
||||
// For example, with name="libclang_rt.asan" and sharedLibrary=true, the
|
||||
// returned string is
|
||||
// "clang/6.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib" on Darwin.
|
||||
// This function is "best effort", the path may not be what Clang does...
|
||||
// See clang/lib/Driver/Toolchain.cpp.
|
||||
std::string getFullClangCompilerRTLibPath(const llvm::Triple &triple,
|
||||
llvm::StringRef name,
|
||||
bool sharedLibrary = false) {
|
||||
llvm::StringRef OSName =
|
||||
triple.isOSDarwin()
|
||||
? "darwin"
|
||||
: triple.isOSFreeBSD() ? "freebsd" : triple.getOSName();
|
||||
|
||||
std::string relPath = (llvm::Twine("clang/") + ldc::llvm_version_base +
|
||||
"/lib/" + OSName + "/" + name)
|
||||
.str();
|
||||
|
||||
if (triple.isOSDarwin()) {
|
||||
return exe_path::prependLibDir(
|
||||
llvm::Twine(relPath) +
|
||||
(sharedLibrary ? "_osx_dynamic.dylib" : "_osx.a"));
|
||||
} else {
|
||||
return exe_path::prependLibDir(llvm::Twine(relPath) + "-" +
|
||||
getCompilerRTArchName(triple) +
|
||||
(sharedLibrary ? ".so" : ".a"));
|
||||
}
|
||||
}
|
||||
|
||||
void ArgsBuilder::addASanLinkFlags(const llvm::Triple &triple) {
|
||||
// Examples: "libclang_rt.asan-x86_64.a" or "libclang_rt.asan-arm.a" and
|
||||
// "libclang_rt.asan-x86_64.so"
|
||||
|
@ -217,12 +248,14 @@ void ArgsBuilder::addASanLinkFlags(const llvm::Triple &triple) {
|
|||
std::string searchPaths[] = {
|
||||
getFullCompilerRTLibPath(triple, "libldc_rt.asan", linkSharedASan),
|
||||
getFullCompilerRTLibPath(triple, "libclang_rt.asan", linkSharedASan),
|
||||
getFullClangCompilerRTLibPath(triple, "libclang_rt.asan", linkSharedASan),
|
||||
};
|
||||
|
||||
for (const auto &filepath : searchPaths) {
|
||||
IF_LOG Logger::println("Searching ASan lib: %s", filepath.c_str());
|
||||
|
||||
if (llvm::sys::fs::exists(filepath)) {
|
||||
if (llvm::sys::fs::exists(filepath) &&
|
||||
!llvm::sys::fs::is_directory(filepath)) {
|
||||
IF_LOG Logger::println("Found, linking with %s", filepath.c_str());
|
||||
args.push_back(filepath);
|
||||
|
||||
|
@ -256,6 +289,7 @@ void ArgsBuilder::addFuzzLinkFlags(const llvm::Triple &triple) {
|
|||
#if LDC_LLVM_VER >= 600
|
||||
getFullCompilerRTLibPath(triple, "libldc_rt.fuzzer"),
|
||||
getFullCompilerRTLibPath(triple, "libclang_rt.fuzzer"),
|
||||
getFullClangCompilerRTLibPath(triple, "libclang_rt.fuzzer"),
|
||||
#else
|
||||
exe_path::prependLibDir("libFuzzer.a"),
|
||||
exe_path::prependLibDir("libLLVMFuzzer.a"),
|
||||
|
@ -265,7 +299,8 @@ void ArgsBuilder::addFuzzLinkFlags(const llvm::Triple &triple) {
|
|||
for (const auto &filepath : searchPaths) {
|
||||
IF_LOG Logger::println("Searching libFuzzer: %s", filepath.c_str());
|
||||
|
||||
if (llvm::sys::fs::exists(filepath)) {
|
||||
if (llvm::sys::fs::exists(filepath) &&
|
||||
!llvm::sys::fs::is_directory(filepath)) {
|
||||
IF_LOG Logger::println("Found, linking with %s", filepath.c_str());
|
||||
args.push_back(filepath);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue