llvm.org GIT mirror llvm / 58c4c96
Split out a getSectionIndex. That code is currently duplicated in lld. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285915 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
1 changed file(s) with 22 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
153153 getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Sym *FirstSym,
154154 ArrayRef ShndxTable) const;
155155 const Elf_Ehdr *getHeader() const { return Header; }
156 ErrorOr getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
157 ArrayRef ShndxTable) const;
156158 ErrorOr getSection(const Elf_Sym *Sym,
157159 const Elf_Shdr *SymTab,
158160 ArrayRef ShndxTable) const;
213215 }
214216
215217 template
216 ErrorOr
217 ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
218 ArrayRef ShndxTable) const {
218 ErrorOr
219 ELFFile::getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
220 ArrayRef ShndxTable) const {
219221 uint32_t Index = Sym->st_shndx;
220 if (Index == ELF::SHN_UNDEF ||
221 (Index >= ELF::SHN_LORESERVE && Index != ELF::SHN_XINDEX))
222 return nullptr;
223
224222 if (Index == ELF::SHN_XINDEX) {
225223 auto ErrorOrIndex = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
226224 if (std::error_code EC = ErrorOrIndex.getError())
227225 return EC;
228 Index = *ErrorOrIndex;
229 }
230
226 return *ErrorOrIndex;
227 }
228 if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
229 return 0;
230 return Index;
231 }
232
233 template
234 ErrorOr
235 ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
236 ArrayRef ShndxTable) const {
237 ErrorOr IndexOrErr = getSectionIndex(Sym, SymTab, ShndxTable);
238 if (std::error_code EC = IndexOrErr.getError())
239 return EC;
240 uint32_t Index = *IndexOrErr;
241 if (Index == 0)
242 return nullptr;
231243 auto SectionsOrErr = sections();
232244 if (std::error_code EC = SectionsOrErr.getError())
233245 return EC;