diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -84,6 +84,8 @@ // config->machine has been set. void addWinSysRootLibSearchPaths(); + void addClangLibSearchPaths(const std::string& argv0); + // Used by the resolver to parse .drectve section contents. void parseDirectives(InputFile *file); diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -465,8 +465,7 @@ return filename; }; - bool hasPathSep = (filename.find_first_of("/\\") != StringRef::npos); - if (hasPathSep) + if (sys::path::is_absolute(filename)) return getFilename(filename); bool hasExt = filename.contains('.'); for (StringRef dir : searchPaths) { @@ -620,6 +619,26 @@ } } +void LinkerDriver::addClangLibSearchPaths(const std::string& argv0) { + std::string lldBinary = sys::fs::getMainExecutable(argv0.c_str(), nullptr); + SmallString<128> binDir(lldBinary); + sys::path::remove_filename(binDir); // remove lld-link.exe + StringRef rootDir = sys::path::parent_path(binDir); // remove 'bin' + + SmallString<128> libDir(rootDir); + sys::path::append(libDir, "lib"); + + searchPaths.push_back(saver().save(std::string(libDir))); + + SmallString<128> runtimeLibDir(rootDir); + sys::path::append(runtimeLibDir, "lib", "clang", std::to_string(LLVM_VERSION_MAJOR), "lib"); + searchPaths.push_back(saver().save(std::string(runtimeLibDir))); + + SmallString<128> runtimeLibDirWithOS(runtimeLibDir); + sys::path::append(runtimeLibDirWithOS, "windows"); + searchPaths.push_back(saver().save(std::string(runtimeLibDirWithOS))); +} + void LinkerDriver::addWinSysRootLibSearchPaths() { if (!diaPath.empty()) { // The DIA SDK always uses the legacy vc arch, even in new MSVC versions. @@ -1525,6 +1544,8 @@ if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot)) addLibSearchPaths(); + addClangLibSearchPaths(argsArr[0]); + // Handle /ignore for (auto *arg : args.filtered(OPT_ignore)) { SmallVector vec; @@ -2042,7 +2063,7 @@ // Handle /RELEASE if (args.hasArg(OPT_release)) config->writeCheckSum = true; - + // Handle /safeseh, x86 only, on by default, except for mingw. if (config->machine == I386) { config->safeSEH = args.hasFlag(OPT_safeseh, OPT_safeseh_no, !config->mingw);