diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-13 02:24:39 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-13 02:24:39 +0000 |
commit | 4e2b922131ae617cb8738d1871e9d918c44bdb69 (patch) | |
tree | d7ce433d5ae4fb27277c6d3777ca12199ffd51ac /lib/Object | |
parent | e431884ed751a78941cb32835d82dda24c839a1e (diff) | |
download | llvm-4e2b922131ae617cb8738d1871e9d918c44bdb69.tar.gz llvm-4e2b922131ae617cb8738d1871e9d918c44bdb69.tar.bz2 llvm-4e2b922131ae617cb8738d1871e9d918c44bdb69.tar.xz |
Remove 'using std::errro_code' from lib.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210871 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object')
-rw-r--r-- | lib/Object/Archive.cpp | 30 | ||||
-rw-r--r-- | lib/Object/COFFObjectFile.cpp | 254 | ||||
-rw-r--r-- | lib/Object/ELFObjectFile.cpp | 3 | ||||
-rw-r--r-- | lib/Object/IRObjectFile.cpp | 9 | ||||
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 1 | ||||
-rw-r--r-- | lib/Object/MachOUniversal.cpp | 18 | ||||
-rw-r--r-- | lib/Object/Object.cpp | 29 | ||||
-rw-r--r-- | lib/Object/ObjectFile.cpp | 13 |
8 files changed, 183 insertions, 174 deletions
diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 1e66da0639..8b362d66db 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -20,7 +20,6 @@ using namespace llvm; using namespace object; -using std::error_code; static const char *const Magic = "!<arch>\n"; @@ -116,7 +115,7 @@ Archive::Child Archive::Child::getNext() const { return Child(Parent, NextLoc); } -error_code Archive::Child::getName(StringRef &Result) const { +std::error_code Archive::Child::getName(StringRef &Result) const { StringRef name = getRawName(); // Check if it's a special name. if (name[0] == '/') { @@ -169,10 +168,11 @@ error_code Archive::Child::getName(StringRef &Result) const { return object_error::success; } -error_code Archive::Child::getMemoryBuffer(std::unique_ptr<MemoryBuffer> &Result, - bool FullPath) const { +std::error_code +Archive::Child::getMemoryBuffer(std::unique_ptr<MemoryBuffer> &Result, + bool FullPath) const { StringRef Name; - if (error_code ec = getName(Name)) + if (std::error_code ec = getName(Name)) return ec; SmallString<128> Path; Result.reset(MemoryBuffer::getMemBuffer( @@ -180,32 +180,32 @@ error_code Archive::Child::getMemoryBuffer(std::unique_ptr<MemoryBuffer> &Result .toStringRef(Path) : Name, false)); - return error_code(); + return std::error_code(); } -error_code Archive::Child::getAsBinary(std::unique_ptr<Binary> &Result, - LLVMContext *Context) const { +std::error_code Archive::Child::getAsBinary(std::unique_ptr<Binary> &Result, + LLVMContext *Context) const { std::unique_ptr<Binary> ret; std::unique_ptr<MemoryBuffer> Buff; - if (error_code ec = getMemoryBuffer(Buff)) + if (std::error_code ec = getMemoryBuffer(Buff)) return ec; ErrorOr<Binary *> BinaryOrErr = createBinary(Buff.release(), Context); - if (error_code EC = BinaryOrErr.getError()) + if (std::error_code EC = BinaryOrErr.getError()) return EC; Result.reset(BinaryOrErr.get()); return object_error::success; } ErrorOr<Archive*> Archive::create(MemoryBuffer *Source) { - error_code EC; + std::error_code EC; std::unique_ptr<Archive> Ret(new Archive(Source, EC)); if (EC) return EC; return Ret.release(); } -Archive::Archive(MemoryBuffer *source, error_code &ec) - : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) { +Archive::Archive(MemoryBuffer *source, std::error_code &ec) + : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) { // Check for sufficient magic. assert(source); if (source->getBufferSize() < 8 || @@ -336,12 +336,12 @@ Archive::child_iterator Archive::child_end() const { return Child(this, nullptr); } -error_code Archive::Symbol::getName(StringRef &Result) const { +std::error_code Archive::Symbol::getName(StringRef &Result) const { Result = StringRef(Parent->SymbolTable->getBuffer().begin() + StringIndex); return object_error::success; } -error_code Archive::Symbol::getMember(child_iterator &Result) const { +std::error_code Archive::Symbol::getMember(child_iterator &Result) const { const char *Buf = Parent->SymbolTable->getBuffer().begin(); const char *Offsets = Buf + 4; uint32_t Offset = 0; diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 8528840e12..186d64bafd 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -24,7 +24,6 @@ using namespace llvm; using namespace object; -using std::error_code; using support::ulittle8_t; using support::ulittle16_t; @@ -32,7 +31,8 @@ using support::ulittle32_t; using support::little16_t; // Returns false if size is greater than the buffer size. And sets ec. -static bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) { +static bool checkSize(const MemoryBuffer *M, std::error_code &EC, + uint64_t Size) { if (M->getBufferSize() < Size) { EC = object_error::unexpected_eof; return false; @@ -42,9 +42,10 @@ static bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) { // Sets Obj unless any bytes in [addr, addr + size) fall outsize of m. // Returns unexpected_eof if error. -template<typename T> -static error_code getObject(const T *&Obj, const MemoryBuffer *M, - const uint8_t *Ptr, const size_t Size = sizeof(T)) { +template <typename T> +static std::error_code getObject(const T *&Obj, const MemoryBuffer *M, + const uint8_t *Ptr, + const size_t Size = sizeof(T)) { uintptr_t Addr = uintptr_t(Ptr); if (Addr + Size < Addr || Addr + Size < Size || @@ -130,17 +131,17 @@ void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const { Ref.p = reinterpret_cast<uintptr_t>(Symb); } -error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, + StringRef &Result) const { const coff_symbol *Symb = toSymb(Ref); return getSymbolName(Symb, Result); } -error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, + uint64_t &Result) const { const coff_symbol *Symb = toSymb(Ref); const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; if (Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) @@ -152,8 +153,8 @@ error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, - SymbolRef::Type &Result) const { +std::error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, + SymbolRef::Type &Result) const { const coff_symbol *Symb = toSymb(Ref); Result = SymbolRef::ST_Other; if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL && @@ -165,7 +166,7 @@ error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, uint32_t Characteristics = 0; if (!COFF::isReservedSectionNumber(Symb->SectionNumber)) { const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; Characteristics = Section->Characteristics; } @@ -203,14 +204,14 @@ uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const { return Result; } -error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, + uint64_t &Result) const { // FIXME: Return the correct size. This requires looking at all the symbols // in the same section as this symbol, and looking for either the next // symbol, or the end of the section. const coff_symbol *Symb = toSymb(Ref); const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; if (Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) @@ -222,14 +223,16 @@ error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::getSymbolSection(DataRefImpl Ref, - section_iterator &Result) const { +std::error_code +COFFObjectFile::getSymbolSection(DataRefImpl Ref, + section_iterator &Result) const { const coff_symbol *Symb = toSymb(Ref); if (COFF::isReservedSectionNumber(Symb->SectionNumber)) { Result = section_end(); } else { const coff_section *Sec = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Sec)) return EC; + if (std::error_code EC = getSection(Symb->SectionNumber, Sec)) + return EC; DataRefImpl Ref; Ref.p = reinterpret_cast<uintptr_t>(Sec); Result = section_iterator(SectionRef(Ref, this)); @@ -243,37 +246,37 @@ void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const { Ref.p = reinterpret_cast<uintptr_t>(Sec); } -error_code COFFObjectFile::getSectionName(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSectionName(DataRefImpl Ref, + StringRef &Result) const { const coff_section *Sec = toSec(Ref); return getSectionName(Sec, Result); } -error_code COFFObjectFile::getSectionAddress(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSectionAddress(DataRefImpl Ref, + uint64_t &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->VirtualAddress; return object_error::success; } -error_code COFFObjectFile::getSectionSize(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSectionSize(DataRefImpl Ref, + uint64_t &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->SizeOfRawData; return object_error::success; } -error_code COFFObjectFile::getSectionContents(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSectionContents(DataRefImpl Ref, + StringRef &Result) const { const coff_section *Sec = toSec(Ref); ArrayRef<uint8_t> Res; - error_code EC = getSectionContents(Sec, Res); + std::error_code EC = getSectionContents(Sec, Res); Result = StringRef(reinterpret_cast<const char*>(Res.data()), Res.size()); return EC; } -error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, - uint64_t &Res) const { +std::error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, + uint64_t &Res) const { const coff_section *Sec = toSec(Ref); if (!Sec) return object_error::parse_failed; @@ -281,62 +284,64 @@ error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::isSectionText(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionText(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE; return object_error::success; } -error_code COFFObjectFile::isSectionData(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionData(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionBSS(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionBSS(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref, - bool &Result) const { +std::error_code +COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented Result = true; return object_error::success; } -error_code COFFObjectFile::isSectionVirtual(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionVirtual(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented. Result = false; return object_error::success; } -error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented. Result = false; return object_error::success; } -error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef, - DataRefImpl SymbRef, - bool &Result) const { +std::error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef, + DataRefImpl SymbRef, + bool &Result) const { const coff_section *Sec = toSec(SecRef); const coff_symbol *Symb = toSymb(SymbRef); const coff_section *SymbSec = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, SymbSec)) return EC; + if (std::error_code EC = getSection(Symb->SectionNumber, SymbSec)) + return EC; if (SymbSec == Sec) Result = true; else @@ -391,8 +396,8 @@ relocation_iterator COFFObjectFile::section_rel_end(DataRefImpl Ref) const { } // Initialize the pointer to the symbol table. -error_code COFFObjectFile::initSymbolTablePtr() { - if (error_code EC = getObject( +std::error_code COFFObjectFile::initSymbolTablePtr() { + if (std::error_code EC = getObject( SymbolTable, Data, base() + COFFHeader->PointerToSymbolTable, COFFHeader->NumberOfSymbols * sizeof(coff_symbol))) return EC; @@ -404,11 +409,11 @@ error_code COFFObjectFile::initSymbolTablePtr() { base() + COFFHeader->PointerToSymbolTable + COFFHeader->NumberOfSymbols * sizeof(coff_symbol); const ulittle32_t *StringTableSizePtr; - if (error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr)) + if (std::error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr)) return EC; StringTableSize = *StringTableSizePtr; - if (error_code EC = - getObject(StringTable, Data, StringTableAddr, StringTableSize)) + if (std::error_code EC = + getObject(StringTable, Data, StringTableAddr, StringTableSize)) return EC; // Treat table sizes < 4 as empty because contrary to the PECOFF spec, some @@ -423,7 +428,7 @@ error_code COFFObjectFile::initSymbolTablePtr() { } // Returns the file offset for the given VA. -error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { +std::error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { uint64_t ImageBase = PE32Header ? (uint64_t)PE32Header->ImageBase : (uint64_t)PE32PlusHeader->ImageBase; uint64_t Rva = Addr - ImageBase; @@ -432,7 +437,7 @@ error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { } // Returns the file offset for the given RVA. -error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { +std::error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { for (const SectionRef &S : sections()) { const coff_section *Section = getCOFFSection(S); uint32_t SectionStart = Section->VirtualAddress; @@ -448,10 +453,10 @@ error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { // Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name // table entry. -error_code COFFObjectFile:: -getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const { +std::error_code COFFObjectFile::getHintName(uint32_t Rva, uint16_t &Hint, + StringRef &Name) const { uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(Rva, IntPtr)) + if (std::error_code EC = getRvaPtr(Rva, IntPtr)) return EC; const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(IntPtr); Hint = *reinterpret_cast<const ulittle16_t *>(Ptr); @@ -460,7 +465,7 @@ getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const { } // Find the import table. -error_code COFFObjectFile::initImportTablePtr() { +std::error_code COFFObjectFile::initImportTablePtr() { // First, we get the RVA of the import table. If the file lacks a pointer to // the import table, do nothing. const data_directory *DataEntry; @@ -478,7 +483,7 @@ error_code COFFObjectFile::initImportTablePtr() { // Find the section that contains the RVA. This is needed because the RVA is // the import table's memory address which is different from its file offset. uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(ImportTableRva, IntPtr)) + if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr)) return EC; ImportDirectory = reinterpret_cast< const import_directory_table_entry *>(IntPtr); @@ -486,7 +491,7 @@ error_code COFFObjectFile::initImportTablePtr() { } // Find the export table. -error_code COFFObjectFile::initExportTablePtr() { +std::error_code COFFObjectFile::initExportTablePtr() { // First, we get the RVA of the export table. If the file lacks a pointer to // the export table, do nothing. const data_directory *DataEntry; @@ -499,14 +504,14 @@ error_code COFFObjectFile::initExportTablePtr() { uint32_t ExportTableRva = DataEntry->RelativeVirtualAddress; uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(ExportTableRva, IntPtr)) + if (std::error_code EC = getRvaPtr(ExportTableRva, IntPtr)) return EC; ExportDirectory = reinterpret_cast<const export_directory_table_entry *>(IntPtr); return object_error::success; } -COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &EC, +COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, std::error_code &EC, bool BufferOwned) : ObjectFile(Binary::ID_COFF, Object, BufferOwned), COFFHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr), DataDirectory(nullptr), @@ -687,28 +692,30 @@ unsigned COFFObjectFile::getArch() const { // This method is kept here because lld uses this. As soon as we make // lld to use getCOFFHeader, this method will be removed. -error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const { +std::error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const { return getCOFFHeader(Res); } -error_code COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const { +std::error_code +COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const { Res = COFFHeader; return object_error::success; } -error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const { +std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const { Res = PE32Header; return object_error::success; } -error_code +std::error_code COFFObjectFile::getPE32PlusHeader(const pe32plus_header *&Res) const { Res = PE32PlusHeader; return object_error::success; } -error_code COFFObjectFile::getDataDirectory(uint32_t Index, - const data_directory *&Res) const { +std::error_code +COFFObjectFile::getDataDirectory(uint32_t Index, + const data_directory *&Res) const { // Error if if there's no data directory or the index is out of range. if (!DataDirectory) return object_error::parse_failed; @@ -721,8 +728,8 @@ error_code COFFObjectFile::getDataDirectory(uint32_t Index, return object_error::success; } -error_code COFFObjectFile::getSection(int32_t Index, - const coff_section *&Result) const { +std::error_code COFFObjectFile::getSection(int32_t Index, + const coff_section *&Result) const { // Check for special index values. if (COFF::isReservedSectionNumber(Index)) Result = nullptr; @@ -734,8 +741,8 @@ error_code COFFObjectFile::getSection(int32_t Index, return object_error::success; } -error_code COFFObjectFile::getString(uint32_t Offset, - StringRef &Result) const { +std::error_code COFFObjectFile::getString(uint32_t Offset, + StringRef &Result) const { if (StringTableSize <= 4) // Tried to get a string from an empty string table. return object_error::parse_failed; @@ -745,8 +752,8 @@ error_code COFFObjectFile::getString(uint32_t Offset, return object_error::success; } -error_code COFFObjectFile::getSymbol(uint32_t Index, - const coff_symbol *&Result) const { +std::error_code COFFObjectFile::getSymbol(uint32_t Index, + const coff_symbol *&Result) const { if (Index < COFFHeader->NumberOfSymbols) Result = SymbolTable + Index; else @@ -754,12 +761,12 @@ error_code COFFObjectFile::getSymbol(uint32_t Index, return object_error::success; } -error_code COFFObjectFile::getSymbolName(const coff_symbol *Symbol, - StringRef &Res) const { +std::error_code COFFObjectFile::getSymbolName(const coff_symbol *Symbol, + StringRef &Res) const { // Check for string table entry. First 4 bytes are 0. if (Symbol->Name.Offset.Zeroes == 0) { uint32_t Offset = Symbol->Name.Offset.Offset; - if (error_code EC = getString(Offset, Res)) + if (std::error_code EC = getString(Offset, Res)) return EC; return object_error::success; } @@ -796,8 +803,8 @@ ArrayRef<uint8_t> COFFObjectFile::getSymbolAuxData( Symbol->NumberOfAuxSymbols * sizeof(coff_symbol)); } -error_code COFFObjectFile::getSectionName(const coff_section *Sec, - StringRef &Res) const { +std::error_code COFFObjectFile::getSectionName(const coff_section *Sec, + StringRef &Res) const { StringRef Name; if (Sec->Name[7] == 0) // Null terminated, let ::strlen figure out the length. @@ -816,7 +823,7 @@ error_code COFFObjectFile::getSectionName(const coff_section *Sec, if (Name.substr(1).getAsInteger(10, Offset)) return object_error::parse_failed; } - if (error_code EC = getString(Offset, Name)) + if (std::error_code EC = getString(Offset, Name)) return EC; } @@ -824,8 +831,9 @@ error_code COFFObjectFile::getSectionName(const coff_section *Sec, return object_error::success; } -error_code COFFObjectFile::getSectionContents(const coff_section *Sec, - ArrayRef<uint8_t> &Res) const { +std::error_code +COFFObjectFile::getSectionContents(const coff_section *Sec, + ArrayRef<uint8_t> &Res) const { // The only thing that we need to verify is that the contents is contained // within the file bounds. We don't need to make sure it doesn't cover other // data, as there's nothing that says that is not allowed. @@ -847,13 +855,13 @@ void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { reinterpret_cast<const coff_relocation*>(Rel.p) + 1); } -error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, + uint64_t &Res) const { report_fatal_error("getRelocationAddress not implemented in COFFObjectFile"); } -error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel, + uint64_t &Res) const { Res = toRel(Rel)->VirtualAddress; return object_error::success; } @@ -865,8 +873,8 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { return symbol_iterator(SymbolRef(Ref, this)); } -error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, + uint64_t &Res) const { const coff_relocation* R = toRel(Rel); Res = R->Type; return object_error::success; @@ -892,8 +900,9 @@ COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const { Res = #reloc_type; \ break; -error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl<char> &Result) const { +std::error_code +COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl<char> &Result) const { const coff_relocation *Reloc = toRel(Rel); StringRef Res; switch (COFFHeader->Machine) { @@ -967,26 +976,29 @@ error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME -error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel, - SmallVectorImpl<char> &Result) const { +std::error_code +COFFObjectFile::getRelocationValueString(DataRefImpl Rel, + SmallVectorImpl<char> &Result) const { const coff_relocation *Reloc = toRel(Rel); const coff_symbol *Symb = nullptr; - if (error_code EC = getSymbol(Reloc->SymbolTableIndex, Symb)) return EC; + if (std::error_code EC = getSymbol(Reloc->SymbolTableIndex, Symb)) + return EC; DataRefImpl Sym; Sym.p = reinterpret_cast<uintptr_t>(Symb); StringRef SymName; - if (error_code EC = getSymbolName(Sym, SymName)) return EC; + if (std::error_code EC = getSymbolName(Sym, SymName)) + return EC; Result.append(SymName.begin(), SymName.end()); return object_error::success; } -error_code COFFObjectFile::getLibraryNext(DataRefImpl LibData, - LibraryRef &Result) const { +std::error_code COFFObjectFile::getLibraryNext(DataRefImpl LibData, + LibraryRef &Result) const { report_fatal_error("getLibraryNext not implemented in COFFObjectFile"); } -error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData, - StringRef &Result) const { +std::error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData, + StringRef &Result) const { report_fatal_error("getLibraryPath not implemented in COFFObjectFile"); } @@ -999,24 +1011,25 @@ void ImportDirectoryEntryRef::moveNext() { ++Index; } -error_code ImportDirectoryEntryRef:: -getImportTableEntry(const import_directory_table_entry *&Result) const { +std::error_code ImportDirectoryEntryRef::getImportTableEntry( + const import_directory_table_entry *&Result) const { Result = ImportTable; return object_error::success; } -error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { +std::error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr)) return EC; Result = StringRef(reinterpret_cast<const char *>(IntPtr)); return object_error::success; } -error_code ImportDirectoryEntryRef::getImportLookupEntry( +std::error_code ImportDirectoryEntryRef::getImportLookupEntry( const import_lookup_table_entry32 *&Result) const { uintptr_t IntPtr = 0; - if (error_code EC = + if (std::error_code EC = OwningObject->getRvaPtr(ImportTable->ImportLookupTableRVA, IntPtr)) return EC; Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr); @@ -1034,31 +1047,33 @@ void ExportDirectoryEntryRef::moveNext() { // Returns the name of the current export symbol. If the symbol is exported only // by ordinal, the empty string is set as a result. -error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const { +std::error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr)) return EC; Result = StringRef(reinterpret_cast<const char *>(IntPtr)); return object_error::success; } // Returns the starting ordinal number. -error_code ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const { +std::error_code +ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const { Result = ExportTable->OrdinalBase; return object_error::success; } // Returns the export ordinal of the current export symbol. -error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const { +std::error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const { Result = ExportTable->OrdinalBase + Index; return object_error::success; } // Returns the address of the current export symbol. -error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { +std::error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->ExportAddressTableRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->ExportAddressTableRVA, IntPtr)) return EC; const export_address_table_entry *entry = reinterpret_cast<const export_address_table_entry *>(IntPtr); @@ -1068,10 +1083,11 @@ error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { // Returns the name of the current export symbol. If the symbol is exported only // by ordinal, the empty string is set as a result. -error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { +std::error_code +ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->OrdinalTableRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->OrdinalTableRVA, IntPtr)) return EC; const ulittle16_t *Start = reinterpret_cast<const ulittle16_t *>(IntPtr); @@ -1081,11 +1097,11 @@ error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { I < E; ++I, ++Offset) { if (*I != Index) continue; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->NamePointerRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->NamePointerRVA, IntPtr)) return EC; const ulittle32_t *NamePtr = reinterpret_cast<const ulittle32_t *>(IntPtr); - if (error_code EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr)) + if (std::error_code EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr)) return EC; Result = StringRef(reinterpret_cast<const char *>(IntPtr)); return object_error::success; @@ -1096,7 +1112,7 @@ error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { ErrorOr<ObjectFile *> ObjectFile::createCOFFObjectFile(MemoryBuffer *Object, bool BufferOwned) { - error_code EC; + std::error_code EC; std::unique_ptr<COFFObjectFile> Ret( new COFFObjectFile(Object, EC, BufferOwned)); if (EC) diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index de05abb43b..a11a9e016d 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -15,7 +15,6 @@ #include "llvm/Support/MathExtras.h" namespace llvm { -using std::error_code; using namespace object; ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj, @@ -24,7 +23,7 @@ ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj, std::size_t MaxAlignment = 1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart())); - error_code EC; + std::error_code EC; std::unique_ptr<ObjectFile> R; if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp index 57c2232d47..48820361d4 100644 --- a/lib/Object/IRObjectFile.cpp +++ b/lib/Object/IRObjectFile.cpp @@ -19,9 +19,8 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace object; -using std::error_code; -IRObjectFile::IRObjectFile(MemoryBuffer *Object, error_code &EC, +IRObjectFile::IRObjectFile(MemoryBuffer *Object, std::error_code &EC, LLVMContext &Context, bool BufferOwned) : SymbolicFile(Binary::ID_IR, Object, BufferOwned) { ErrorOr<Module*> MOrErr = parseBitcodeFile(Object, Context); @@ -93,8 +92,8 @@ void IRObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.p = Res; } -error_code IRObjectFile::printSymbolName(raw_ostream &OS, - DataRefImpl Symb) const { +std::error_code IRObjectFile::printSymbolName(raw_ostream &OS, + DataRefImpl Symb) const { const GlobalValue &GV = getGV(Symb); if (Mang) @@ -143,7 +142,7 @@ basic_symbol_iterator IRObjectFile::symbol_end_impl() const { ErrorOr<SymbolicFile *> llvm::object::SymbolicFile::createIRObjectFile( MemoryBuffer *Object, LLVMContext &Context, bool BufferOwned) { - error_code EC; + std::error_code EC; std::unique_ptr<IRObjectFile> Ret( new IRObjectFile(Object, EC, Context, BufferOwned)); if (EC) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a71a139b02..e61422885b 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -28,7 +28,6 @@ using namespace llvm; using namespace object; namespace llvm { -using std::error_code; namespace object { diff --git a/lib/Object/MachOUniversal.cpp b/lib/Object/MachOUniversal.cpp index 1d45004273..ea4773feee 100644 --- a/lib/Object/MachOUniversal.cpp +++ b/lib/Object/MachOUniversal.cpp @@ -21,7 +21,6 @@ using namespace llvm; using namespace object; -using std::error_code; template<typename T> static void SwapValue(T &Value) { @@ -73,7 +72,7 @@ MachOUniversalBinary::ObjectForArch::ObjectForArch( } } -error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( +std::error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( std::unique_ptr<ObjectFile> &Result) const { if (Parent) { StringRef ParentData = Parent->getData(); @@ -84,7 +83,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( ObjectData, ObjectName, false); ErrorOr<ObjectFile *> Obj = ObjectFile::createMachOObjectFile(ObjBuffer); - if (error_code EC = Obj.getError()) + if (std::error_code EC = Obj.getError()) return EC; Result.reset(Obj.get()); return object_error::success; @@ -92,7 +91,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( return object_error::parse_failed; } -error_code MachOUniversalBinary::ObjectForArch::getAsArchive( +std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive( std::unique_ptr<Archive> &Result) const { if (Parent) { StringRef ParentData = Parent->getData(); @@ -103,7 +102,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsArchive( MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( ObjectData, ObjectName, false); ErrorOr<Archive *> Obj = Archive::create(ObjBuffer); - if (error_code EC = Obj.getError()) + if (std::error_code EC = Obj.getError()) return EC; Result.reset(Obj.get()); return object_error::success; @@ -115,7 +114,7 @@ void MachOUniversalBinary::anchor() { } ErrorOr<MachOUniversalBinary *> MachOUniversalBinary::create(MemoryBuffer *Source) { - error_code EC; + std::error_code EC; std::unique_ptr<MachOUniversalBinary> Ret( new MachOUniversalBinary(Source, EC)); if (EC) @@ -124,9 +123,8 @@ MachOUniversalBinary::create(MemoryBuffer *Source) { } MachOUniversalBinary::MachOUniversalBinary(MemoryBuffer *Source, - error_code &ec) - : Binary(Binary::ID_MachOUniversalBinary, Source), - NumberOfObjects(0) { + std::error_code &ec) + : Binary(Binary::ID_MachOUniversalBinary, Source), NumberOfObjects(0) { if (Source->getBufferSize() < sizeof(MachO::fat_header)) { ec = object_error::invalid_file_type; return; @@ -156,7 +154,7 @@ static bool getCTMForArch(Triple::ArchType Arch, MachO::CPUType &CTM) { } } -error_code MachOUniversalBinary::getObjectForArch( +std::error_code MachOUniversalBinary::getObjectForArch( Triple::ArchType Arch, std::unique_ptr<ObjectFile> &Result) const { MachO::CPUType CTM; if (!getCTMForArch(Arch, CTM)) diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index 8792345c79..7282f468b0 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -18,7 +18,6 @@ using namespace llvm; using namespace object; -using std::error_code; inline ObjectFile *unwrap(LLVMObjectFileRef OF) { return reinterpret_cast<ObjectFile*>(OF); @@ -90,7 +89,7 @@ void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, LLVMSymbolIteratorRef Sym) { - if (error_code ec = (*unwrap(Sym))->getSection(*unwrap(Sect))) + if (std::error_code ec = (*unwrap(Sym))->getSection(*unwrap(Sect))) report_fatal_error(ec.message()); } @@ -116,28 +115,28 @@ void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) { // SectionRef accessors const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getName(ret)) + if (std::error_code ec = (*unwrap(SI))->getName(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getSize(ret)) + if (std::error_code ec = (*unwrap(SI))->getSize(ret)) report_fatal_error(ec.message()); return ret; } const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getContents(ret)) + if (std::error_code ec = (*unwrap(SI))->getContents(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(SI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } @@ -145,7 +144,7 @@ uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) { LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, LLVMSymbolIteratorRef Sym) { bool ret; - if (error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret)) + if (std::error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret)) report_fatal_error(ec.message()); return ret; } @@ -173,21 +172,21 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) { // SymbolRef accessors const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getName(ret)) + if (std::error_code ec = (*unwrap(SI))->getName(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(SI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getSize(ret)) + if (std::error_code ec = (*unwrap(SI))->getSize(ret)) report_fatal_error(ec.message()); return ret; } @@ -195,14 +194,14 @@ uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) { // RelocationRef accessors uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(RI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getOffset(ret)) + if (std::error_code ec = (*unwrap(RI))->getOffset(ret)) report_fatal_error(ec.message()); return ret; } @@ -214,7 +213,7 @@ LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) { uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getType(ret)) + if (std::error_code ec = (*unwrap(RI))->getType(ret)) report_fatal_error(ec.message()); return ret; } @@ -222,7 +221,7 @@ uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { // NOTE: Caller takes ownership of returned string. const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { SmallVector<char, 0> ret; - if (error_code ec = (*unwrap(RI))->getTypeName(ret)) + if (std::error_code ec = (*unwrap(RI))->getTypeName(ret)) report_fatal_error(ec.message()); char *str = static_cast<char*>(malloc(ret.size())); @@ -233,7 +232,7 @@ const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { // NOTE: Caller takes ownership of returned string. const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI) { SmallVector<char, 0> ret; - if (error_code ec = (*unwrap(RI))->getValueString(ret)) + if (std::error_code ec = (*unwrap(RI))->getValueString(ret)) report_fatal_error(ec.message()); char *str = static_cast<char*>(malloc(ret.size())); diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index 5d43249234..7666ed53c3 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -20,7 +20,6 @@ using namespace llvm; using namespace object; -using std::error_code; void ObjectFile::anchor() { } @@ -28,17 +27,17 @@ ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned) : SymbolicFile(Type, Source, BufferOwned) {} -error_code ObjectFile::printSymbolName(raw_ostream &OS, - DataRefImpl Symb) const { +std::error_code ObjectFile::printSymbolName(raw_ostream &OS, + DataRefImpl Symb) const { StringRef Name; - if (error_code EC = getSymbolName(Symb, Name)) + if (std::error_code EC = getSymbolName(Symb, Name)) return EC; OS << Name; return object_error::success; } -error_code ObjectFile::getSymbolAlignment(DataRefImpl DRI, - uint32_t &Result) const { +std::error_code ObjectFile::getSymbolAlignment(DataRefImpl DRI, + uint32_t &Result) const { Result = 0; return object_error::success; } @@ -88,7 +87,7 @@ ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object, ErrorOr<ObjectFile *> ObjectFile::createObjectFile(StringRef ObjectPath) { std::unique_ptr<MemoryBuffer> File; - if (error_code EC = MemoryBuffer::getFile(ObjectPath, File)) + if (std::error_code EC = MemoryBuffer::getFile(ObjectPath, File)) return EC; return createObjectFile(File.release()); } |