llvm.org GIT mirror llvm / 497f200
replace a report_fatal_error with a ErrorOr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285910 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
3 changed file(s) with 21 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
146146 }
147147
148148 ErrorOr getSectionStringTable(Elf_Shdr_Range Sections) const;
149 uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
150 const Elf_Shdr *SymTab,
151 ArrayRef ShndxTable) const;
152 uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
153 const Elf_Sym *FirstSym,
154 ArrayRef ShndxTable) const;
149 ErrorOr
150 getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
151 ArrayRef ShndxTable) const;
152 ErrorOr
153 getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Sym *FirstSym,
154 ArrayRef ShndxTable) const;
155155 const Elf_Ehdr *getHeader() const { return Header; }
156156 ErrorOr getSection(const Elf_Sym *Sym,
157157 const Elf_Shdr *SymTab,
191191 }
192192
193193 template
194 uint32_t ELFFile::getExtendedSymbolTableIndex(
194 ErrorOr ELFFile::getExtendedSymbolTableIndex(
195195 const Elf_Sym *Sym, const Elf_Shdr *SymTab,
196196 ArrayRef ShndxTable) const {
197197 auto SymsOrErr = symbols(SymTab);
198198 if (std::error_code EC = SymsOrErr.getError())
199 report_fatal_error(EC.message());
199 return EC;
200200 return getExtendedSymbolTableIndex(Sym, SymsOrErr->begin(), ShndxTable);
201201 }
202202
203203 template
204 uint32_t ELFFile::getExtendedSymbolTableIndex(
204 ErrorOr ELFFile::getExtendedSymbolTableIndex(
205205 const Elf_Sym *Sym, const Elf_Sym *FirstSym,
206206 ArrayRef ShndxTable) const {
207207 assert(Sym->st_shndx == ELF::SHN_XINDEX);
208208 unsigned Index = Sym - FirstSym;
209209 if (Index >= ShndxTable.size())
210 report_fatal_error("Invalid symbol table index");
210 return object_error::parse_failed;
211211 // The size of the table was checked in getSHNDXTable.
212212 return ShndxTable[Index];
213213 }
221221 (Index >= ELF::SHN_LORESERVE && Index != ELF::SHN_XINDEX))
222222 return nullptr;
223223
224 if (Index == ELF::SHN_XINDEX)
225 Index = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
224 if (Index == ELF::SHN_XINDEX) {
225 auto ErrorOrIndex = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
226 if (std::error_code EC = ErrorOrIndex.getError())
227 return EC;
228 Index = *ErrorOrIndex;
229 }
226230
227231 auto SectionsOrErr = sections();
228232 if (std::error_code EC = SectionsOrErr.getError())
5959
6060 RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \
6161 RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s
62 INVALID-EXT-SYMTAB-INDEX: Invalid symbol table index
62 INVALID-EXT-SYMTAB-INDEX: Invalid data was encountered while parsing the file.
6363
6464 RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-i386 2>&1 | \
6565 RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
716716 SectionName = "Reserved";
717717 else {
718718 if (SectionIndex == SHN_XINDEX)
719 SectionIndex =
720 Obj.getExtendedSymbolTableIndex(Symbol, FirstSym, ShndxTable);
719 SectionIndex = unwrapOrError(
720 Obj.getExtendedSymbolTableIndex(Symbol, FirstSym, ShndxTable));
721721 const typename ELFO::Elf_Shdr *Sec =
722722 unwrapOrError(Obj.getSection(SectionIndex));
723723 SectionName = unwrapOrError(Obj.getSectionName(Sec));
27362736 case ELF::SHN_COMMON:
27372737 return "COM";
27382738 case ELF::SHN_XINDEX:
2739 SectionIndex = Obj->getExtendedSymbolTableIndex(
2740 Symbol, FirstSym, this->dumper()->getShndxTable());
2739 SectionIndex = unwrapOrError(Obj->getExtendedSymbolTableIndex(
2740 Symbol, FirstSym, this->dumper()->getShndxTable()));
27412741 default:
27422742 // Find if:
27432743 // Processor specific