These are the matching changes needed to the lld project for the changes to llvm

in r252192 that changed the Archive and Child interfaces in libObject. These include
Rafael Espindola’s many suggested updates.

llvm-svn: 252193
This commit is contained in:
Kevin Enderby 2015-11-05 19:25:47 +00:00
parent 7a96942a6a
commit 35dfc95efe
4 changed files with 34 additions and 16 deletions

View File

@ -521,7 +521,9 @@ static std::unique_ptr<MemoryBuffer> createEmptyImportLibrary() {
static std::vector<NewArchiveIterator> static std::vector<NewArchiveIterator>
readMembers(const object::Archive &Archive) { readMembers(const object::Archive &Archive) {
std::vector<NewArchiveIterator> V; std::vector<NewArchiveIterator> V;
for (const object::Archive::Child &C : Archive.children()) { for (const auto &ChildOrErr : Archive.children()) {
error(ChildOrErr, "Archive::Child::getName failed");
const object::Archive::Child C(*ChildOrErr);
ErrorOr<StringRef> NameOrErr = C.getName(); ErrorOr<StringRef> NameOrErr = C.getName();
error(NameOrErr, "Archive::Child::getName failed"); error(NameOrErr, "Archive::Child::getName failed");
V.emplace_back(C, *NameOrErr); V.emplace_back(C, *NameOrErr);
@ -570,7 +572,7 @@ public:
P += Sym.size() + 1; P += Sym.size() + 1;
memcpy(P, DLLName.data(), DLLName.size()); memcpy(P, DLLName.data(), DLLName.size());
object::Archive::Child C(Parent, Buf); object::Archive::Child C(Parent, Buf, nullptr);
return NewArchiveIterator(C, DLLName); return NewArchiveIterator(C, DLLName);
} }

View File

@ -67,8 +67,11 @@ void ArchiveFile::parse() {
// Seen is a map from member files to boolean values. Initially // Seen is a map from member files to boolean values. Initially
// all members are mapped to false, which indicates all these files // all members are mapped to false, which indicates all these files
// are not read yet. // are not read yet.
for (const Archive::Child &Child : File->children()) for (auto &ChildOrErr : File->children()) {
error(ChildOrErr, "Failed to parse static library");
const Archive::Child &Child = *ChildOrErr;
Seen[Child.getChildOffset()].clear(); Seen[Child.getChildOffset()].clear();
}
} }
// Returns a buffer pointing to a member file containing a given symbol. // Returns a buffer pointing to a member file containing a given symbol.

View File

@ -308,7 +308,10 @@ std::vector<MemoryBufferRef> ArchiveFile::getMembers() {
File = openArchive(MB); File = openArchive(MB);
std::vector<MemoryBufferRef> Result; std::vector<MemoryBufferRef> Result;
for (const Archive::Child &Child : File->children()) { for (auto &ChildOrErr : File->children()) {
error(ChildOrErr,
"Could not get the child of the archive " + File->getFileName());
const Archive::Child Child(*ChildOrErr);
ErrorOr<MemoryBufferRef> MbOrErr = Child.getMemoryBufferRef(); ErrorOr<MemoryBufferRef> MbOrErr = Child.getMemoryBufferRef();
error(MbOrErr, "Could not get the buffer for a child of the archive " + error(MbOrErr, "Could not get the buffer for a child of the archive " +
File->getFileName()); File->getFileName());

View File

@ -49,9 +49,11 @@ public:
if (member == _symbolMemberMap.end()) if (member == _symbolMemberMap.end())
return nullptr; return nullptr;
Archive::child_iterator ci = member->second; Archive::child_iterator ci = member->second;
if (ci->getError())
return nullptr;
// Don't return a member already returned // Don't return a member already returned
ErrorOr<StringRef> buf = ci->getBuffer(); ErrorOr<StringRef> buf = (*ci)->getBuffer();
if (!buf) if (!buf)
return nullptr; return nullptr;
const char *memberStart = buf->data(); const char *memberStart = buf->data();
@ -90,9 +92,11 @@ public:
if (member == _symbolMemberMap.end()) if (member == _symbolMemberMap.end())
return; return;
Archive::child_iterator ci = member->second; Archive::child_iterator ci = member->second;
if (ci->getError())
return;
// Do nothing if a member is already instantiated. // Do nothing if a member is already instantiated.
ErrorOr<StringRef> buf = ci->getBuffer(); ErrorOr<StringRef> buf = (*ci)->getBuffer();
if (!buf) if (!buf)
return; return;
const char *memberStart = buf->data(); const char *memberStart = buf->data();
@ -167,10 +171,12 @@ protected:
} }
private: private:
std::error_code std::error_code instantiateMember(Archive::child_iterator cOrErr,
instantiateMember(Archive::child_iterator member, std::unique_ptr<File> &result) const {
std::unique_ptr<File> &result) const { if (std::error_code ec = cOrErr->getError())
ErrorOr<llvm::MemoryBufferRef> mbOrErr = member->getMemoryBufferRef(); return ec;
Archive::child_iterator member = cOrErr->get();
ErrorOr<llvm::MemoryBufferRef> mbOrErr = (*member)->getMemoryBufferRef();
if (std::error_code ec = mbOrErr.getError()) if (std::error_code ec = mbOrErr.getError())
return ec; return ec;
llvm::MemoryBufferRef mb = mbOrErr.get(); llvm::MemoryBufferRef mb = mbOrErr.get();
@ -201,8 +207,11 @@ private:
// Parses the given memory buffer as an object file, and returns true // Parses the given memory buffer as an object file, and returns true
// code if the given symbol is a data symbol. If the symbol is not a data // code if the given symbol is a data symbol. If the symbol is not a data
// symbol or does not exist, returns false. // symbol or does not exist, returns false.
bool isDataSymbol(Archive::child_iterator member, StringRef symbol) const { bool isDataSymbol(Archive::child_iterator cOrErr, StringRef symbol) const {
ErrorOr<llvm::MemoryBufferRef> buf = member->getMemoryBufferRef(); if (cOrErr->getError())
return false;
Archive::child_iterator member = cOrErr->get();
ErrorOr<llvm::MemoryBufferRef> buf = (*member)->getMemoryBufferRef();
if (buf.getError()) if (buf.getError())
return false; return false;
std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer( std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer(
@ -242,10 +251,11 @@ private:
if (std::error_code ec = memberOrErr.getError()) if (std::error_code ec = memberOrErr.getError())
return ec; return ec;
Archive::child_iterator member = memberOrErr.get(); Archive::child_iterator member = memberOrErr.get();
DEBUG_WITH_TYPE( DEBUG_WITH_TYPE("FileArchive",
"FileArchive", llvm::dbgs()
llvm::dbgs() << llvm::format("0x%08llX ", member->getBuffer()->data()) << llvm::format("0x%08llX ",
<< "'" << name << "'\n"); (*member)->getBuffer()->data())
<< "'" << name << "'\n");
_symbolMemberMap.insert(std::make_pair(name, member)); _symbolMemberMap.insert(std::make_pair(name, member));
} }
return std::error_code(); return std::error_code();