summaryrefslogtreecommitdiffstats
path: root/lld/lib
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2016-03-30 23:58:24 +0000
committerPete Cooper <peter_cooper@apple.com>2016-03-30 23:58:24 +0000
commitc6e7b8146a71b10ac41f452286e8aa57c1bf4c8b (patch)
tree86003ad806bf82c8e86a54e3827ac2a37dc3fbda /lld/lib
parentbe0df2b10243c539cf58f23854d0c470ac3e687f (diff)
downloadbcm5719-llvm-c6e7b8146a71b10ac41f452286e8aa57c1bf4c8b.tar.gz
bcm5719-llvm-c6e7b8146a71b10ac41f452286e8aa57c1bf4c8b.zip
Convert readBinary to llvm::Error. NFC
llvm-svn: 264973
Diffstat (limited to 'lld/lib')
-rw-r--r--lld/lib/ReaderWriter/MachO/File.h8
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFile.h2
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp13
3 files changed, 12 insertions, 11 deletions
diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h
index bfb150a440d..7e0f0b2e89b 100644
--- a/lld/lib/ReaderWriter/MachO/File.h
+++ b/lld/lib/ReaderWriter/MachO/File.h
@@ -228,8 +228,8 @@ protected:
std::error_code doParse() override {
// Convert binary file to normalized mach-o.
auto normFile = normalized::readBinary(_mb, _ctx->arch());
- if (std::error_code ec = normFile.getError())
- return ec;
+ if (auto ec = normFile.takeError())
+ return llvm::errorToErrorCode(std::move(ec));
// Convert normalized mach-o to atoms.
if (auto ec = normalized::normalizedObjectToAtoms(this, **normFile, false))
return llvm::errorToErrorCode(std::move(ec));
@@ -317,8 +317,8 @@ public:
std::error_code doParse() override {
// Convert binary file to normalized mach-o.
auto normFile = normalized::readBinary(_mb, _ctx->arch());
- if (std::error_code ec = normFile.getError())
- return ec;
+ if (auto ec = normFile.takeError())
+ return llvm::errorToErrorCode(std::move(ec));
// Convert normalized mach-o to atoms.
if (auto ec = normalized::normalizedDylibToAtoms(this, **normFile, false))
return llvm::errorToErrorCode(std::move(ec));
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
index b6f264c41ef..5f7584a3a40 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
@@ -289,7 +289,7 @@ bool sliceFromFatFile(MemoryBufferRef mb, MachOLinkingContext::Arch arch,
uint32_t &offset, uint32_t &size);
/// Reads a mach-o file and produces an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
readBinary(std::unique_ptr<MemoryBuffer> &mb,
const MachOLinkingContext::Arch arch);
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
index 39860bbbdfa..cca400b9082 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
@@ -199,7 +199,7 @@ bool sliceFromFatFile(MemoryBufferRef mb, MachOLinkingContext::Arch arch,
}
/// Reads a mach-o file and produces an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
readBinary(std::unique_ptr<MemoryBuffer> &mb,
const MachOLinkingContext::Arch arch) {
// Make empty NormalizedFile.
@@ -220,7 +220,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
// Determine endianness and pointer size for mach-o file.
bool is64, isBig;
if (!isMachOHeader(mh, is64, isBig))
- return make_error_code(llvm::errc::executable_format_error);
+ return llvm::make_error<GenericError>("File is not a mach-o");
// Endian swap header, if needed.
mach_header headerCopy;
@@ -237,12 +237,13 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
start + (is64 ? sizeof(mach_header_64) : sizeof(mach_header));
StringRef lcRange(lcStart, smh->sizeofcmds);
if (lcRange.end() > (start + objSize))
- return make_error_code(llvm::errc::executable_format_error);
+ return llvm::make_error<GenericError>("Load commands exceed file size");
// Get architecture from mach_header.
f->arch = MachOLinkingContext::archFromCpuType(smh->cputype, smh->cpusubtype);
if (f->arch != arch) {
- return make_dynamic_error_code(Twine("file is wrong architecture. Expected "
+ return llvm::make_error<GenericError>(
+ Twine("file is wrong architecture. Expected "
"(" + MachOLinkingContext::nameFromArch(arch)
+ ") found ("
+ MachOLinkingContext::nameFromArch(f->arch)
@@ -268,7 +269,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
return false;
});
if (ec)
- return ec;
+ return llvm::errorCodeToError(ec);
// Walk load commands looking for segments/sections and the symbol table.
const data_in_code_entry *dataInCode = nullptr;
@@ -484,7 +485,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
return false;
});
if (ec)
- return ec;
+ return llvm::errorCodeToError(ec);
if (dataInCode) {
// Convert on-disk data_in_code_entry array to DataInCode vector.
OpenPOWER on IntegriCloud