diff options
author | Greg Steuck <gnezdo@cvs.openbsd.org> | 2022-03-04 16:46:24 +0000 |
---|---|---|
committer | Greg Steuck <gnezdo@cvs.openbsd.org> | 2022-03-04 16:46:24 +0000 |
commit | 93dfb9c84a51ff32677cdef21bc79b73c5ccc3e1 (patch) | |
tree | fa47f02f3292f2adcde2270c975798acd0d53d97 /gnu/llvm/lld | |
parent | 5db61140f844a379a7b1bcb5facf8f8141a4c027 (diff) |
Report versioned lib.so in cc --print-file-name given short name
E.g. `cc --print-file-name libc.so` reports /usr/lib/libc.so.96.1
This is a complement of the major.minor finding logic in DriverUtils.
`ld -lc -L/usr/lib` currently find the libraries with this logic.
To make things more obviously related the code was extracted into a
function which was copied over verbatim.
fine with mortimer@
ok patrick@
Diffstat (limited to 'gnu/llvm/lld')
-rw-r--r-- | gnu/llvm/lld/ELF/DriverUtils.cpp | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/gnu/llvm/lld/ELF/DriverUtils.cpp b/gnu/llvm/lld/ELF/DriverUtils.cpp index 6b164e30677..2fee8538913 100644 --- a/gnu/llvm/lld/ELF/DriverUtils.cpp +++ b/gnu/llvm/lld/ELF/DriverUtils.cpp @@ -230,6 +230,38 @@ Optional<std::string> elf::findFromSearchPaths(StringRef path) { return None; } +namespace { +// Must be in sync with findMajMinShlib in clang/lib/Driver/Driver.cpp. +llvm::Optional<std::string> findMajMinShlib(StringRef dir, const Twine& libNameSo) { + // Handle OpenBSD-style maj/min shlib scheme + llvm::SmallString<128> Scratch; + const StringRef LibName = (libNameSo + ".").toStringRef(Scratch); + int MaxMaj = -1, MaxMin = -1; + std::error_code EC; + for (llvm::sys::fs::directory_iterator LI(dir, EC), LE; + LI != LE; LI = LI.increment(EC)) { + StringRef FilePath = LI->path(); + StringRef FileName = llvm::sys::path::filename(FilePath); + if (!(FileName.startswith(LibName))) + continue; + std::pair<StringRef, StringRef> MajMin = + FileName.substr(LibName.size()).split('.'); + int Maj, Min; + if (MajMin.first.getAsInteger(10, Maj) || Maj < 0) + continue; + if (MajMin.second.getAsInteger(10, Min) || Min < 0) + continue; + if (Maj > MaxMaj) + MaxMaj = Maj, MaxMin = Min; + if (MaxMaj == Maj && Min > MaxMin) + MaxMin = Min; + } + if (MaxMaj >= 0) + return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin)); + return None; +} +} // namespace + // This is for -l<basename>. We'll look for lib<basename>.so or lib<basename>.a from // search paths. Optional<std::string> elf::searchLibraryBaseName(StringRef name) { @@ -237,32 +269,8 @@ Optional<std::string> elf::searchLibraryBaseName(StringRef name) { if (!config->isStatic) { if (Optional<std::string> s = findFile(dir, "lib" + name + ".so")) return s; - - // Handle OpenBSD-style maj/min shlib scheme - llvm::SmallString<128> Scratch; - const StringRef LibName = ("lib" + name + ".so.").toStringRef(Scratch); - int MaxMaj = -1, MaxMin = -1; - std::error_code EC; - for (fs::directory_iterator LI(dir, EC), LE; - LI != LE; LI = LI.increment(EC)) { - StringRef FilePath = LI->path(); - StringRef FileName = path::filename(FilePath); - if (!(FileName.startswith(LibName))) - continue; - std::pair<StringRef, StringRef> MajMin = - FileName.substr(LibName.size()).split('.'); - int Maj, Min; - if (MajMin.first.getAsInteger(10, Maj) || Maj < 0) - continue; - if (MajMin.second.getAsInteger(10, Min) || Min < 0) - continue; - if (Maj > MaxMaj) - MaxMaj = Maj, MaxMin = Min; - if (MaxMaj == Maj && Min > MaxMin) - MaxMin = Min; - } - if (MaxMaj >= 0) - return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin)); + if (Optional<std::string> s = findMajMinShlib(dir, "lib" + name + ".so")) + return s; } if (Optional<std::string> s = findFile(dir, "lib" + name + ".a")) return s; |