[lld] r228352 - Add methods to get archive file name from member file.

Rui Ueyama ruiu at google.com
Thu Feb 5 14:51:37 PST 2015


Author: ruiu
Date: Thu Feb  5 16:51:36 2015
New Revision: 228352

URL: http://llvm.org/viewvc/llvm-project?rev=228352&view=rev
Log:
Add methods to get archive file name from member file.

Previously we only have File::path() to get the path name of a file.
If a file was a member of an archive file, path() returns a concatenated
string of the file name in the archive and the archive file name.
If we wanted to get a file name or an archive file name, we had to
parse that string. That's of course not good.

This patch adds new member functions, archivePath and memberPath, to File.

http://reviews.llvm.org/D7447

Modified:
    lld/trunk/include/lld/Core/File.h
    lld/trunk/lib/ReaderWriter/FileArchive.cpp

Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=228352&r1=228351&r2=228352&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Thu Feb  5 16:51:36 2015
@@ -55,12 +55,25 @@ public:
     return _kind;
   }
 
-  /// \brief For error messages and debugging, this returns the path to the file
-  /// which was used to create this object (e.g. "/tmp/foo.o").
-  StringRef path() const  {
-    return _path;
+  /// This returns the path to the file which was used to create this object
+  /// (e.g. "/tmp/foo.o"). If the file is a member of an archive file, the
+  /// returned string includes the archive file name.
+  StringRef path() const {
+    if (_archivePath.empty())
+      return _path;
+    if (_archiveMemberPath.empty())
+      _archiveMemberPath = (_archivePath + "(" + _path + ")").str();
+    return _archiveMemberPath;
   }
 
+  /// Returns the path of the archive file name if this file is instantiated
+  /// from an archive file. Otherwise returns the empty string.
+  StringRef archivePath() const { return _archivePath; }
+  void setArchivePath(StringRef path) { _archivePath = path; }
+
+  /// Returns the path name of this file. It doesn't include archive file name.
+  StringRef memberPath() const { return _path; }
+
   /// Returns the command line order of the file.
   uint64_t ordinal() const {
     assert(_ordinal != UINT64_MAX);
@@ -248,6 +261,8 @@ protected:
 
 private:
   StringRef _path;
+  std::string _archivePath;
+  mutable std::string _archiveMemberPath;
   Kind              _kind;
   mutable uint64_t  _ordinal;
   std::shared_ptr<MemoryBuffer> _sharedMemoryBuffer;

Modified: lld/trunk/lib/ReaderWriter/FileArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/FileArchive.cpp?rev=228352&r1=228351&r2=228352&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/FileArchive.cpp (original)
+++ lld/trunk/lib/ReaderWriter/FileArchive.cpp Thu Feb  5 16:51:36 2015
@@ -196,7 +196,7 @@ private:
       llvm::errs() << memberPath << "\n";
 
     std::unique_ptr<MemoryBuffer> memberMB(MemoryBuffer::getMemBuffer(
-        mb.getBuffer(), memberPath, false));
+        mb.getBuffer(), mb.getBufferIdentifier(), false));
 
     std::vector<std::unique_ptr<File>> files;
     if (std::error_code ec = _registry.loadFile(std::move(memberMB), files))
@@ -205,6 +205,7 @@ private:
     result = std::move(files[0]);
     if (std::error_code ec = result->parse())
       return ec;
+    result->setArchivePath(_archive->getFileName());
 
     // The memory buffer is co-owned by the archive file and the children,
     // so that the bufffer is deallocated when all the members are destructed.





More information about the llvm-commits mailing list