llvm.org GIT mirror llvm / 9421b70
Add lower level versions of some functions. This adds versions of getSectionIndex, getSection and getSymbol that instead of a Elf_Shdr take the content of that section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285932 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
1 changed file(s) with 32 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
149149 const Elf_Ehdr *getHeader() const { return Header; }
150150 ErrorOr getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
151151 ArrayRef ShndxTable) const;
152 ErrorOr getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms,
153 ArrayRef ShndxTable) const;
152154 ErrorOr getSection(const Elf_Sym *Sym,
153155 const Elf_Shdr *SymTab,
156 ArrayRef ShndxTable) const;
157 ErrorOr getSection(const Elf_Sym *Sym, Elf_Sym_Range Symtab,
154158 ArrayRef ShndxTable) const;
155159 ErrorOr getSection(uint32_t Index) const;
156160
198202 auto SymsOrErr = symbols(SymTab);
199203 if (std::error_code EC = SymsOrErr.getError())
200204 return EC;
201
205 return getSectionIndex(Sym, *SymsOrErr, ShndxTable);
206 }
207
208 template
209 ErrorOr
210 ELFFile::getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms,
211 ArrayRef ShndxTable) const {
202212 uint32_t Index = Sym->st_shndx;
203213 if (Index == ELF::SHN_XINDEX) {
204214 auto ErrorOrIndex = object::getExtendedSymbolTableIndex(
205 Sym, SymsOrErr->begin(), ShndxTable);
215 Sym, Syms.begin(), ShndxTable);
206216 if (std::error_code EC = ErrorOrIndex.getError())
207217 return EC;
208218 return *ErrorOrIndex;
216226 ErrorOr
217227 ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
218228 ArrayRef ShndxTable) const {
219 ErrorOr IndexOrErr = getSectionIndex(Sym, SymTab, ShndxTable);
229 auto SymsOrErr = symbols(SymTab);
230 if (std::error_code EC = SymsOrErr.getError())
231 return EC;
232 return getSection(Sym, *SymsOrErr, ShndxTable);
233 }
234
235 template
236 ErrorOr
237 ELFFile::getSection(const Elf_Sym *Sym, Elf_Sym_Range Symbols,
238 ArrayRef ShndxTable) const {
239 ErrorOr IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
220240 if (std::error_code EC = IndexOrErr.getError())
221241 return EC;
222242 uint32_t Index = *IndexOrErr;
229249 }
230250
231251 template
252 inline ErrorOr
253 getSymbol(typename ELFT::SymRange Symbols, uint32_t Index) {
254 if (Index >= Symbols.size())
255 return object_error::invalid_symbol_index;
256 return &Symbols[Index];
257 }
258
259 template
232260 ErrorOr
233261 ELFFile::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
234262 auto SymtabOrErr = symbols(Sec);
235263 if (std::error_code EC = SymtabOrErr.getError())
236264 return EC;
237 Elf_Sym_Range Symbols = *SymtabOrErr;
238 if (Index >= Symbols.size())
239 return object_error::invalid_symbol_index;
240 return &Symbols[Index];
265 return object::getSymbol(*SymtabOrErr, Index);
241266 }
242267
243268 template