[lld] r224209 - [PECOFF] Resolve file name in the driver, not in InputElement.

Rui Ueyama ruiu at google.com
Sat Dec 13 18:50:31 PST 2014


Author: ruiu
Date: Sat Dec 13 20:50:29 2014
New Revision: 224209

URL: http://llvm.org/viewvc/llvm-project?rev=224209&view=rev
Log:
[PECOFF] Resolve file name in the driver, not in InputElement.

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=224209&r1=224208&r2=224209&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkInputGraph.h Sat Dec 13 20:50:29 2014
@@ -31,8 +31,6 @@ public:
   PECOFFFileNode(PECOFFLinkingContext &ctx, StringRef path)
       : FileNode(path), _ctx(ctx), _parsed(false) {}
 
-  ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
-
   /// \brief Parse the input file to lld::File.
   std::error_code parse(const LinkingContext &ctx,
                         raw_ostream &diagnostics) override;
@@ -49,8 +47,6 @@ class PECOFFLibraryNode : public PECOFFF
 public:
   PECOFFLibraryNode(PECOFFLinkingContext &ctx, StringRef path)
       : PECOFFFileNode(ctx, path) {}
-
-  ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
 };
 
 } // namespace lld

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=224209&r1=224208&r2=224209&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Sat Dec 13 20:50:29 2014
@@ -282,6 +282,25 @@ static bool parseManifest(StringRef opti
   return true;
 }
 
+StringRef getObjectPath(PECOFFLinkingContext &ctx, StringRef path) {
+  std::string result;
+  if (isCOFFLibraryFileExtension(path)) {
+    result =ctx.searchLibraryFile(path);
+  } else if (llvm::sys::path::extension(path).empty()) {
+    result = path.str() + ".obj";
+  } else {
+    result = path;
+  }
+  return ctx.allocate(result);
+}
+
+StringRef getLibraryPath(PECOFFLinkingContext &ctx, StringRef path) {
+  std::string result = isCOFFLibraryFileExtension(path)
+      ? ctx.searchLibraryFile(path)
+      : ctx.searchLibraryFile(path.str() + ".lib");
+  return ctx.allocate(result);
+}
+
 // Returns true if the given file is a Windows resource file.
 static bool isResoruceFile(StringRef path) {
   llvm::sys::fs::file_magic fileType;
@@ -1340,9 +1359,11 @@ bool WinLinkDriver::parse(int argc, cons
   for (StringRef path : inputFiles) {
     path = ctx.allocate(path);
     if (isCOFFLibraryFileExtension(path)) {
-      libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
+      libraries.push_back(std::unique_ptr<FileNode>(
+          new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path))));
     } else {
-      files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
+      files.push_back(std::unique_ptr<FileNode>(
+          new PECOFFFileNode(ctx, getObjectPath(ctx, path))));
     }
   }
 
@@ -1365,7 +1386,7 @@ bool WinLinkDriver::parse(int argc, cons
     for (const StringRef path : defaultLibs)
       if (!ctx.hasNoDefaultLib(path))
         libraries.push_back(std::unique_ptr<FileNode>(
-                              new PECOFFLibraryNode(ctx, ctx.allocate(path.lower()))));
+            new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path.lower()))));
 
   if (files.empty() && !isReadingDirectiveSection) {
     diag << "No input files\n";

Modified: lld/trunk/lib/Driver/WinLinkInputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkInputGraph.cpp?rev=224209&r1=224208&r2=224209&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkInputGraph.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkInputGraph.cpp Sat Dec 13 20:50:29 2014
@@ -40,18 +40,4 @@ std::error_code PECOFFFileNode::parse(co
   return ctx.registry().parseFile(std::move(mb.get()), _files);
 }
 
-ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
-  if (isCOFFLibraryFileExtension(_path))
-    return _ctx.searchLibraryFile(_path);
-  if (llvm::sys::path::extension(_path).empty())
-    return _ctx.allocate(_path.str() + ".obj");
-  return _path;
-}
-
-ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
-  if (isCOFFLibraryFileExtension(_path))
-    return _ctx.searchLibraryFile(_path);
-  return _ctx.searchLibraryFile(_ctx.allocate(_path.str() + ".lib"));
-}
-
 } // end anonymous namespace





More information about the llvm-commits mailing list