diff options
Diffstat (limited to 'contrib/llvm/lib/Object/ELFObjectFile.cpp')
-rw-r--r-- | contrib/llvm/lib/Object/ELFObjectFile.cpp | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/contrib/llvm/lib/Object/ELFObjectFile.cpp b/contrib/llvm/lib/Object/ELFObjectFile.cpp index 15bc6be..4f0f60b 100644 --- a/contrib/llvm/lib/Object/ELFObjectFile.cpp +++ b/contrib/llvm/lib/Object/ELFObjectFile.cpp @@ -17,57 +17,70 @@ namespace llvm { using namespace object; -// Creates an in-memory object-file by default: createELFObjectFile(Buffer) -ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) { - std::pair<unsigned char, unsigned char> Ident = getElfArchType(Object); - error_code ec; - +ErrorOr<ObjectFile *> +ObjectFile::createELFObjectFile(std::unique_ptr<MemoryBuffer> &Obj) { + std::pair<unsigned char, unsigned char> Ident = + getElfArchType(Obj->getBuffer()); std::size_t MaxAlignment = - 1ULL << countTrailingZeros(uintptr_t(Object->getBufferStart())); + 1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart())); + std::error_code EC; + std::unique_ptr<ObjectFile> R; if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 4) - return new ELFObjectFile<ELFType<support::little, 4, false> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::little, 4, false>>( + std::move(Obj), EC)); else #endif if (MaxAlignment >= 2) - return new ELFObjectFile<ELFType<support::little, 2, false> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::little, 2, false>>( + std::move(Obj), EC)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 4) - return new ELFObjectFile<ELFType<support::big, 4, false> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::big, 4, false>>(std::move(Obj), + EC)); else #endif if (MaxAlignment >= 2) - return new ELFObjectFile<ELFType<support::big, 2, false> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::big, 2, false>>(std::move(Obj), + EC)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) - return new ELFObjectFile<ELFType<support::big, 8, true> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::big, 8, true>>(std::move(Obj), + EC)); else #endif if (MaxAlignment >= 2) - return new ELFObjectFile<ELFType<support::big, 2, true> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::big, 2, true>>(std::move(Obj), + EC)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) { #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) - return new ELFObjectFile<ELFType<support::little, 8, true> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::little, 8, true>>( + std::move(Obj), EC)); else #endif if (MaxAlignment >= 2) - return new ELFObjectFile<ELFType<support::little, 2, true> >(Object, ec); + R.reset(new ELFObjectFile<ELFType<support::little, 2, true>>( + std::move(Obj), EC)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; } + else + llvm_unreachable("Buffer is not an ELF object file!"); - report_fatal_error("Buffer is not an ELF object file!"); + if (EC) + return EC; + return R.release(); } } // end namespace llvm |