diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp index 4637a3b306da..b472f5c2b453 100644 --- a/ELF/Driver.cpp +++ b/ELF/Driver.cpp @@ -254,12 +254,8 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) { // file has a DT_SONAME or not because we haven't parsed it yet. // Here, we set the default soname for the file because we might // need it later. - // - // If a file was specified by -lfoo, the directory part is not - // significant, as a user did not specify it. This behavior is - // compatible with GNU. files.push_back( - make(mbref, withLOption ? path::filename(path) : path)); + make(mbref, path)); return; case file_magic::bitcode: case file_magic::elf_relocatable: diff --git a/ELF/DriverUtils.cpp b/ELF/DriverUtils.cpp index e33b07c0c9c9..e8d4e4f4497f 100644 --- a/ELF/DriverUtils.cpp +++ b/ELF/DriverUtils.cpp @@ -205,14 +205,16 @@ std::string elf::createResponseFile(const opt::InputArgList &args) { // Find a file by concatenating given paths. If a resulting path // starts with "=", the character is replaced with a --sysroot value. static Optional findFile(StringRef path1, const Twine &path2) { - SmallString<128> s; + SmallString<256> s; if (path1.startswith("=")) path::append(s, config->sysroot, path1.substr(1), path2); else path::append(s, path1, path2); - if (fs::exists(s)) - return std::string(s); + SmallString<256> RealPath; + fs::real_path(s, RealPath); + if (fs::exists(RealPath)) + return RealPath.str().str(); return None; } @@ -226,10 +228,22 @@ Optional elf::findFromSearchPaths(StringRef path) { // This is for -l. We'll look for lib.so or lib.a from // search paths. Optional elf::searchLibraryBaseName(StringRef name) { + for (StringRef dir : config->searchPaths) { if (!config->isStatic) - if (Optional s = findFile(dir, "lib" + name + ".so")) - return s; + if (name.size() == 1) { + if (Optional s = findFile(dir, "lib" + name + ".lib.so")) + return s; + if (Optional s = findFile(dir, "lib" + name + ".so")) + return s; + } else { + if (Optional s = findFile(dir, name + ".lib.so")) + return s; + if (Optional s = findFile(dir, "lib" + name + ".so")) + return s; + } + if (Optional s = findFile(dir, name + ".lib.a")) + return s; if (Optional s = findFile(dir, "lib" + name + ".a")) return s; }