1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Clean up of libObject/Archive interfaces and change the last three uses of ErrorOr<>

changing them to Expected<> to allow them to pass through llvm Errors.
No functional change.

This commit by itself will break the next lld builds.  I’ll be committing the
matching change for lld immediately next.

llvm-svn: 277656
This commit is contained in:
Kevin Enderby 2016-08-03 21:57:47 +00:00
parent d5e7d1acab
commit 83d2e01ea8
4 changed files with 87 additions and 50 deletions

View File

@ -19,7 +19,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@ -100,7 +100,7 @@ public:
Expected<Child> getNext() const;
Expected<StringRef> getName() const;
ErrorOr<std::string> getFullName() const;
Expected<std::string> getFullName() const;
Expected<StringRef> getRawName() const { return Header.getRawName(); }
Expected<sys::TimeValue> getLastModified() const {
return Header.getLastModified();
@ -118,7 +118,7 @@ public:
/// \return the size in the archive header for this member.
Expected<uint64_t> getRawSize() const;
ErrorOr<StringRef> getBuffer() const;
Expected<StringRef> getBuffer() const;
uint64_t getChildOffset() const;
Expected<MemoryBufferRef> getMemoryBufferRef() const;
@ -179,7 +179,7 @@ public:
, SymbolIndex(symi)
, StringIndex(stri) {}
StringRef getName() const;
ErrorOr<Child> getMember() const;
Expected<Child> getMember() const;
Symbol getNext() const;
};

View File

@ -389,14 +389,14 @@ Expected<bool> Archive::Child::isThinMember() const {
return Parent->IsThin && Name != "/" && Name != "//";
}
ErrorOr<std::string> Archive::Child::getFullName() const {
Expected<std::string> Archive::Child::getFullName() const {
Expected<bool> isThin = isThinMember();
if (!isThin)
return errorToErrorCode(isThin.takeError());
return isThin.takeError();
assert(isThin.get());
Expected<StringRef> NameOrErr = getName();
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
return NameOrErr.takeError();
StringRef Name = *NameOrErr;
if (sys::path::is_absolute(Name))
return Name;
@ -407,24 +407,24 @@ ErrorOr<std::string> Archive::Child::getFullName() const {
return StringRef(FullName);
}
ErrorOr<StringRef> Archive::Child::getBuffer() const {
Expected<StringRef> Archive::Child::getBuffer() const {
Expected<bool> isThinOrErr = isThinMember();
if (!isThinOrErr)
return errorToErrorCode(isThinOrErr.takeError());
return isThinOrErr.takeError();
bool isThin = isThinOrErr.get();
if (!isThin) {
Expected<uint32_t> Size = getSize();
if (!Size)
return errorToErrorCode(Size.takeError());
return Size.takeError();
return StringRef(Data.data() + StartOfFile, Size.get());
}
ErrorOr<std::string> FullNameOrEr = getFullName();
if (std::error_code EC = FullNameOrEr.getError())
return EC;
const std::string &FullName = *FullNameOrEr;
Expected<std::string> FullNameOrErr = getFullName();
if (!FullNameOrErr)
return FullNameOrErr.takeError();
const std::string &FullName = *FullNameOrErr;
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(FullName);
if (std::error_code EC = Buf.getError())
return EC;
return errorCodeToError(EC);
Parent->ThinBuffers.push_back(std::move(*Buf));
return Parent->ThinBuffers.back()->getBuffer();
}
@ -485,9 +485,9 @@ Expected<MemoryBufferRef> Archive::Child::getMemoryBufferRef() const {
if (!NameOrErr)
return NameOrErr.takeError();
StringRef Name = NameOrErr.get();
ErrorOr<StringRef> Buf = getBuffer();
if (std::error_code EC = Buf.getError())
return errorCodeToError(EC);
Expected<StringRef> Buf = getBuffer();
if (!Buf)
return Buf.takeError();
return MemoryBufferRef(*Buf, Name);
}
@ -590,9 +590,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
Format = K_BSD;
else // Name == "__.SYMDEF_64"
Format = K_DARWIN64;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *C->getBuffer();
// We know that the symbol table is not an external file, but we still must
// check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
SymbolTable = BufOrErr.get();
if (Increment())
return;
setFirstRegular(*C);
@ -611,17 +616,27 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
}
Name = NameOrErr.get();
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
// We know that the symbol table is not an external file, so we just
// assert there is no error.
SymbolTable = *C->getBuffer();
// We know that the symbol table is not an external file, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
SymbolTable = BufOrErr.get();
if (Increment())
return;
}
else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
Format = K_DARWIN64;
// We know that the symbol table is not an external file, so we just
// assert there is no error.
SymbolTable = *C->getBuffer();
// We know that the symbol table is not an external file, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
SymbolTable = BufOrErr.get();
if (Increment())
return;
}
@ -636,9 +651,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
bool has64SymTable = false;
if (Name == "/" || Name == "/SYM64/") {
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *C->getBuffer();
// We know that the symbol table is not an external file, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
SymbolTable = BufOrErr.get();
if (Name == "/SYM64/")
has64SymTable = true;
@ -658,9 +678,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
if (Name == "//") {
Format = has64SymTable ? K_MIPS64 : K_GNU;
// The string table is never an external member, so we just assert on the
// ErrorOr.
StringTable = *C->getBuffer();
// The string table is never an external member, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
StringTable = BufOrErr.get();
if (Increment())
return;
setFirstRegular(*C);
@ -681,9 +706,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
}
Format = K_COFF;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *C->getBuffer();
// We know that the symbol table is not an external file, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
SymbolTable = BufOrErr.get();
if (Increment())
return;
@ -702,9 +732,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
Name = NameOrErr.get();
if (Name == "//") {
// The string table is never an external member, so we just assert on the
// ErrorOr.
StringTable = *C->getBuffer();
// The string table is never an external member, but we still
// must check any Expected<> return value.
Expected<StringRef> BufOrErr = C->getBuffer();
if (!BufOrErr) {
Err = BufOrErr.takeError();
return;
}
StringTable = BufOrErr.get();
if (Increment())
return;
}
@ -738,7 +773,7 @@ StringRef Archive::Symbol::getName() const {
return Parent->getSymbolTable().begin() + StringIndex;
}
ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
Expected<Archive::Child> Archive::Symbol::getMember() const {
const char *Buf = Parent->getSymbolTable().begin();
const char *Offsets = Buf;
if (Parent->kind() == K_MIPS64 || Parent->kind() == K_DARWIN64)
@ -773,7 +808,7 @@ ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
uint32_t SymbolCount = read32le(Buf);
if (SymbolIndex >= SymbolCount)
return object_error::parse_failed;
return errorCodeToError(object_error::parse_failed);
// Skip SymbolCount to get to the indices table.
const char *Indices = Buf + 4;
@ -785,7 +820,7 @@ ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
--OffsetIndex;
if (OffsetIndex >= MemberCount)
return object_error::parse_failed;
return errorCodeToError(object_error::parse_failed);
Offset = read32le(Offsets + OffsetIndex * 4);
}
@ -794,7 +829,7 @@ ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
Error Err;
Child C(Parent, Loc, &Err);
if (Err)
return errorToErrorCode(std::move(Err));
return std::move(Err);
return C;
}
@ -925,7 +960,7 @@ Expected<Optional<Archive::Child>> Archive::findSym(StringRef name) const {
if (auto MemberOrErr = bs->getMember())
return Child(*MemberOrErr);
else
return errorCodeToError(MemberOrErr.getError());
return MemberOrErr.takeError();
}
}
return Optional<Child>();

View File

@ -318,8 +318,8 @@ static void doPrint(StringRef Name, const object::Archive::Child &C) {
if (Verbose)
outs() << "Printing " << Name << "\n";
ErrorOr<StringRef> DataOrErr = C.getBuffer();
failIfError(DataOrErr.getError());
Expected<StringRef> DataOrErr = C.getBuffer();
failIfError(DataOrErr.takeError());
StringRef Data = *DataOrErr;
outs().write(Data.data(), Data.size());
}
@ -376,7 +376,9 @@ static void doExtract(StringRef Name, const object::Archive::Child &C) {
raw_fd_ostream file(FD, false);
// Get the data and its length
StringRef Data = *C.getBuffer();
Expected<StringRef> BufOrErr = C.getBuffer();
failIfError(BufOrErr.takeError());
StringRef Data = BufOrErr.get();
// Write the data.
file.write(Data.data(), Data.size());

View File

@ -1097,9 +1097,9 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
if (I != E) {
outs() << "Archive map\n";
for (; I != E; ++I) {
ErrorOr<Archive::Child> C = I->getMember();
if (error(C.getError()))
return;
Expected<Archive::Child> C = I->getMember();
if (!C)
error(C.takeError(), Filename);
Expected<StringRef> FileNameOrErr = C->getName();
if (!FileNameOrErr) {
error(FileNameOrErr.takeError(), Filename);