From e84d8c12d5157a926db15976389f703809c49aa5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 7 Aug 2015 23:27:14 +0000 Subject: [PATCH] Convert getSymbolSection to return an ErrorOr. This function can actually fail since the symbol contains an index to the section and that can be invalid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244375 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/COFF.h | 3 +-- include/llvm/Object/ELFObjectFile.h | 17 ++++++------- include/llvm/Object/MachO.h | 3 +-- include/llvm/Object/ObjectFile.h | 10 ++++---- lib/DebugInfo/DWARF/DWARFContext.cpp | 2 +- .../RuntimeDyld/RuntimeDyld.cpp | 5 ++-- .../RuntimeDyld/RuntimeDyldELF.cpp | 8 +++---- .../Targets/RuntimeDyldCOFFX86_64.h | 3 +-- lib/Object/COFFObjectFile.cpp | 24 ++++++++----------- lib/Object/MachOObjectFile.cpp | 22 +++++++---------- lib/Object/Object.cpp | 4 +++- lib/Object/ObjectFile.cpp | 6 ++--- tools/dsymutil/MachODebugMapParser.cpp | 9 +++++-- tools/llvm-cxxdump/llvm-cxxdump.cpp | 5 ++-- tools/llvm-nm/llvm-nm.cpp | 16 ++++++------- tools/llvm-objdump/COFFDump.cpp | 6 ++--- tools/llvm-objdump/MachODump.cpp | 6 ++--- tools/llvm-objdump/llvm-objdump.cpp | 5 ++-- tools/llvm-readobj/ARMWinEHPrinter.cpp | 5 ++-- tools/llvm-readobj/MachODumper.cpp | 5 ++-- tools/llvm-readobj/Win64EHDumper.cpp | 7 ++---- tools/llvm-rtdyld/llvm-rtdyld.cpp | 3 +-- 22 files changed, 83 insertions(+), 91 deletions(-) diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 025a9dbc6bc..ce9042fd3ab 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -653,8 +653,7 @@ protected: uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; uint32_t getSymbolFlags(DataRefImpl Symb) const override; SymbolRef::Type getSymbolType(DataRefImpl Symb) const override; - std::error_code getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const override; + ErrorOr getSymbolSection(DataRefImpl Symb) const override; void moveSectionNext(DataRefImpl &Sec) const override; std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index c3483378eb9..b63eaac52d2 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -204,9 +204,8 @@ protected: uint8_t getSymbolOther(DataRefImpl Symb) const override; uint8_t getSymbolELFType(DataRefImpl Symb) const override; SymbolRef::Type getSymbolType(DataRefImpl Symb) const override; - section_iterator getSymbolSection(const Elf_Sym *Symb) const; - std::error_code getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const override; + ErrorOr getSymbolSection(const Elf_Sym *Symb) const; + ErrorOr getSymbolSection(DataRefImpl Symb) const override; void moveSectionNext(DataRefImpl &Sec) const override; std::error_code getSectionName(DataRefImpl Sec, @@ -505,11 +504,11 @@ uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const { } template -section_iterator +ErrorOr ELFObjectFile::getSymbolSection(const Elf_Sym *ESym) const { ErrorOr ESecOrErr = EF.getSection(ESym); if (std::error_code EC = ESecOrErr.getError()) - report_fatal_error(EC.message()); + return EC; const Elf_Shdr *ESec = *ESecOrErr; if (!ESec) @@ -521,11 +520,9 @@ ELFObjectFile::getSymbolSection(const Elf_Sym *ESym) const { } template -std::error_code -ELFObjectFile::getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const { - Res = getSymbolSection(getSymbol(Symb)); - return std::error_code(); +ErrorOr +ELFObjectFile::getSymbolSection(DataRefImpl Symb) const { + return getSymbolSection(getSymbol(Symb)); } template diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 489ecef5c99..47d018d3a5e 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -210,8 +210,7 @@ public: uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; SymbolRef::Type getSymbolType(DataRefImpl Symb) const override; uint32_t getSymbolFlags(DataRefImpl Symb) const override; - std::error_code getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const override; + ErrorOr getSymbolSection(DataRefImpl Symb) const override; unsigned getSymbolSectionID(SymbolRef Symb) const; unsigned getSectionID(SectionRef Sec) const; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 8dd52562621..08131908e06 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -147,7 +147,7 @@ public: /// @brief Get section this symbol is defined in reference to. Result is /// end_sections() if it is undefined or is an absolute symbol. - std::error_code getSection(section_iterator &Result) const; + ErrorOr getSection() const; const ObjectFile *getObject() const; }; @@ -202,8 +202,8 @@ protected: virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const; virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0; virtual SymbolRef::Type getSymbolType(DataRefImpl Symb) const = 0; - virtual std::error_code getSymbolSection(DataRefImpl Symb, - section_iterator &Res) const = 0; + virtual ErrorOr + getSymbolSection(DataRefImpl Symb) const = 0; // Same as above for SectionRef. friend class SectionRef; @@ -323,8 +323,8 @@ inline uint64_t SymbolRef::getCommonSize() const { return getObject()->getCommonSymbolSize(getRawDataRefImpl()); } -inline std::error_code SymbolRef::getSection(section_iterator &Result) const { - return getObject()->getSymbolSection(getRawDataRefImpl(), Result); +inline ErrorOr SymbolRef::getSection() const { + return getObject()->getSymbolSection(getRawDataRefImpl()); } inline SymbolRef::Type SymbolRef::getType() const { diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 408214339a8..4316934df04 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -685,7 +685,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, } SymAddr = *SymAddrOrErr; // Also remember what section this symbol is in for later - Sym->getSection(RSec); + RSec = *Sym->getSection(); } else if (auto *MObj = dyn_cast(&Obj)) { // MachO also has relocations that point to sections and // scattered relocations. diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 24495b21d45..2ce337dc83d 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -164,8 +164,9 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) { ErrorOr NameOrErr = I->getName(); Check(NameOrErr.getError()); StringRef Name = *NameOrErr; - section_iterator SI = Obj.section_end(); - Check(I->getSection(SI)); + ErrorOr SIOrErr = I->getSection(); + Check(SIOrErr.getError()); + section_iterator SI = *SIOrErr; if (SI == Obj.section_end()) continue; uint64_t SectOffset; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index a93c3d3098c..16612c146dd 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -845,8 +845,9 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj, if (Rel.Addend != (int64_t)TargetSymbolOffset) continue; - section_iterator tsi(Obj.section_end()); - check(TargetSymbol->getSection(tsi)); + ErrorOr TSIOrErr = TargetSymbol->getSection(); + check(TSIOrErr.getError()); + section_iterator tsi = *TSIOrErr; bool IsCode = tsi->isText(); Rel.SectionID = findOrEmitSection(Obj, (*tsi), IsCode, LocalSections); Rel.Addend = (intptr_t)Addend; @@ -1162,8 +1163,7 @@ relocation_iterator RuntimeDyldELF::processRelocationRef( // TODO: Now ELF SymbolRef::ST_Debug = STT_SECTION, it's not obviously // and can be changed by another developers. Maybe best way is add // a new symbol type ST_Section to SymbolRef and use it. - section_iterator si(Obj.section_end()); - Symbol->getSection(si); + section_iterator si = *Symbol->getSection(); if (si == Obj.section_end()) llvm_unreachable("Symbol section not found, bad object file format!"); DEBUG(dbgs() << "\t\tThis is section symbol\n"); diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h index 408227eb0f2..8b7d06930a1 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h @@ -119,8 +119,7 @@ public: symbol_iterator Symbol = RelI->getSymbol(); if (Symbol == Obj.symbol_end()) report_fatal_error("Unknown symbol in relocation"); - section_iterator SecI(Obj.section_end()); - Symbol->getSection(SecI); + section_iterator SecI = *Symbol->getSection(); // If there is no section, this must be an external reference. const bool IsExtern = SecI == Obj.section_end(); diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index fa6aa4ced39..d3f604a8d35 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/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 +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(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(Sec); + return section_iterator(SectionRef(Ret, this)); } unsigned COFFObjectFile::getSymbolSectionID(SymbolRef Sym) const { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 05900630c75..d1faf7be3af 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/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 +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/lib/Object/Object.cpp b/lib/Object/Object.cpp index 5c4b7a67b2a..b44c1a16fd0 100644 --- a/lib/Object/Object.cpp +++ b/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 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/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index f82edae89bc..d12dc411361 100644 --- a/lib/Object/ObjectFile.cpp +++ b/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 SymSec = S.getSection(); + if (!SymSec) return false; - return *this == *SymSec; + return *this == **SymSec; } uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const { diff --git a/tools/dsymutil/MachODebugMapParser.cpp b/tools/dsymutil/MachODebugMapParser.cpp index cd427cb1d94..bd29f004b09 100644 --- a/tools/dsymutil/MachODebugMapParser.cpp +++ b/tools/dsymutil/MachODebugMapParser.cpp @@ -265,8 +265,13 @@ void MachODebugMapParser::loadMainBinarySymbols( // are the only ones that need to be queried because the address // of common data won't be described in the debug map. All other // addresses should be fetched for the debug map. - if (!(Sym.getFlags() & SymbolRef::SF_Global) || Sym.getSection(Section) || - Section == MainBinary.section_end() || Section->isText()) + if (!(Sym.getFlags() & SymbolRef::SF_Global)) + continue; + ErrorOr SectionOrErr = Sym.getSection(); + if (!SectionOrErr) + continue; + Section = *SectionOrErr; + if (Section == MainBinary.section_end() || Section->isText()) continue; uint64_t Addr = Sym.getValue(); ErrorOr NameOrErr = Sym.getName(); diff --git a/tools/llvm-cxxdump/llvm-cxxdump.cpp b/tools/llvm-cxxdump/llvm-cxxdump.cpp index ee905c6f696..b2a653700b4 100644 --- a/tools/llvm-cxxdump/llvm-cxxdump.cpp +++ b/tools/llvm-cxxdump/llvm-cxxdump.cpp @@ -184,8 +184,9 @@ static void dumpCXXData(const ObjectFile *Obj) { ErrorOr SymNameOrErr = Sym.getName(); error(SymNameOrErr.getError()); StringRef SymName = *SymNameOrErr; - object::section_iterator SecI(Obj->section_begin()); - error(Sym.getSection(SecI)); + ErrorOr SecIOrErr = Sym.getSection(); + error(SecIOrErr.getError()); + object::section_iterator SecI = *SecIOrErr; // Skip external symbols. if (SecI == Obj->section_end()) continue; diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index e7ee3124ed7..ce12fe6bc0e 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -314,8 +314,7 @@ static void darwinPrintSymbol(MachOObjectFile *MachO, SymbolListT::iterator I, outs() << "(indirect) "; break; case MachO::N_SECT: { - section_iterator Sec = MachO->section_end(); - MachO->getSymbolSection(I->Sym.getRawDataRefImpl(), Sec); + section_iterator Sec = *MachO->getSymbolSection(I->Sym.getRawDataRefImpl()); DataRefImpl Ref = Sec->getRawDataRefImpl(); StringRef SectionName; MachO->getSectionName(Ref, SectionName); @@ -594,10 +593,11 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj, // OK, this is ELF elf_symbol_iterator SymI(I); - elf_section_iterator SecI = Obj.section_end(); - if (error(SymI->getSection(SecI))) + ErrorOr SecIOrErr = SymI->getSection(); + if (error(SecIOrErr.getError())) return '?'; + elf_section_iterator SecI = *SecIOrErr; if (SecI != Obj.section_end()) { switch (SecI->getType()) { case ELF::SHT_PROGBITS: @@ -651,9 +651,10 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) { uint32_t Characteristics = 0; if (!COFF::isReservedSectionNumber(Symb.getSectionNumber())) { - section_iterator SecI = Obj.section_end(); - if (error(SymI->getSection(SecI))) + ErrorOr SecIOrErr = SymI->getSection(); + if (error(SecIOrErr.getError())) return '?'; + section_iterator SecI = *SecIOrErr; const coff_section *Section = Obj.getCOFFSection(*SecI); Characteristics = Section->Characteristics; } @@ -701,8 +702,7 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) { case MachO::N_INDR: return 'i'; case MachO::N_SECT: { - section_iterator Sec = Obj.section_end(); - Obj.getSymbolSection(Symb, Sec); + section_iterator Sec = *Obj.getSymbolSection(Symb); DataRefImpl Ref = Sec->getRawDataRefImpl(); StringRef SectionName; Obj.getSectionName(Ref, SectionName); diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index a822266485e..53500a4bb76 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -165,10 +165,10 @@ resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym, if (std::error_code EC = ResolvedAddrOrErr.getError()) return EC; ResolvedAddr = *ResolvedAddrOrErr; - section_iterator iter(Obj->section_begin()); - if (std::error_code EC = Sym.getSection(iter)) + ErrorOr Iter = Sym.getSection(); + if (std::error_code EC = Iter.getError()) return EC; - ResolvedSection = Obj->getCOFFSection(*iter); + ResolvedSection = Obj->getCOFFSection(**Iter); return std::error_code(); } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 2c9095468be..cda28c48611 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -6436,8 +6436,7 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj, // Go back one so that SymbolAddress <= Addr. --Sym; - section_iterator SymSection = Obj->section_end(); - Sym->second.getSection(SymSection); + section_iterator SymSection = *Sym->second.getSection(); if (RelocSection == *SymSection) { // There's a valid symbol in the same section before this reference. ErrorOr NameOrErr = Sym->second.getName(); @@ -6780,8 +6779,7 @@ void llvm::printMachOUnwindInfo(const MachOObjectFile *Obj) { for (const SymbolRef &SymRef : Obj->symbols()) { // Discard any undefined or absolute symbols. They're not going to take part // in the convenience lookup for unwind info and just take up resources. - section_iterator Section = Obj->section_end(); - SymRef.getSection(Section); + section_iterator Section = *SymRef.getSection(); if (Section == Obj->section_end()) continue; diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 22f5519f500..49674e75b93 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -1225,8 +1225,9 @@ void llvm::PrintSymbolTable(const ObjectFile *o) { uint64_t Address = *AddressOrError; SymbolRef::Type Type = Symbol.getType(); uint32_t Flags = Symbol.getFlags(); - section_iterator Section = o->section_end(); - error(Symbol.getSection(Section)); + ErrorOr SectionOrErr = Symbol.getSection(); + error(SectionOrErr.getError()); + section_iterator Section = *SectionOrErr; StringRef Name; if (Type == SymbolRef::ST_Debug && Section != o->section_end()) { Section->getName(Name); diff --git a/tools/llvm-readobj/ARMWinEHPrinter.cpp b/tools/llvm-readobj/ARMWinEHPrinter.cpp index bf5ff8e1d03..650955d1d75 100644 --- a/tools/llvm-readobj/ARMWinEHPrinter.cpp +++ b/tools/llvm-readobj/ARMWinEHPrinter.cpp @@ -630,9 +630,10 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF, SW.printString("ExceptionRecord", formatSymbol(*Name, Address)); - section_iterator SI = COFF.section_end(); - if (XDataRecord->getSection(SI)) + ErrorOr SIOrErr = XDataRecord->getSection(); + if (!SIOrErr) return false; + section_iterator SI = *SIOrErr; return dumpXDataRecord(COFF, *SI, FunctionAddress, Address); } else { diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index b226e5f35b5..6b1889a66b6 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -542,8 +542,9 @@ void MachODumper::printSymbol(const SymbolRef &Symbol) { getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol); StringRef SectionName = ""; - section_iterator SecI(Obj->section_begin()); - error(Symbol.getSection(SecI)); + ErrorOr SecIOrErr = Symbol.getSection(); + error(SecIOrErr.getError()); + section_iterator SecI = *SecIOrErr; if (SecI != Obj->section_end()) error(SecI->getName(SectionName)); diff --git a/tools/llvm-readobj/Win64EHDumper.cpp b/tools/llvm-readobj/Win64EHDumper.cpp index 076f137d6ee..ffb0855606a 100644 --- a/tools/llvm-readobj/Win64EHDumper.cpp +++ b/tools/llvm-readobj/Win64EHDumper.cpp @@ -149,11 +149,8 @@ static std::error_code resolveRelocation(const Dumper::Context &Ctx, return EC; ResolvedAddress = *ResolvedAddressOrErr; - section_iterator SI = Ctx.COFF.section_begin(); - if (std::error_code EC = Symbol.getSection(SI)) - return EC; - - ResolvedSection = Ctx.COFF.getCOFFSection(*SI); + ErrorOr SI = Symbol.getSection(); + ResolvedSection = Ctx.COFF.getCOFFSection(**SI); return std::error_code(); } diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index d6423a3e693..d8699505f59 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -304,8 +304,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { // symbol in memory (rather than that in the unrelocated object file) // and use that to query the DWARFContext. if (!UseDebugObj && LoadObjects) { - object::section_iterator Sec(SymbolObj->section_end()); - Sym.getSection(Sec); + object::section_iterator Sec = *Sym.getSection(); StringRef SecName; Sec->getName(SecName); uint64_t SectionLoadAddress = -- 2.34.1