[lld] r186645 - [PECOFF] Use library search path when looking for a .lib file.
Rui Ueyama
ruiu at google.com
Thu Jul 18 19:18:26 PDT 2013
Author: ruiu
Date: Thu Jul 18 21:18:25 2013
New Revision: 186645
URL: http://llvm.org/viewvc/llvm-project?rev=186645&view=rev
Log:
[PECOFF] Use library search path when looking for a .lib file.
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
lld/trunk/test/pecoff/importlib.test
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h?rev=186645&r1=186644&r2=186645&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h Thu Jul 18 21:18:25 2013
@@ -53,6 +53,9 @@ public:
return _inputSearchPaths;
}
+ bool appendInputFileOrLibrary(std::string path);
+ bool appendLibraryFile(StringRef path);
+
void setStackReserve(uint64_t size) { _stackReserve = size; }
void setStackCommit(uint64_t size) { _stackCommit = size; }
uint64_t getStackReserve() const { return _stackReserve; }
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=186645&r1=186644&r2=186645&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Jul 18 21:18:25 2013
@@ -167,13 +167,6 @@ bool parseSubsystemOption(PECOFFTargetIn
return true;
}
-// Add ".obj" extension if the given path name has no file extension.
-StringRef canonicalizeInputFileName(PECOFFTargetInfo &info, std::string path) {
- if (llvm::sys::path::extension(path).empty())
- path.append(".obj");
- return info.allocateString(path);
-}
-
// Replace a file extension with ".exe". If the given file has no
// extension, just add ".exe".
StringRef getDefaultOutputFileName(PECOFFTargetInfo &info, StringRef path) {
@@ -290,12 +283,12 @@ bool WinLinkDriver::parse(int argc, cons
for (int i = doubleDashPosition + 1; i < argc; ++i)
inputPaths.push_back(argv[i]);
- // Add ".obj" extension for those who have no file extension.
for (const StringRef &path : inputPaths)
- info.appendInputFile(canonicalizeInputFileName(info, path));
+ info.appendInputFileOrLibrary(path);
// If -out option was not specified, the default output file name is
- // constructed by replacing an extension with ".exe".
+ // constructed by replacing an extension of the first input file
+ // with ".exe".
if (info.outputPath().empty() && !inputPaths.empty())
info.setOutputPath(getDefaultOutputFileName(info, inputPaths[0]));
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp?rev=186645&r1=186644&r2=186645&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp Thu Jul 18 21:18:25 2013
@@ -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_
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;
}
Modified: lld/trunk/test/pecoff/importlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/importlib.test?rev=186645&r1=186644&r2=186645&view=diff
==============================================================================
--- lld/trunk/test/pecoff/importlib.test (original)
+++ lld/trunk/test/pecoff/importlib.test Thu Jul 18 21:18:25 2013
@@ -5,6 +5,9 @@
#
# RUN: lld -flavor link -out %t1 -subsystem console -- %t.obj \
# RUN: %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
+#
+# RUN: lld -flavor link -out %t1 -subsystem console -libpath %p/Inputs \
+# RUN: -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:
CHECK: .text:
More information about the llvm-commits
mailing list