[lld] r205283 - [PECOFF] Treat .imp as an import library file.

Rui Ueyama ruiu at google.com
Mon Mar 31 23:11:09 PDT 2014


Author: ruiu
Date: Tue Apr  1 01:11:09 2014
New Revision: 205283

URL: http://llvm.org/viewvc/llvm-project?rev=205283&view=rev
Log:
[PECOFF] Treat .imp as an import library file.

Some Clang build uses .imp not .lib file extension for an import library file,
so we need to treat such file as a library file.

Ideally we should not rely on file extensions to detect file type. Instead
we should use magic bytes at beginning of a file. The GNU-compatible driver
actually does that but it made writing unit tests hard, so I chose an ad-hoc
approach for now.

Modified:
    lld/trunk/include/lld/Driver/WinLinkInputGraph.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkInputGraph.cpp

Modified: lld/trunk/include/lld/Driver/WinLinkInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkInputGraph.h?rev=205283&r1=205282&r2=205283&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkInputGraph.h Tue Apr  1 01:11:09 2014
@@ -24,6 +24,8 @@
 
 namespace lld {
 
+extern bool isCOFFLibraryFileExtension(StringRef path);
+
 /// \brief Represents a PECOFF File
 class PECOFFFileNode : public FileNode {
 public:

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=205283&r1=205282&r2=205283&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Apr  1 01:11:09 2014
@@ -1172,7 +1172,7 @@ bool WinLinkDriver::parse(int argc, cons
   // Prepare objects to add them to input graph.
   for (StringRef path : inputFiles) {
     path = ctx.allocate(path);
-    if (path.endswith_lower(".lib")) {
+    if (isCOFFLibraryFileExtension(path)) {
       libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
     } else {
       files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));

Modified: lld/trunk/lib/Driver/WinLinkInputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkInputGraph.cpp?rev=205283&r1=205282&r2=205283&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkInputGraph.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkInputGraph.cpp Tue Apr  1 01:11:09 2014
@@ -11,6 +11,10 @@
 
 namespace lld {
 
+bool isCOFFLibraryFileExtension(StringRef path) {
+  return path.endswith_lower(".lib") || path.endswith_lower(".imp");
+}
+
 /// \brief Parse the input file to lld::File.
 error_code PECOFFFileNode::parse(const LinkingContext &ctx,
                                  raw_ostream &diagnostics) {
@@ -38,7 +42,7 @@ ErrorOr<File &> PECOFFFileNode::getNextF
 }
 
 ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
-  if (_path.endswith_lower(".lib"))
+  if (isCOFFLibraryFileExtension(_path))
     return _ctx.searchLibraryFile(_path);
   if (llvm::sys::path::extension(_path).empty())
     return _ctx.allocate(_path.str() + ".obj");
@@ -46,7 +50,7 @@ ErrorOr<StringRef> PECOFFFileNode::getPa
 }
 
 ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
-  if (_path.endswith_lower(".lib"))
+  if (isCOFFLibraryFileExtension(_path))
     return _ctx.searchLibraryFile(_path);
   return _ctx.searchLibraryFile(_ctx.allocate(_path.str() + ".lib"));
 }





More information about the llvm-commits mailing list