Convert getSymbolSection to return an ErrorOr.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 7 Aug 2015 23:27:14 +0000 (23:27 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 7 Aug 2015 23:27:14 +0000 (23:27 +0000)
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

22 files changed:
include/llvm/Object/COFF.h
include/llvm/Object/ELFObjectFile.h
include/llvm/Object/MachO.h
include/llvm/Object/ObjectFile.h
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
lib/Object/COFFObjectFile.cpp
lib/Object/MachOObjectFile.cpp
lib/Object/Object.cpp
lib/Object/ObjectFile.cpp
tools/dsymutil/MachODebugMapParser.cpp
tools/llvm-cxxdump/llvm-cxxdump.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-objdump/COFFDump.cpp
tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/ARMWinEHPrinter.cpp
tools/llvm-readobj/MachODumper.cpp
tools/llvm-readobj/Win64EHDumper.cpp
tools/llvm-rtdyld/llvm-rtdyld.cpp

index 025a9dbc6bc0b20b6b820b0e625d9ebfd022a5bd..ce9042fd3ab2f90dae86519349d183913d5d3691 100644 (file)
@@ -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;
   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<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
   void moveSectionNext(DataRefImpl &Sec) const override;
   std::error_code getSectionName(DataRefImpl Sec,
                                  StringRef &Res) const override;
   void moveSectionNext(DataRefImpl &Sec) const override;
   std::error_code getSectionName(DataRefImpl Sec,
                                  StringRef &Res) const override;
index c3483378eb9e345e6a9978587c2ef1dfa30bce18..b63eaac52d2171963a9f306ce8627d098295e785 100644 (file)
@@ -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;
   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<section_iterator> getSymbolSection(const Elf_Sym *Symb) const;
+  ErrorOr<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
 
   void moveSectionNext(DataRefImpl &Sec) const override;
   std::error_code getSectionName(DataRefImpl Sec,
 
   void moveSectionNext(DataRefImpl &Sec) const override;
   std::error_code getSectionName(DataRefImpl Sec,
@@ -505,11 +504,11 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
-section_iterator
+ErrorOr<section_iterator>
 ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym) const {
   ErrorOr<const Elf_Shdr *> ESecOrErr = EF.getSection(ESym);
   if (std::error_code EC = ESecOrErr.getError())
 ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym) const {
   ErrorOr<const Elf_Shdr *> 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)
 
   const Elf_Shdr *ESec = *ESecOrErr;
   if (!ESec)
@@ -521,11 +520,9 @@ ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym) const {
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
-std::error_code
-ELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb,
-                                      section_iterator &Res) const {
-  Res = getSymbolSection(getSymbol(Symb));
-  return std::error_code();
+ErrorOr<section_iterator>
+ELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb) const {
+  return getSymbolSection(getSymbol(Symb));
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
index 489ecef5c99616a31ab79a2deaa52e839d32b849..47d018d3a5ea6e9c72dbeefafabbec8e244222a1 100644 (file)
@@ -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;
   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<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
   unsigned getSymbolSectionID(SymbolRef Symb) const;
   unsigned getSectionID(SectionRef Sec) const;
 
   unsigned getSymbolSectionID(SymbolRef Symb) const;
   unsigned getSectionID(SectionRef Sec) const;
 
index 8dd5256262182419c2474b39cede836e30697c64..08131908e06783a78a56db6698459eda9faf1985 100644 (file)
@@ -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.
 
   /// @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<section_iterator> getSection() const;
 
   const ObjectFile *getObject() 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 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<section_iterator>
+  getSymbolSection(DataRefImpl Symb) const = 0;
 
   // Same as above for SectionRef.
   friend class SectionRef;
 
   // Same as above for SectionRef.
   friend class SectionRef;
@@ -323,8 +323,8 @@ inline uint64_t SymbolRef::getCommonSize() const {
   return getObject()->getCommonSymbolSize(getRawDataRefImpl());
 }
 
   return getObject()->getCommonSymbolSize(getRawDataRefImpl());
 }
 
-inline std::error_code SymbolRef::getSection(section_iterator &Result) const {
-  return getObject()->getSymbolSection(getRawDataRefImpl(), Result);
+inline ErrorOr<section_iterator> SymbolRef::getSection() const {
+  return getObject()->getSymbolSection(getRawDataRefImpl());
 }
 
 inline SymbolRef::Type SymbolRef::getType() const {
 }
 
 inline SymbolRef::Type SymbolRef::getType() const {
index 408214339a8dab2ae04945c455bc9f924f48412e..4316934df0497380d8192329b5a3865f60aa1935 100644 (file)
@@ -685,7 +685,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
           }
           SymAddr = *SymAddrOrErr;
           // Also remember what section this symbol is in for later
           }
           SymAddr = *SymAddrOrErr;
           // Also remember what section this symbol is in for later
-          Sym->getSection(RSec);
+          RSec = *Sym->getSection();
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
           // MachO also has relocations that point to sections and
           // scattered relocations.
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
           // MachO also has relocations that point to sections and
           // scattered relocations.
index 24495b21d4584a5c9ede5be8e01e4de1d43f8253..2ce337dc83de3313ded6bc01e89ee4dbad1a0c1e 100644 (file)
@@ -164,8 +164,9 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
         ErrorOr<StringRef> NameOrErr = I->getName();
         Check(NameOrErr.getError());
         StringRef Name = *NameOrErr;
         ErrorOr<StringRef> NameOrErr = I->getName();
         Check(NameOrErr.getError());
         StringRef Name = *NameOrErr;
-        section_iterator SI = Obj.section_end();
-        Check(I->getSection(SI));
+        ErrorOr<section_iterator> SIOrErr = I->getSection();
+        Check(SIOrErr.getError());
+        section_iterator SI = *SIOrErr;
         if (SI == Obj.section_end())
           continue;
         uint64_t SectOffset;
         if (SI == Obj.section_end())
           continue;
         uint64_t SectOffset;
index a93c3d3098cd64618d2c8b0fe0302cd497c18955..16612c146dd0bf0581c717b26d2694ddfcd1ad1a 100644 (file)
@@ -845,8 +845,9 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
       if (Rel.Addend != (int64_t)TargetSymbolOffset)
         continue;
 
       if (Rel.Addend != (int64_t)TargetSymbolOffset)
         continue;
 
-      section_iterator tsi(Obj.section_end());
-      check(TargetSymbol->getSection(tsi));
+      ErrorOr<section_iterator> 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;
       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.
       // 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");
       if (si == Obj.section_end())
         llvm_unreachable("Symbol section not found, bad object file format!");
       DEBUG(dbgs() << "\t\tThis is section symbol\n");
index 408227eb0f218c5dae4a2670976bfa3091036cfc..8b7d06930a1c68178ac6ca98616de695adc7a7dd 100644 (file)
@@ -119,8 +119,7 @@ public:
     symbol_iterator Symbol = RelI->getSymbol();
     if (Symbol == Obj.symbol_end())
       report_fatal_error("Unknown symbol in relocation");
     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();
 
     // If there is no section, this must be an external reference.
     const bool IsExtern = SecI == Obj.section_end();
 
index fa6aa4ced392572ae740cf4cfe18b22f3c195798..d3f604a8d359154ab260291a73abaa9ec988e898 100644 (file)
@@ -238,21 +238,17 @@ uint64_t COFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Ref) const {
   return Symb.getValue();
 }
 
   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);
   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 {
 }
 
 unsigned COFFObjectFile::getSymbolSectionID(SymbolRef Sym) const {
index 05900630c75c52f0bad28152fe45f5266dc0fc29..d1faf7be3af8dd26ae00160af07acb727366b1ba 100644 (file)
@@ -445,22 +445,18 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
   return Result;
 }
 
   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;
 
   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 {
 }
 
 unsigned MachOObjectFile::getSymbolSectionID(SymbolRef Sym) const {
index 5c4b7a67b2ad0e763d43ae13b3cdf8ae44ba44de..b44c1a16fd0846b9dcdc81158cd343708fbfd7f4 100644 (file)
@@ -98,8 +98,10 @@ void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
 
 void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
                                  LLVMSymbolIteratorRef Sym) {
 
 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());
     report_fatal_error(ec.message());
+  *unwrap(Sect) = *SecOrErr;
 }
 
 // ObjectFile Symbol iterators
 }
 
 // ObjectFile Symbol iterators
index f82edae89bc6d98d41cd69389b61003b34fe83c8..d12dc411361c80fa9b6fdb35da361f8a6c69b786 100644 (file)
@@ -29,10 +29,10 @@ ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source)
     : SymbolicFile(Type, Source) {}
 
 bool SectionRef::containsSymbol(SymbolRef S) const {
     : 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 false;
-  return *this == *SymSec;
+  return *this == **SymSec;
 }
 
 uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const {
 }
 
 uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const {
index cd427cb1d94a820ae47f308f7580397b103961d9..bd29f004b0973f2de122b53645aed7df4ff8b053 100644 (file)
@@ -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.
     // 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<section_iterator> SectionOrErr = Sym.getSection();
+    if (!SectionOrErr)
+      continue;
+    Section = *SectionOrErr;
+    if (Section == MainBinary.section_end() || Section->isText())
       continue;
     uint64_t Addr = Sym.getValue();
     ErrorOr<StringRef> NameOrErr = Sym.getName();
       continue;
     uint64_t Addr = Sym.getValue();
     ErrorOr<StringRef> NameOrErr = Sym.getName();
index ee905c6f696bb41fb4aceecbd730c2647fe4ffac..b2a653700b470ae9d5d897e90f557223af5a5d04 100644 (file)
@@ -184,8 +184,9 @@ static void dumpCXXData(const ObjectFile *Obj) {
     ErrorOr<StringRef> SymNameOrErr = Sym.getName();
     error(SymNameOrErr.getError());
     StringRef SymName = *SymNameOrErr;
     ErrorOr<StringRef> SymNameOrErr = Sym.getName();
     error(SymNameOrErr.getError());
     StringRef SymName = *SymNameOrErr;
-    object::section_iterator SecI(Obj->section_begin());
-    error(Sym.getSection(SecI));
+    ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection();
+    error(SecIOrErr.getError());
+    object::section_iterator SecI = *SecIOrErr;
     // Skip external symbols.
     if (SecI == Obj->section_end())
       continue;
     // Skip external symbols.
     if (SecI == Obj->section_end())
       continue;
index e7ee3124ed731f8531856d32effe48557e0fddd1..ce12fe6bc0e1c85663ee6e67f82b6187734aecdf 100644 (file)
@@ -314,8 +314,7 @@ static void darwinPrintSymbol(MachOObjectFile *MachO, SymbolListT::iterator I,
     outs() << "(indirect) ";
     break;
   case MachO::N_SECT: {
     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);
     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);
 
   // OK, this is ELF
   elf_symbol_iterator SymI(I);
 
-  elf_section_iterator SecI = Obj.section_end();
-  if (error(SymI->getSection(SecI)))
+  ErrorOr<elf_section_iterator> SecIOrErr = SymI->getSection();
+  if (error(SecIOrErr.getError()))
     return '?';
 
     return '?';
 
+  elf_section_iterator SecI = *SecIOrErr;
   if (SecI != Obj.section_end()) {
     switch (SecI->getType()) {
     case ELF::SHT_PROGBITS:
   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())) {
 
   uint32_t Characteristics = 0;
   if (!COFF::isReservedSectionNumber(Symb.getSectionNumber())) {
-    section_iterator SecI = Obj.section_end();
-    if (error(SymI->getSection(SecI)))
+    ErrorOr<section_iterator> SecIOrErr = SymI->getSection();
+    if (error(SecIOrErr.getError()))
       return '?';
       return '?';
+    section_iterator SecI = *SecIOrErr;
     const coff_section *Section = Obj.getCOFFSection(*SecI);
     Characteristics = Section->Characteristics;
   }
     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: {
   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);
     DataRefImpl Ref = Sec->getRawDataRefImpl();
     StringRef SectionName;
     Obj.getSectionName(Ref, SectionName);
index a822266485ed92e84072c44dae3c7efcfe8ab824..53500a4bb767649c4f8c594155cebc5e9339cb7e 100644 (file)
@@ -165,10 +165,10 @@ resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
   if (std::error_code EC = ResolvedAddrOrErr.getError())
     return EC;
   ResolvedAddr = *ResolvedAddrOrErr;
   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<section_iterator> Iter = Sym.getSection();
+  if (std::error_code EC = Iter.getError())
     return EC;
     return EC;
-  ResolvedSection = Obj->getCOFFSection(*iter);
+  ResolvedSection = Obj->getCOFFSection(**Iter);
   return std::error_code();
 }
 
   return std::error_code();
 }
 
index 2c9095468be52a24d48c4c478dd1e14e0424e12a..cda28c48611616def0aba2782e40b7244cb12c7e 100644 (file)
@@ -6436,8 +6436,7 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
   // Go back one so that SymbolAddress <= Addr.
   --Sym;
 
   // 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<StringRef> NameOrErr = Sym->second.getName();
   if (RelocSection == *SymSection) {
     // There's a valid symbol in the same section before this reference.
     ErrorOr<StringRef> 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.
   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;
 
     if (Section == Obj->section_end())
       continue;
 
index 22f5519f5008a6a598d0256dfb7027a70a930b62..49674e75b9392b9ba072608cf9ef0778d1ef40fe 100644 (file)
@@ -1225,8 +1225,9 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
     uint64_t Address = *AddressOrError;
     SymbolRef::Type Type = Symbol.getType();
     uint32_t Flags = Symbol.getFlags();
     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<section_iterator> SectionOrErr = Symbol.getSection();
+    error(SectionOrErr.getError());
+    section_iterator Section = *SectionOrErr;
     StringRef Name;
     if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
       Section->getName(Name);
     StringRef Name;
     if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
       Section->getName(Name);
index bf5ff8e1d03101e68c708c5c09048b98c0c77165..650955d1d75c053c2266b0fabd1ebba671591de5 100644 (file)
@@ -630,9 +630,10 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
 
     SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
 
 
     SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
 
-    section_iterator SI = COFF.section_end();
-    if (XDataRecord->getSection(SI))
+    ErrorOr<section_iterator> SIOrErr = XDataRecord->getSection();
+    if (!SIOrErr)
       return false;
       return false;
+    section_iterator SI = *SIOrErr;
 
     return dumpXDataRecord(COFF, *SI, FunctionAddress, Address);
   } else {
 
     return dumpXDataRecord(COFF, *SI, FunctionAddress, Address);
   } else {
index b226e5f35b55434166139957a3ae3ea0698f5fe3..6b1889a66b699c288a911ce58eba648c133d3e4b 100644 (file)
@@ -542,8 +542,9 @@ void MachODumper::printSymbol(const SymbolRef &Symbol) {
   getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
 
   StringRef SectionName = "";
   getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
 
   StringRef SectionName = "";
-  section_iterator SecI(Obj->section_begin());
-  error(Symbol.getSection(SecI));
+  ErrorOr<section_iterator> SecIOrErr = Symbol.getSection();
+  error(SecIOrErr.getError());
+  section_iterator SecI = *SecIOrErr;
   if (SecI != Obj->section_end())
     error(SecI->getName(SectionName));
 
   if (SecI != Obj->section_end())
     error(SecI->getName(SectionName));
 
index 076f137d6ee7f7876d69720728614c40428b76e2..ffb0855606a5cbb12196ef97de5ffc8aa49cbf74 100644 (file)
@@ -149,11 +149,8 @@ static std::error_code resolveRelocation(const Dumper::Context &Ctx,
     return EC;
   ResolvedAddress = *ResolvedAddressOrErr;
 
     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<section_iterator> SI = Symbol.getSection();
+  ResolvedSection = Ctx.COFF.getCOFFSection(**SI);
   return std::error_code();
 }
 
   return std::error_code();
 }
 
index d6423a3e693c21660f102797ed8e8562a020c7d5..d8699505f59eda5d264b53ca2e74be03ac0f62d8 100644 (file)
@@ -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) {
         // 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 =
           StringRef SecName;
           Sec->getName(SecName);
           uint64_t SectionLoadAddress =