Index: include/lld/Core/File.h =================================================================== --- include/lld/Core/File.h +++ include/lld/Core/File.h @@ -55,12 +55,24 @@ 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; + return *new (_allocator) std::string( + (_archivePath + "(" + _path + ")").str()); } + /// Returns the path of the archive file name if this file is instantiated + /// from an archive file. Otehrwise 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 +260,7 @@ private: StringRef _path; + std::string _archivePath; Kind _kind; mutable uint64_t _ordinal; std::shared_ptr _sharedMemoryBuffer; Index: lib/ReaderWriter/FileArchive.cpp =================================================================== --- lib/ReaderWriter/FileArchive.cpp +++ lib/ReaderWriter/FileArchive.cpp @@ -196,7 +196,7 @@ llvm::errs() << memberPath << "\n"; std::unique_ptr memberMB(MemoryBuffer::getMemBuffer( - mb.getBuffer(), memberPath, false)); + mb.getBuffer(), mb.getBufferIdentifier(), false)); std::vector> files; if (std::error_code ec = _registry.loadFile(std::move(memberMB), files)) @@ -205,6 +205,7 @@ 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.