diff options
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/Object/Object.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Object/ObjectFile.cpp | 6 |
4 files changed, 25 insertions, 31 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index fa6aa4ced39..d3f604a8d35 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -238,21 +238,17 @@ uint64_t COFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Ref) const { return Symb.getValue(); } -std::error_code -COFFObjectFile::getSymbolSection(DataRefImpl Ref, - section_iterator &Result) const { +ErrorOr<section_iterator> +COFFObjectFile::getSymbolSection(DataRefImpl Ref) const { COFFSymbolRef Symb = getCOFFSymbol(Ref); - if (COFF::isReservedSectionNumber(Symb.getSectionNumber())) { - Result = section_end(); - } else { - const coff_section *Sec = nullptr; - if (std::error_code EC = getSection(Symb.getSectionNumber(), Sec)) - return EC; - DataRefImpl Ref; - Ref.p = reinterpret_cast<uintptr_t>(Sec); - Result = section_iterator(SectionRef(Ref, this)); - } - return std::error_code(); + if (COFF::isReservedSectionNumber(Symb.getSectionNumber())) + return section_end(); + const coff_section *Sec = nullptr; + if (std::error_code EC = getSection(Symb.getSectionNumber(), Sec)) + return EC; + DataRefImpl Ret; + Ret.p = reinterpret_cast<uintptr_t>(Sec); + return section_iterator(SectionRef(Ret, this)); } unsigned COFFObjectFile::getSymbolSectionID(SymbolRef Sym) const { diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 05900630c75..d1faf7be3af 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -445,22 +445,18 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const { return Result; } -std::error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const { +ErrorOr<section_iterator> +MachOObjectFile::getSymbolSection(DataRefImpl Symb) const { MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb); uint8_t index = Entry.n_sect; - if (index == 0) { - Res = section_end(); - } else { - DataRefImpl DRI; - DRI.d.a = index - 1; - if (DRI.d.a >= Sections.size()) - report_fatal_error("getSymbolSection: Invalid section index."); - Res = section_iterator(SectionRef(DRI, this)); - } - - return std::error_code(); + if (index == 0) + return section_end(); + DataRefImpl DRI; + DRI.d.a = index - 1; + if (DRI.d.a >= Sections.size()) + report_fatal_error("getSymbolSection: Invalid section index."); + return section_iterator(SectionRef(DRI, this)); } unsigned MachOObjectFile::getSymbolSectionID(SymbolRef Sym) const { diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index 5c4b7a67b2a..b44c1a16fd0 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -98,8 +98,10 @@ void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, LLVMSymbolIteratorRef Sym) { - if (std::error_code ec = (*unwrap(Sym))->getSection(*unwrap(Sect))) + ErrorOr<section_iterator> SecOrErr = (*unwrap(Sym))->getSection(); + if (std::error_code ec = SecOrErr.getError()) report_fatal_error(ec.message()); + *unwrap(Sect) = *SecOrErr; } // ObjectFile Symbol iterators diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index f82edae89bc..d12dc411361 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -29,10 +29,10 @@ ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source) : SymbolicFile(Type, Source) {} bool SectionRef::containsSymbol(SymbolRef S) const { - section_iterator SymSec = getObject()->section_end(); - if (S.getSection(SymSec)) + ErrorOr<section_iterator> SymSec = S.getSection(); + if (!SymSec) return false; - return *this == *SymSec; + return *this == **SymSec; } uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const { |