llvm.org GIT mirror llvm / d1f0655
Split getSection in two. This will allow avoiding repeated error checking in a few cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285874 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
1 changed file(s) with 19 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
178178 typedef ELFFile> ELF64BEFile;
179179
180180 template
181 inline ErrorOr
182 getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
183 if (Index >= Sections.size())
184 return object_error::invalid_section_index;
185 return &Sections[Index];
186 }
187
188 template
181189 uint32_t ELFFile::getExtendedSymbolTableIndex(
182190 const Elf_Sym *Sym, const Elf_Shdr *SymTab,
183191 ArrayRef ShndxTable) const {
201209 ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
202210 ArrayRef ShndxTable) const {
203211 uint32_t Index = Sym->st_shndx;
212 if (Index == ELF::SHN_UNDEF ||
213 (Index >= ELF::SHN_LORESERVE && Index != ELF::SHN_XINDEX))
214 return nullptr;
215
204216 if (Index == ELF::SHN_XINDEX)
205 return getSection(getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable));
206
207 if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
208 return nullptr;
209 return getSection(Sym->st_shndx);
217 Index = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
218
219 auto SectionsOrErr = sections();
220 if (std::error_code EC = SectionsOrErr.getError())
221 return EC;
222 return object::getSection(*SectionsOrErr, Index);
210223 }
211224
212225 template
386399 auto TableOrErr = sections();
387400 if (std::error_code EC = TableOrErr.getError())
388401 return EC;
389 ArrayRef Table = *TableOrErr;
390 if (Index >= Table.size())
391 return object_error::invalid_section_index;
392 return &Table[Index];
402 return object::getSection(*TableOrErr, Index);
393403 }
394404
395405 template