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>
readMembers(const object::Archive &Archive) {
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();
error(NameOrErr, "Archive::Child::getName failed");
V.emplace_back(C, *NameOrErr);
@ -570,7 +572,7 @@ public:
P += Sym.size() + 1;
memcpy(P, DLLName.data(), DLLName.size());
object::Archive::Child C(Parent, Buf);
object::Archive::Child C(Parent, Buf, nullptr);
return NewArchiveIterator(C, DLLName);
}

View File

@ -67,8 +67,11 @@ void ArchiveFile::parse() {
// Seen is a map from member files to boolean values. Initially
// all members are mapped to false, which indicates all these files
// 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();
}
}
// 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);
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();
error(MbOrErr, "Could not get the buffer for a child of the archive " +
File->getFileName());

View File

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