llvm.org GIT mirror llvm / 28bec63
Fix the name of the iterator functions to match the coding standards. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241074 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
6 changed file(s) with 83 addition(s) and 84 deletion(s). Raw diff Collapse all Expand all
263263 Header->getDataEncoding() == ELF::ELFDATA2LSB;
264264 }
265265
266 Elf_Shdr_Iter begin_sections() const;
267 Elf_Shdr_Iter end_sections() const;
266 Elf_Shdr_Iter section_begin() const;
267 Elf_Shdr_Iter section_end() const;
268268 Elf_Shdr_Range sections() const {
269 return make_range(begin_sections(), end_sections());
270 }
271
272 const Elf_Sym *begin_symbols() const;
273 const Elf_Sym *end_symbols() const;
269 return make_range(section_begin(), section_end());
270 }
271
272 const Elf_Sym *symbol_begin() const;
273 const Elf_Sym *symbol_end() const;
274274 Elf_Sym_Range symbols() const {
275 return make_range(begin_symbols(), end_symbols());
276 }
277
278 Elf_Dyn_Iter begin_dynamic_table() const;
275 return make_range(symbol_begin(), symbol_end());
276 }
277
278 Elf_Dyn_Iter dynamic_table_begin() const;
279279 /// \param NULLEnd use one past the first DT_NULL entry as the end instead of
280280 /// the section size.
281 Elf_Dyn_Iter end_dynamic_table(bool NULLEnd = false) const;
281 Elf_Dyn_Iter dynamic_table_end(bool NULLEnd = false) const;
282282 Elf_Dyn_Range dynamic_table(bool NULLEnd = false) const {
283 return make_range(begin_dynamic_table(), end_dynamic_table(NULLEnd));
284 }
285
286 const Elf_Sym *begin_dynamic_symbols() const {
283 return make_range(dynamic_table_begin(), dynamic_table_end(NULLEnd));
284 }
285
286 const Elf_Sym *dynamic_symbol_begin() const {
287287 if (!DynSymRegion.Addr)
288288 return nullptr;
289289 if (DynSymRegion.EntSize != sizeof(Elf_Sym))
291291 return reinterpret_cast(DynSymRegion.Addr);
292292 }
293293
294 const Elf_Sym *end_dynamic_symbols() const {
294 const Elf_Sym *dynamic_symbol_end() const {
295295 if (!DynSymRegion.Addr)
296296 return nullptr;
297297 return reinterpret_cast(
299299 }
300300
301301 Elf_Sym_Range dynamic_symbols() const {
302 return make_range(begin_dynamic_symbols(), end_dynamic_symbols());
303 }
304
305 Elf_Rela_Iter begin_dyn_rela() const {
302 return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
303 }
304
305 Elf_Rela_Iter dyn_rela_begin() const {
306306 if (DynRelaRegion.Addr)
307307 return Elf_Rela_Iter(DynRelaRegion.EntSize,
308308 (const char *)DynRelaRegion.Addr);
309309 return Elf_Rela_Iter(0, nullptr);
310310 }
311311
312 Elf_Rela_Iter end_dyn_rela() const {
312 Elf_Rela_Iter dyn_rela_end() const {
313313 if (DynRelaRegion.Addr)
314314 return Elf_Rela_Iter(
315315 DynRelaRegion.EntSize,
317317 return Elf_Rela_Iter(0, nullptr);
318318 }
319319
320 Elf_Rela_Iter begin_rela(const Elf_Shdr *sec) const {
320 Elf_Rela_Iter rela_begin(const Elf_Shdr *sec) const {
321321 return Elf_Rela_Iter(sec->sh_entsize,
322322 (const char *)(base() + sec->sh_offset));
323323 }
324324
325 Elf_Rela_Iter end_rela(const Elf_Shdr *sec) const {
325 Elf_Rela_Iter rela_end(const Elf_Shdr *sec) const {
326326 return Elf_Rela_Iter(
327327 sec->sh_entsize,
328328 (const char *)(base() + sec->sh_offset + sec->sh_size));
329329 }
330330
331 Elf_Rel_Iter begin_rel(const Elf_Shdr *sec) const {
331 Elf_Rel_Iter rel_begin(const Elf_Shdr *sec) const {
332332 return Elf_Rel_Iter(sec->sh_entsize,
333333 (const char *)(base() + sec->sh_offset));
334334 }
335335
336 Elf_Rel_Iter end_rel(const Elf_Shdr *sec) const {
336 Elf_Rel_Iter rel_end(const Elf_Shdr *sec) const {
337337 return Elf_Rel_Iter(sec->sh_entsize,
338338 (const char *)(base() + sec->sh_offset + sec->sh_size));
339339 }
341341 /// \brief Iterate over program header table.
342342 typedef ELFEntityIterator Elf_Phdr_Iter;
343343
344 Elf_Phdr_Iter begin_program_headers() const {
344 Elf_Phdr_Iter program_header_begin() const {
345345 return Elf_Phdr_Iter(Header->e_phentsize,
346346 (const char*)base() + Header->e_phoff);
347347 }
348348
349 Elf_Phdr_Iter end_program_headers() const {
349 Elf_Phdr_Iter program_header_end() const {
350350 return Elf_Phdr_Iter(Header->e_phentsize,
351351 (const char*)base() +
352352 Header->e_phoff +
477477 template
478478 const typename ELFFile::Elf_Sym *
479479 ELFFile::getSymbol(uint32_t Index) const {
480 return &*(begin_symbols() + Index);
480 return &*(symbol_begin() + Index);
481481 }
482482
483483 template
691691 }
692692
693693 // Scan program headers.
694 for (Elf_Phdr_Iter PhdrI = begin_program_headers(),
695 PhdrE = end_program_headers();
694 for (Elf_Phdr_Iter PhdrI = program_header_begin(),
695 PhdrE = program_header_end();
696696 PhdrI != PhdrE; ++PhdrI) {
697697 if (PhdrI->p_type == ELF::PT_DYNAMIC) {
698698 DynamicRegion.Addr = base() + PhdrI->p_offset;
703703 }
704704
705705 // Scan dynamic table.
706 for (Elf_Dyn_Iter DynI = begin_dynamic_table(), DynE = end_dynamic_table();
707 DynI != DynE; ++DynI) {
706 for (Elf_Dyn_Iter DynI = dynamic_table_begin(), DynE = dynamic_table_end();
707 DynI != DynE; ++DynI) {
708708 switch (DynI->d_tag) {
709709 case ELF::DT_RELA: {
710710 uint64_t VBase = 0;
711711 const uint8_t *FBase = nullptr;
712 for (Elf_Phdr_Iter PhdrI = begin_program_headers(),
713 PhdrE = end_program_headers();
714 PhdrI != PhdrE; ++PhdrI) {
712 for (Elf_Phdr_Iter PhdrI = program_header_begin(),
713 PhdrE = program_header_end();
714 PhdrI != PhdrE; ++PhdrI) {
715715 if (PhdrI->p_type != ELF::PT_LOAD)
716716 continue;
717717 if (DynI->getPtr() >= PhdrI->p_vaddr &&
750750 }
751751
752752 template
753 typename ELFFile::Elf_Shdr_Iter ELFFile::begin_sections() const {
753 typename ELFFile::Elf_Shdr_Iter ELFFile::section_begin() const {
754754 return Elf_Shdr_Iter(Header->e_shentsize,
755755 (const char *)base() + Header->e_shoff);
756756 }
757757
758758 template
759 typename ELFFile::Elf_Shdr_Iter ELFFile::end_sections() const {
759 typename ELFFile::Elf_Shdr_Iter ELFFile::section_end() const {
760760 return Elf_Shdr_Iter(Header->e_shentsize,
761761 (const char *)base() + Header->e_shoff +
762762 (getNumSections() * Header->e_shentsize));
763763 }
764764
765765 template
766 const typename ELFFile::Elf_Sym *ELFFile::begin_symbols() const {
766 const typename ELFFile::Elf_Sym *ELFFile::symbol_begin() const {
767767 if (!dot_symtab_sec)
768768 return nullptr;
769769 if (dot_symtab_sec->sh_entsize != sizeof(Elf_Sym))
772772 }
773773
774774 template
775 const typename ELFFile::Elf_Sym *ELFFile::end_symbols() const {
775 const typename ELFFile::Elf_Sym *ELFFile::symbol_end() const {
776776 if (!dot_symtab_sec)
777777 return nullptr;
778778 return reinterpret_cast(base() + dot_symtab_sec->sh_offset +
781781
782782 template
783783 typename ELFFile::Elf_Dyn_Iter
784 ELFFile::begin_dynamic_table() const {
784 ELFFile::dynamic_table_begin() const {
785785 if (DynamicRegion.Addr)
786786 return Elf_Dyn_Iter(DynamicRegion.EntSize,
787787 (const char *)DynamicRegion.Addr);
790790
791791 template
792792 typename ELFFile::Elf_Dyn_Iter
793 ELFFile::end_dynamic_table(bool NULLEnd) const {
793 ELFFile::dynamic_table_end(bool NULLEnd) const {
794794 if (!DynamicRegion.Addr)
795795 return Elf_Dyn_Iter(0, nullptr);
796796 Elf_Dyn_Iter Ret(DynamicRegion.EntSize,
797797 (const char *)DynamicRegion.Addr + DynamicRegion.Size);
798798
799799 if (NULLEnd) {
800 Elf_Dyn_Iter Start = begin_dynamic_table();
800 Elf_Dyn_Iter Start = dynamic_table_begin();
801801 while (Start != Ret && Start->getTag() != ELF::DT_NULL)
802802 ++Start;
803803
489489 Result |= SymbolRef::SF_Absolute;
490490
491491 if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
492 ESym == EF.begin_symbols() || ESym == EF.begin_dynamic_symbols())
492 ESym == EF.symbol_begin() || ESym == EF.dynamic_symbol_begin())
493493 Result |= SymbolRef::SF_FormatSpecific;
494494
495495 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
616616 relocation_iterator
617617 ELFObjectFile::section_rel_begin(DataRefImpl Sec) const {
618618 DataRefImpl RelData;
619 uintptr_t SHT = reinterpret_cast(EF.begin_sections().get());
619 uintptr_t SHT = reinterpret_cast(EF.section_begin().get());
620620 RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize;
621621 RelData.d.b = 0;
622622 return relocation_iterator(RelocationRef(RelData, this));
626626 relocation_iterator
627627 ELFObjectFile::section_rel_end(DataRefImpl Sec) const {
628628 DataRefImpl RelData;
629 uintptr_t SHT = reinterpret_cast(EF.begin_sections().get());
629 uintptr_t SHT = reinterpret_cast(EF.section_begin().get());
630630 const Elf_Shdr *S = reinterpret_cast(Sec.p);
631631 RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize;
632632 if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
677677 default:
678678 report_fatal_error("Invalid symbol table section type!");
679679 case ELF::SHT_SYMTAB:
680 SymbolData = toDRI(EF.begin_symbols() + symbolIdx, false);
680 SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false);
681681 break;
682682 case ELF::SHT_DYNSYM:
683 SymbolData = toDRI(EF.begin_dynamic_symbols() + symbolIdx, true);
683 SymbolData = toDRI(EF.dynamic_symbol_begin() + symbolIdx, true);
684684 break;
685685 }
686686
781781
782782 template
783783 basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const {
784 DataRefImpl Sym = toDRI(EF.begin_symbols(), false);
784 DataRefImpl Sym = toDRI(EF.symbol_begin(), false);
785785 return basic_symbol_iterator(SymbolRef(Sym, this));
786786 }
787787
788788 template
789789 basic_symbol_iterator ELFObjectFile::symbol_end_impl() const {
790 DataRefImpl Sym = toDRI(EF.end_symbols(), false);
790 DataRefImpl Sym = toDRI(EF.symbol_end(), false);
791791 return basic_symbol_iterator(SymbolRef(Sym, this));
792792 }
793793
794794 template
795795 elf_symbol_iterator ELFObjectFile::dynamic_symbol_begin() const {
796 DataRefImpl Sym = toDRI(EF.begin_dynamic_symbols(), true);
796 DataRefImpl Sym = toDRI(EF.dynamic_symbol_begin(), true);
797797 return symbol_iterator(SymbolRef(Sym, this));
798798 }
799799
800800 template
801801 elf_symbol_iterator ELFObjectFile::dynamic_symbol_end() const {
802 DataRefImpl Sym = toDRI(EF.end_dynamic_symbols(), true);
802 DataRefImpl Sym = toDRI(EF.dynamic_symbol_end(), true);
803803 return symbol_iterator(SymbolRef(Sym, this));
804804 }
805805
806806 template
807807 section_iterator ELFObjectFile::section_begin() const {
808 return section_iterator(SectionRef(toDRI(EF.begin_sections()), this));
808 return section_iterator(SectionRef(toDRI(EF.section_begin()), this));
809809 }
810810
811811 template
812812 section_iterator ELFObjectFile::section_end() const {
813 return section_iterator(SectionRef(toDRI(EF.end_sections()), this));
813 return section_iterator(SectionRef(toDRI(EF.section_end()), this));
814814 }
815815
816816 template
817817 StringRef ELFObjectFile::getLoadName() const {
818 Elf_Dyn_Iter DI = EF.begin_dynamic_table();
819 Elf_Dyn_Iter DE = EF.end_dynamic_table();
818 Elf_Dyn_Iter DI = EF.dynamic_table_begin();
819 Elf_Dyn_Iter DE = EF.dynamic_table_end();
820820
821821 while (DI != DE && DI->getTag() != ELF::DT_SONAME)
822822 ++DI;
2323 template void printProgramHeaders(const ELFFile *o) {
2424 typedef ELFFile ELFO;
2525 outs() << "Program Header:\n";
26 for (typename ELFO::Elf_Phdr_Iter pi = o->begin_program_headers(),
27 pe = o->end_program_headers();
28 pi != pe; ++pi) {
26 for (typename ELFO::Elf_Phdr_Iter pi = o->program_header_begin(),
27 pe = o->program_header_end();
28 pi != pe; ++pi) {
2929 switch (pi->p_type) {
3030 case ELF::PT_LOAD:
3131 outs() << " LOAD ";
364364 /// handling table. Use this symbol to recover the actual exception handling
365365 /// table.
366366
367 for (Elf_Shdr_iterator SI = ELF->begin_sections(), SE = ELF->end_sections();
367 for (Elf_Shdr_iterator SI = ELF->section_begin(), SE = ELF->section_end();
368368 SI != SE; ++SI) {
369369 if (SI->sh_type == ELF::SHT_REL && SI->sh_info == IndexSectionIndex) {
370 for (Elf_Rel_iterator RI = ELF->begin_rel(&*SI), RE = ELF->end_rel(&*SI);
370 for (Elf_Rel_iterator RI = ELF->rel_begin(&*SI), RE = ELF->rel_end(&*SI);
371371 RI != RE; ++RI) {
372372 if (RI->r_offset == static_cast(IndexTableOffset)) {
373373 typename object::ELFFile::Elf_Rela RelA;
526526 DictScope UI(SW, "UnwindInformation");
527527
528528 int SectionIndex = 0;
529 for (Elf_Shdr_iterator SI = ELF->begin_sections(), SE = ELF->end_sections();
529 for (Elf_Shdr_iterator SI = ELF->section_begin(), SE = ELF->section_end();
530530 SI != SE; ++SI, ++SectionIndex) {
531531 if (SI->sh_type == ELF::SHT_ARM_EXIDX) {
532532 const Elf_Shdr *IT = &(*SI);
615615 ListScope SectionsD(W, "Sections");
616616
617617 int SectionIndex = -1;
618 for (typename ELFO::Elf_Shdr_Iter SecI = Obj->begin_sections(),
619 SecE = Obj->end_sections();
618 for (typename ELFO::Elf_Shdr_Iter SecI = Obj->section_begin(),
619 SecE = Obj->section_end();
620620 SecI != SecE; ++SecI) {
621621 ++SectionIndex;
622622
664664 ListScope D(W, "Relocations");
665665
666666 int SectionNumber = -1;
667 for (typename ELFO::Elf_Shdr_Iter SecI = Obj->begin_sections(),
668 SecE = Obj->end_sections();
667 for (typename ELFO::Elf_Shdr_Iter SecI = Obj->section_begin(),
668 SecE = Obj->section_end();
669669 SecI != SecE; ++SecI) {
670670 ++SectionNumber;
671671
688688 void ELFDumper::printDynamicRelocations() {
689689 W.startLine() << "Dynamic Relocations {\n";
690690 W.indent();
691 for (typename ELFO::Elf_Rela_Iter RelI = Obj->begin_dyn_rela(),
692 RelE = Obj->end_dyn_rela();
693 RelI != RelE; ++RelI) {
691 for (typename ELFO::Elf_Rela_Iter RelI = Obj->dyn_rela_begin(),
692 RelE = Obj->dyn_rela_end();
693 RelI != RelE; ++RelI) {
694694 SmallString<32> RelocName;
695695 Obj->getRelocationTypeName(RelI->getType(Obj->isMips64EL()), RelocName);
696696 StringRef SymbolName;
697697 uint32_t SymIndex = RelI->getSymbol(Obj->isMips64EL());
698 const typename ELFO::Elf_Sym *Sym = Obj->begin_dynamic_symbols() + SymIndex;
698 const typename ELFO::Elf_Sym *Sym = Obj->dynamic_symbol_begin() + SymIndex;
699699 SymbolName = errorOrDefault(Obj->getSymbolName(Sym, true));
700700 if (opts::ExpandRelocs) {
701701 DictScope Group(W, "Relocation");
721721 void ELFDumper::printRelocations(const Elf_Shdr *Sec) {
722722 switch (Sec->sh_type) {
723723 case ELF::SHT_REL:
724 for (typename ELFO::Elf_Rel_Iter RI = Obj->begin_rel(Sec),
725 RE = Obj->end_rel(Sec);
724 for (typename ELFO::Elf_Rel_Iter RI = Obj->rel_begin(Sec),
725 RE = Obj->rel_end(Sec);
726726 RI != RE; ++RI) {
727727 typename ELFO::Elf_Rela Rela;
728728 Rela.r_offset = RI->r_offset;
732732 }
733733 break;
734734 case ELF::SHT_RELA:
735 for (typename ELFO::Elf_Rela_Iter RI = Obj->begin_rela(Sec),
736 RE = Obj->end_rela(Sec);
735 for (typename ELFO::Elf_Rela_Iter RI = Obj->rela_begin(Sec),
736 RE = Obj->rela_end(Sec);
737737 RI != RE; ++RI) {
738738 printRelocation(Sec, *RI);
739739 }
10981098 void ELFDumper::printProgramHeaders() {
10991099 ListScope L(W, "ProgramHeaders");
11001100
1101 for (typename ELFO::Elf_Phdr_Iter PI = Obj->begin_program_headers(),
1102 PE = Obj->end_program_headers();
1103 PI != PE; ++PI) {
1101 for (typename ELFO::Elf_Phdr_Iter PI = Obj->program_header_begin(),
1102 PE = Obj->program_header_end();
1103 PI != PE; ++PI) {
11041104 DictScope P(W, "ProgramHeader");
11051105 W.printHex ("Type",
11061106 getElfSegmentType(Obj->getHeader()->e_machine, PI->p_type),
11281128 }
11291129
11301130 DictScope BA(W, "BuildAttributes");
1131 for (ELFO::Elf_Shdr_Iter SI = Obj->begin_sections(), SE = Obj->end_sections();
1131 for (ELFO::Elf_Shdr_Iter SI = Obj->section_begin(), SE = Obj->section_end();
11321132 SI != SE; ++SI) {
11331133 if (SI->sh_type != ELF::SHT_ARM_ATTRIBUTES)
11341134 continue;
12031203 return;
12041204 }
12051205
1206 const Elf_Sym *DynSymBegin = Obj->begin_dynamic_symbols();
1207 const Elf_Sym *DynSymEnd = Obj->end_dynamic_symbols();
1206 const Elf_Sym *DynSymBegin = Obj->dynamic_symbol_begin();
1207 const Elf_Sym *DynSymEnd = Obj->dynamic_symbol_end();
12081208 std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd));
12091209
12101210 if (DtGotSym > DynSymTotal) {
114114
115115 // Dump symbols
116116 bool IsFirstSym = true;
117 for (auto SI = Obj.begin_symbols(), SE = Obj.end_symbols(); SI != SE; ++SI) {
117 for (auto SI = Obj.symbol_begin(), SE = Obj.symbol_end(); SI != SE; ++SI) {
118118 if (IsFirstSym) {
119119 IsFirstSym = false;
120120 continue;
247247 if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
248248 return EC;
249249
250 for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE;
251 ++RI) {
250 for (auto RI = Obj.rel_begin(Shdr), RE = Obj.rel_end(Shdr); RI != RE; ++RI) {
252251 ELFYAML::Relocation R;
253252 if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
254253 return EC;
267266 if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
268267 return EC;
269268
270 for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE;
269 for (auto RI = Obj.rela_begin(Shdr), RE = Obj.rela_end(Shdr); RI != RE;
271270 ++RI) {
272271 ELFYAML::Relocation R;
273272 if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))