summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-02-05 22:51:36 +0000
committerRui Ueyama <ruiu@google.com>2015-02-05 22:51:36 +0000
commitf038a525428dc14fa80fb92763b030b3402923ec (patch)
tree582530a16a768df75930c74ab44871351894ac24
parentb5d5bceefe2bd2bf56ef6b8a6bfd706198d00e79 (diff)
downloadbcm5719-llvm-f038a525428dc14fa80fb92763b030b3402923ec.tar.gz
bcm5719-llvm-f038a525428dc14fa80fb92763b030b3402923ec.zip
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 llvm-svn: 228352
-rw-r--r--lld/include/lld/Core/File.h23
-rw-r--r--lld/lib/ReaderWriter/FileArchive.cpp3
2 files changed, 21 insertions, 5 deletions
diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h
index e78b7279699..5792ccfd4d7 100644
--- a/lld/include/lld/Core/File.h
+++ b/lld/include/lld/Core/File.h
@@ -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;
diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp
index fe336aa4cea..888c13ec424 100644
--- a/lld/lib/ReaderWriter/FileArchive.cpp
+++ b/lld/lib/ReaderWriter/FileArchive.cpp
@@ -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.
OpenPOWER on IntegriCloud