llvm.org GIT mirror llvm / 77e7778
Replace a report_fatal_error with an ErrorOr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285905 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
5 changed file(s) with 21 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
110110
111111 ErrorOr sections() const;
112112
113 Elf_Sym_Range symbols(const Elf_Shdr *Sec) const {
113 ErrorOr symbols(const Elf_Shdr *Sec) const {
114114 if (!Sec)
115115 return makeArrayRef(nullptr, nullptr);
116 auto V = getSectionContentsAsArray(Sec);
117 if (!V)
118 report_fatal_error(V.getError().message());
119 return *V;
116 return getSectionContentsAsArray(Sec);
120117 }
121118
122119 Elf_Rela_Range relas(const Elf_Shdr *Sec) const {
163160
164161 ErrorOr getSymbol(const Elf_Shdr *Sec,
165162 uint32_t Index) const {
166 Elf_Sym_Range Symbols = symbols(Sec);
163 auto SymtabOrErr = symbols(Sec);
164 if (std::error_code EC = SymtabOrErr.getError())
165 return object_error::parse_failed;
166 Elf_Sym_Range Symbols = *SymtabOrErr;
167167 if (Index >= Symbols.size())
168168 return object_error::invalid_symbol_index;
169169 return &Symbols[Index];
194194 uint32_t ELFFile::getExtendedSymbolTableIndex(
195195 const Elf_Sym *Sym, const Elf_Shdr *SymTab,
196196 ArrayRef ShndxTable) const {
197 return getExtendedSymbolTableIndex(Sym, symbols(SymTab).begin(), ShndxTable);
197 auto SymsOrErr = symbols(SymTab);
198 if (std::error_code EC = SymsOrErr.getError())
199 report_fatal_error(EC.message());
200 return getExtendedSymbolTableIndex(Sym, SymsOrErr->begin(), ShndxTable);
198201 }
199202
200203 template
506506 Result |= SymbolRef::SF_Absolute;
507507
508508 if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
509 ESym == EF.symbols(DotSymtabSec).begin() ||
510 ESym == EF.symbols(DotDynSymSec).begin())
509 ESym == (*EF.symbols(DotSymtabSec)).begin() ||
510 ESym == (*EF.symbols(DotDynSymSec)).begin())
511511 Result |= SymbolRef::SF_FormatSpecific;
512512
513513 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
352352 error(StrTableOrErr.getError());
353353 StringRef StrTable = *StrTableOrErr;
354354
355 for (const Elf_Sym &Sym : ELF->symbols(Symtab))
355 for (const Elf_Sym &Sym : unwrapOrError(ELF->symbols(Symtab)))
356356 if (Sym.st_shndx == Section && Sym.st_value == Address &&
357357 Sym.getType() == ELF::STT_FUNC) {
358358 auto NameOrErr = Sym.getName(StrTable);
245245 if (!DotSymtabSec)
246246 return;
247247 StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec));
248 Syms = Obj->symbols(DotSymtabSec);
248 Syms = unwrapOrError(Obj->symbols(DotSymtabSec));
249249 SymtabName = unwrapOrError(Obj->getSectionName(DotSymtabSec));
250250 Entries = DotSymtabSec->getEntityCount();
251251 }
34933493 const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec();
34943494 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
34953495
3496 for (const Elf_Sym &Sym : Obj->symbols(Symtab)) {
3496 for (const Elf_Sym &Sym : unwrapOrError(Obj->symbols(Symtab))) {
34973497 const Elf_Shdr *SymSec = unwrapOrError(
34983498 Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable()));
34993499 if (SymSec == &Sec)
3500 printSymbol(Obj, &Sym, Obj->symbols(Symtab).begin(), StrTable, false);
3500 printSymbol(Obj, &Sym, unwrapOrError(Obj->symbols(Symtab)).begin(),
3501 StrTable, false);
35013502 }
35023503 }
35033504
144144 StringRef StrTable = *StrTableOrErr;
145145
146146 bool IsFirstSym = true;
147 for (const Elf_Sym &Sym : Obj.symbols(Symtab)) {
147 auto SymtabOrErr = Obj.symbols(Symtab);
148 if (std::error_code EC = SymtabOrErr.getError())
149 return EC;
150 for (const Elf_Sym &Sym : *SymtabOrErr) {
148151 if (IsFirstSym) {
149152 IsFirstSym = false;
150153 continue;