mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-06 23:31:48 +00: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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277656 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dfe91b47a8
commit
b48816b9fc
@ -19,7 +19,7 @@
|
|||||||
#include "llvm/ADT/iterator_range.h"
|
#include "llvm/ADT/iterator_range.h"
|
||||||
#include "llvm/Object/Binary.h"
|
#include "llvm/Object/Binary.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/ErrorOr.h"
|
#include "llvm/Support/Error.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public:
|
|||||||
Expected<Child> getNext() const;
|
Expected<Child> getNext() const;
|
||||||
|
|
||||||
Expected<StringRef> getName() const;
|
Expected<StringRef> getName() const;
|
||||||
ErrorOr<std::string> getFullName() const;
|
Expected<std::string> getFullName() const;
|
||||||
Expected<StringRef> getRawName() const { return Header.getRawName(); }
|
Expected<StringRef> getRawName() const { return Header.getRawName(); }
|
||||||
Expected<sys::TimeValue> getLastModified() const {
|
Expected<sys::TimeValue> getLastModified() const {
|
||||||
return Header.getLastModified();
|
return Header.getLastModified();
|
||||||
@ -118,7 +118,7 @@ public:
|
|||||||
/// \return the size in the archive header for this member.
|
/// \return the size in the archive header for this member.
|
||||||
Expected<uint64_t> getRawSize() const;
|
Expected<uint64_t> getRawSize() const;
|
||||||
|
|
||||||
ErrorOr<StringRef> getBuffer() const;
|
Expected<StringRef> getBuffer() const;
|
||||||
uint64_t getChildOffset() const;
|
uint64_t getChildOffset() const;
|
||||||
|
|
||||||
Expected<MemoryBufferRef> getMemoryBufferRef() const;
|
Expected<MemoryBufferRef> getMemoryBufferRef() const;
|
||||||
@ -179,7 +179,7 @@ public:
|
|||||||
, SymbolIndex(symi)
|
, SymbolIndex(symi)
|
||||||
, StringIndex(stri) {}
|
, StringIndex(stri) {}
|
||||||
StringRef getName() const;
|
StringRef getName() const;
|
||||||
ErrorOr<Child> getMember() const;
|
Expected<Child> getMember() const;
|
||||||
Symbol getNext() const;
|
Symbol getNext() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -389,14 +389,14 @@ Expected<bool> Archive::Child::isThinMember() const {
|
|||||||
return Parent->IsThin && Name != "/" && Name != "//";
|
return Parent->IsThin && Name != "/" && Name != "//";
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<std::string> Archive::Child::getFullName() const {
|
Expected<std::string> Archive::Child::getFullName() const {
|
||||||
Expected<bool> isThin = isThinMember();
|
Expected<bool> isThin = isThinMember();
|
||||||
if (!isThin)
|
if (!isThin)
|
||||||
return errorToErrorCode(isThin.takeError());
|
return isThin.takeError();
|
||||||
assert(isThin.get());
|
assert(isThin.get());
|
||||||
Expected<StringRef> NameOrErr = getName();
|
Expected<StringRef> NameOrErr = getName();
|
||||||
if (!NameOrErr)
|
if (!NameOrErr)
|
||||||
return errorToErrorCode(NameOrErr.takeError());
|
return NameOrErr.takeError();
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
if (sys::path::is_absolute(Name))
|
if (sys::path::is_absolute(Name))
|
||||||
return Name;
|
return Name;
|
||||||
@ -407,24 +407,24 @@ ErrorOr<std::string> Archive::Child::getFullName() const {
|
|||||||
return StringRef(FullName);
|
return StringRef(FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> Archive::Child::getBuffer() const {
|
Expected<StringRef> Archive::Child::getBuffer() const {
|
||||||
Expected<bool> isThinOrErr = isThinMember();
|
Expected<bool> isThinOrErr = isThinMember();
|
||||||
if (!isThinOrErr)
|
if (!isThinOrErr)
|
||||||
return errorToErrorCode(isThinOrErr.takeError());
|
return isThinOrErr.takeError();
|
||||||
bool isThin = isThinOrErr.get();
|
bool isThin = isThinOrErr.get();
|
||||||
if (!isThin) {
|
if (!isThin) {
|
||||||
Expected<uint32_t> Size = getSize();
|
Expected<uint32_t> Size = getSize();
|
||||||
if (!Size)
|
if (!Size)
|
||||||
return errorToErrorCode(Size.takeError());
|
return Size.takeError();
|
||||||
return StringRef(Data.data() + StartOfFile, Size.get());
|
return StringRef(Data.data() + StartOfFile, Size.get());
|
||||||
}
|
}
|
||||||
ErrorOr<std::string> FullNameOrEr = getFullName();
|
Expected<std::string> FullNameOrErr = getFullName();
|
||||||
if (std::error_code EC = FullNameOrEr.getError())
|
if (!FullNameOrErr)
|
||||||
return EC;
|
return FullNameOrErr.takeError();
|
||||||
const std::string &FullName = *FullNameOrEr;
|
const std::string &FullName = *FullNameOrErr;
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(FullName);
|
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(FullName);
|
||||||
if (std::error_code EC = Buf.getError())
|
if (std::error_code EC = Buf.getError())
|
||||||
return EC;
|
return errorCodeToError(EC);
|
||||||
Parent->ThinBuffers.push_back(std::move(*Buf));
|
Parent->ThinBuffers.push_back(std::move(*Buf));
|
||||||
return Parent->ThinBuffers.back()->getBuffer();
|
return Parent->ThinBuffers.back()->getBuffer();
|
||||||
}
|
}
|
||||||
@ -485,9 +485,9 @@ Expected<MemoryBufferRef> Archive::Child::getMemoryBufferRef() const {
|
|||||||
if (!NameOrErr)
|
if (!NameOrErr)
|
||||||
return NameOrErr.takeError();
|
return NameOrErr.takeError();
|
||||||
StringRef Name = NameOrErr.get();
|
StringRef Name = NameOrErr.get();
|
||||||
ErrorOr<StringRef> Buf = getBuffer();
|
Expected<StringRef> Buf = getBuffer();
|
||||||
if (std::error_code EC = Buf.getError())
|
if (!Buf)
|
||||||
return errorCodeToError(EC);
|
return Buf.takeError();
|
||||||
return MemoryBufferRef(*Buf, Name);
|
return MemoryBufferRef(*Buf, Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,9 +590,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
Format = K_BSD;
|
Format = K_BSD;
|
||||||
else // Name == "__.SYMDEF_64"
|
else // Name == "__.SYMDEF_64"
|
||||||
Format = K_DARWIN64;
|
Format = K_DARWIN64;
|
||||||
// We know that the symbol table is not an external file, so we just assert
|
// We know that the symbol table is not an external file, but we still must
|
||||||
// there is no error.
|
// check any Expected<> return value.
|
||||||
SymbolTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolTable = BufOrErr.get();
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
setFirstRegular(*C);
|
setFirstRegular(*C);
|
||||||
@ -611,17 +616,27 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
}
|
}
|
||||||
Name = NameOrErr.get();
|
Name = NameOrErr.get();
|
||||||
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
|
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
|
||||||
// We know that the symbol table is not an external file, so we just
|
// We know that the symbol table is not an external file, but we still
|
||||||
// assert there is no error.
|
// must check any Expected<> return value.
|
||||||
SymbolTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolTable = BufOrErr.get();
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
|
else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
|
||||||
Format = K_DARWIN64;
|
Format = K_DARWIN64;
|
||||||
// We know that the symbol table is not an external file, so we just
|
// We know that the symbol table is not an external file, but we still
|
||||||
// assert there is no error.
|
// must check any Expected<> return value.
|
||||||
SymbolTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolTable = BufOrErr.get();
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -636,9 +651,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
|
|
||||||
bool has64SymTable = false;
|
bool has64SymTable = false;
|
||||||
if (Name == "/" || Name == "/SYM64/") {
|
if (Name == "/" || Name == "/SYM64/") {
|
||||||
// We know that the symbol table is not an external file, so we just assert
|
// We know that the symbol table is not an external file, but we still
|
||||||
// there is no error.
|
// must check any Expected<> return value.
|
||||||
SymbolTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolTable = BufOrErr.get();
|
||||||
if (Name == "/SYM64/")
|
if (Name == "/SYM64/")
|
||||||
has64SymTable = true;
|
has64SymTable = true;
|
||||||
|
|
||||||
@ -658,9 +678,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
|
|
||||||
if (Name == "//") {
|
if (Name == "//") {
|
||||||
Format = has64SymTable ? K_MIPS64 : K_GNU;
|
Format = has64SymTable ? K_MIPS64 : K_GNU;
|
||||||
// The string table is never an external member, so we just assert on the
|
// The string table is never an external member, but we still
|
||||||
// ErrorOr.
|
// must check any Expected<> return value.
|
||||||
StringTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringTable = BufOrErr.get();
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
setFirstRegular(*C);
|
setFirstRegular(*C);
|
||||||
@ -681,9 +706,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Format = K_COFF;
|
Format = K_COFF;
|
||||||
// We know that the symbol table is not an external file, so we just assert
|
// We know that the symbol table is not an external file, but we still
|
||||||
// there is no error.
|
// must check any Expected<> return value.
|
||||||
SymbolTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolTable = BufOrErr.get();
|
||||||
|
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
@ -702,9 +732,14 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
|
|||||||
Name = NameOrErr.get();
|
Name = NameOrErr.get();
|
||||||
|
|
||||||
if (Name == "//") {
|
if (Name == "//") {
|
||||||
// The string table is never an external member, so we just assert on the
|
// The string table is never an external member, but we still
|
||||||
// ErrorOr.
|
// must check any Expected<> return value.
|
||||||
StringTable = *C->getBuffer();
|
Expected<StringRef> BufOrErr = C->getBuffer();
|
||||||
|
if (!BufOrErr) {
|
||||||
|
Err = BufOrErr.takeError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringTable = BufOrErr.get();
|
||||||
if (Increment())
|
if (Increment())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -738,7 +773,7 @@ StringRef Archive::Symbol::getName() const {
|
|||||||
return Parent->getSymbolTable().begin() + StringIndex;
|
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 *Buf = Parent->getSymbolTable().begin();
|
||||||
const char *Offsets = Buf;
|
const char *Offsets = Buf;
|
||||||
if (Parent->kind() == K_MIPS64 || Parent->kind() == K_DARWIN64)
|
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);
|
uint32_t SymbolCount = read32le(Buf);
|
||||||
if (SymbolIndex >= SymbolCount)
|
if (SymbolIndex >= SymbolCount)
|
||||||
return object_error::parse_failed;
|
return errorCodeToError(object_error::parse_failed);
|
||||||
|
|
||||||
// Skip SymbolCount to get to the indices table.
|
// Skip SymbolCount to get to the indices table.
|
||||||
const char *Indices = Buf + 4;
|
const char *Indices = Buf + 4;
|
||||||
@ -785,7 +820,7 @@ ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
|
|||||||
--OffsetIndex;
|
--OffsetIndex;
|
||||||
|
|
||||||
if (OffsetIndex >= MemberCount)
|
if (OffsetIndex >= MemberCount)
|
||||||
return object_error::parse_failed;
|
return errorCodeToError(object_error::parse_failed);
|
||||||
|
|
||||||
Offset = read32le(Offsets + OffsetIndex * 4);
|
Offset = read32le(Offsets + OffsetIndex * 4);
|
||||||
}
|
}
|
||||||
@ -794,7 +829,7 @@ ErrorOr<Archive::Child> Archive::Symbol::getMember() const {
|
|||||||
Error Err;
|
Error Err;
|
||||||
Child C(Parent, Loc, &Err);
|
Child C(Parent, Loc, &Err);
|
||||||
if (Err)
|
if (Err)
|
||||||
return errorToErrorCode(std::move(Err));
|
return std::move(Err);
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,7 +960,7 @@ Expected<Optional<Archive::Child>> Archive::findSym(StringRef name) const {
|
|||||||
if (auto MemberOrErr = bs->getMember())
|
if (auto MemberOrErr = bs->getMember())
|
||||||
return Child(*MemberOrErr);
|
return Child(*MemberOrErr);
|
||||||
else
|
else
|
||||||
return errorCodeToError(MemberOrErr.getError());
|
return MemberOrErr.takeError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional<Child>();
|
return Optional<Child>();
|
||||||
|
@ -318,8 +318,8 @@ static void doPrint(StringRef Name, const object::Archive::Child &C) {
|
|||||||
if (Verbose)
|
if (Verbose)
|
||||||
outs() << "Printing " << Name << "\n";
|
outs() << "Printing " << Name << "\n";
|
||||||
|
|
||||||
ErrorOr<StringRef> DataOrErr = C.getBuffer();
|
Expected<StringRef> DataOrErr = C.getBuffer();
|
||||||
failIfError(DataOrErr.getError());
|
failIfError(DataOrErr.takeError());
|
||||||
StringRef Data = *DataOrErr;
|
StringRef Data = *DataOrErr;
|
||||||
outs().write(Data.data(), Data.size());
|
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);
|
raw_fd_ostream file(FD, false);
|
||||||
|
|
||||||
// Get the data and its length
|
// 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.
|
// Write the data.
|
||||||
file.write(Data.data(), Data.size());
|
file.write(Data.data(), Data.size());
|
||||||
|
@ -1097,9 +1097,9 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
|||||||
if (I != E) {
|
if (I != E) {
|
||||||
outs() << "Archive map\n";
|
outs() << "Archive map\n";
|
||||||
for (; I != E; ++I) {
|
for (; I != E; ++I) {
|
||||||
ErrorOr<Archive::Child> C = I->getMember();
|
Expected<Archive::Child> C = I->getMember();
|
||||||
if (error(C.getError()))
|
if (!C)
|
||||||
return;
|
error(C.takeError(), Filename);
|
||||||
Expected<StringRef> FileNameOrErr = C->getName();
|
Expected<StringRef> FileNameOrErr = C->getName();
|
||||||
if (!FileNameOrErr) {
|
if (!FileNameOrErr) {
|
||||||
error(FileNameOrErr.takeError(), Filename);
|
error(FileNameOrErr.takeError(), Filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user