diff options
| author | Rui Ueyama <ruiu@google.com> | 2013-07-19 02:18:25 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2013-07-19 02:18:25 +0000 |
| commit | 2897feb7e0cf167a5eef0b2f350c25d91cf9d06a (patch) | |
| tree | d599e614d645b11a03181bc29ebc9ccfdd303bc1 /lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp | |
| parent | 9f24922bd18a59d13282f26f2d4e6e6c7207a8e0 (diff) | |
| download | bcm5719-llvm-2897feb7e0cf167a5eef0b2f350c25d91cf9d06a.tar.gz bcm5719-llvm-2897feb7e0cf167a5eef0b2f350c25d91cf9d06a.zip | |
[PECOFF] Use library search path when looking for a .lib file.
llvm-svn: 186645
Diffstat (limited to 'lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp index 4b182346d8a..8c2352319ec 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp @@ -10,6 +10,8 @@ #include "GroupedSectionsPass.h" #include "IdataPass.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" #include "lld/Core/PassManager.h" #include "lld/Passes/LayoutPass.h" #include "lld/ReaderWriter/PECOFFTargetInfo.h" @@ -18,6 +20,14 @@ namespace lld { +namespace { +bool containDirectoryName(StringRef path) { + SmallString<128> smallStr = StringRef(path); + llvm::sys::path::remove_filename(smallStr); + return !smallStr.str().empty(); +} +} // anonymous namespace + error_code PECOFFTargetInfo::parseFile( std::unique_ptr<MemoryBuffer> &mb, std::vector<std::unique_ptr<File>> &result) const { @@ -44,6 +54,47 @@ bool PECOFFTargetInfo::validateImpl(raw_ostream &diagnostics) { return false; } +/// Append the given file to the input file list. The file must be an object +/// file or an import library file. +bool PECOFFTargetInfo::appendInputFileOrLibrary(std::string path) { + StringRef ext = llvm::sys::path::extension(path).lower(); + // This is an import library file. Look for the library file in the search + // paths, unless the path contains a directory name. + if (ext == ".lib") { + if (containDirectoryName(path)) { + appendInputFile(path); + return true; + } + return appendLibraryFile(path); + } + // This is an object file otherwise. Add ".obj" extension if the given path + // name has no file extension. + if (ext.empty()) + path.append(".obj"); + appendInputFile(allocateString(path)); + return true; +} + +/// Try to find the input library file from the search paths and append it to +/// the input file list. Returns true if the library file is found. +bool PECOFFTargetInfo::appendLibraryFile(StringRef filename) { + // Current directory always takes precedence over the search paths. + if (llvm::sys::fs::exists(filename)) { + appendInputFile(filename); + return true; + } + // Iterate over the search paths. + for (StringRef dir : _inputSearchPaths) { + SmallString<128> path = dir; + llvm::sys::path::append(path, filename); + if (llvm::sys::fs::exists(path.str())) { + appendInputFile(allocateString(path.str())); + return true; + } + } + return false; +} + Writer &PECOFFTargetInfo::writer() const { return *_writer; } |

