llvm.org GIT mirror llvm / 9b7ca41
Add Michael Spencer's iterator class for stepping through relocations. Add method that, given a symbol index, will return the symbol's data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164026 91177308-0d34-0410-b5e6-96231b3b80d8 Sid Manning 7 years ago
1 changed file(s) with 85 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
461461 // This is set the first time getLoadName is called.
462462 mutable const char *dt_soname;
463463
464 public:
465 /// \brief Iterate over relocations in a .rel or .rela section.
466 template
467 class ELFRelocationIterator {
468 public:
469 typedef void difference_type;
470 typedef const RelocT value_type;
471 typedef std::forward_iterator_tag iterator_category;
472 typedef value_type &reference;
473 typedef value_type *pointer;
474
475 /// \brief Default construct iterator.
476 ELFRelocationIterator() : Section(0), Current(0) {}
477 ELFRelocationIterator(const Elf_Shdr *Sec, const char *Start)
478 : Section(Sec)
479 , Current(Start) {}
480
481 reference operator *() {
482 assert(Current && "Attempted to dereference an invalid iterator!");
483 return *reinterpret_cast(Current);
484 }
485
486 pointer operator ->() {
487 assert(Current && "Attempted to dereference an invalid iterator!");
488 return reinterpret_cast(Current);
489 }
490
491 bool operator ==(const ELFRelocationIterator &Other) {
492 return Section == Other.Section && Current == Other.Current;
493 }
494
495 bool operator !=(const ELFRelocationIterator &Other) {
496 return !(*this == Other);
497 }
498
499 ELFRelocationIterator &operator ++(int) {
500 assert(Current && "Attempted to increment an invalid iterator!");
501 Current += Section->sh_entsize;
502 return *this;
503 }
504
505 ELFRelocationIterator operator ++() {
506 ELFRelocationIterator Tmp = *this;
507 ++*this;
508 return Tmp;
509 }
510
511 private:
512 const Elf_Shdr *Section;
513 const char *Current;
514 };
515
516 private:
464517 // Records for each version index the corresponding Verdef or Vernaux entry.
465518 // This is filled the first time LoadVersionMap() is called.
466519 class VersionMapEntry : public PointerIntPair {
596649 virtual dyn_iterator begin_dynamic_table() const;
597650 virtual dyn_iterator end_dynamic_table() const;
598651
652 typedef ELFRelocationIterator Elf_Rela_Iter;
653 typedef ELFRelocationIterator Elf_Rel_Iter;
654
655 virtual Elf_Rela_Iter beginELFRela(const Elf_Shdr *sec) const {
656 return Elf_Rela_Iter(sec, (const char *)(base() + sec->sh_offset));
657 };
658
659 virtual Elf_Rela_Iter endELFRela(const Elf_Shdr *sec) const {
660 return Elf_Rela_Iter(sec, (const char *)
661 (base() + sec->sh_offset + sec->sh_size));
662 };
663
664 virtual Elf_Rel_Iter beginELFRel(const Elf_Shdr *sec) const {
665 return Elf_Rel_Iter(sec, (const char *)(base() + sec->sh_offset));
666 };
667
668 virtual Elf_Rel_Iter endELFRel(const Elf_Shdr *sec) const {
669 return Elf_Rel_Iter(sec, (const char *)
670 (base() + sec->sh_offset + sec->sh_size));
671 };
672
599673 virtual uint8_t getBytesInAddress() const;
600674 virtual StringRef getFileFormatName() const;
601675 virtual StringRef getObjectType() const { return "ELF"; }
610684 const Elf_Shdr *getSection(const Elf_Sym *symb) const;
611685 const Elf_Shdr *getElfSection(section_iterator &It) const;
612686 const Elf_Sym *getElfSymbol(symbol_iterator &It) const;
687 const Elf_Sym *getElfSymbol(uint32_t index) const;
613688
614689 // Methods for type inquiry through isa, cast, and dyn_cast
615690 bool isDyldType() const { return isDyldELFObject; }
803878 ELFObjectFile
804879 ::getElfSymbol(symbol_iterator &It) const {
805880 return getSymbol(It->getRawDataRefImpl());
881 }
882
883 template
884 const typename ELFObjectFile::Elf_Sym *
885 ELFObjectFile
886 ::getElfSymbol(uint32_t index) const {
887 DataRefImpl SymbolData;
888 SymbolData.d.a = index;
889 SymbolData.d.b = 1;
890 return getSymbol(SymbolData);
806891 }
807892
808893 template