llvm.org GIT mirror llvm / 09912eb
Move function to the only file that uses it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241040 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
4 changed file(s) with 35 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
243243 std::error_code
244244 getRelocationTypeName(DataRefImpl Rel,
245245 SmallVectorImpl &Result) const override;
246 bool getRelocationHidden(DataRefImpl Rel) const override;
247246 uint8_t getRelocationLength(DataRefImpl Rel) const;
248247
249248 // MachO specific.
5353 uint64_t getOffset() const;
5454 symbol_iterator getSymbol() const;
5555 uint64_t getType() const;
56
57 /// @brief Indicates whether this relocation should hidden when listing
58 /// relocations, usually because it is the trailing part of a multipart
59 /// relocation that will be printed as part of the leading relocation.
60 bool getHidden() const;
6156
6257 /// @brief Get a string that represents the type of this relocation.
6358 ///
245240 virtual std::error_code
246241 getRelocationTypeName(DataRefImpl Rel,
247242 SmallVectorImpl &Result) const = 0;
248 virtual bool getRelocationHidden(DataRefImpl Rel) const { return false; }
249243
250244 public:
251245 uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
467461 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
468462 }
469463
470 inline bool RelocationRef::getHidden() const {
471 return OwningObject->getRelocationHidden(RelocationPimpl);
472 }
473
474464 inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
475465 return RelocationPimpl;
476466 }
767767 }
768768 Result.append(res.begin(), res.end());
769769 return std::error_code();
770 }
771
772 bool MachOObjectFile::getRelocationHidden(DataRefImpl Rel) const {
773 unsigned Arch = getArch();
774 uint64_t Type = getRelocationType(Rel);
775
776 // On arches that use the generic relocations, GENERIC_RELOC_PAIR
777 // is always hidden.
778 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
779 if (Type == MachO::GENERIC_RELOC_PAIR)
780 return true;
781 } else if (Arch == Triple::x86_64) {
782 // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
783 // an X86_64_RELOC_SUBTRACTOR.
784 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
785 DataRefImpl RelPrev = Rel;
786 RelPrev.d.a--;
787 uint64_t PrevType = getRelocationType(RelPrev);
788 if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
789 return true;
790 }
791 }
792
793 return false;
794770 }
795771
796772 uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const {
691691 return getRelocationValueString(MachO, Rel, Result);
692692 }
693693
694 /// @brief Indicates whether this relocation should hidden when listing
695 /// relocations, usually because it is the trailing part of a multipart
696 /// relocation that will be printed as part of the leading relocation.
697 static bool getHidden(RelocationRef RelRef) {
698 const ObjectFile *Obj = RelRef.getObject();
699 auto *MachO = dyn_cast(Obj);
700 if (!MachO)
701 return false;
702
703 unsigned Arch = MachO->getArch();
704 DataRefImpl Rel = RelRef.getRawDataRefImpl();
705 uint64_t Type = MachO->getRelocationType(Rel);
706
707 // On arches that use the generic relocations, GENERIC_RELOC_PAIR
708 // is always hidden.
709 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
710 if (Type == MachO::GENERIC_RELOC_PAIR)
711 return true;
712 } else if (Arch == Triple::x86_64) {
713 // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
714 // an X86_64_RELOC_SUBTRACTOR.
715 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
716 DataRefImpl RelPrev = Rel;
717 RelPrev.d.a--;
718 uint64_t PrevType = MachO->getRelocationType(RelPrev);
719 if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
720 return true;
721 }
722 }
723
724 return false;
725 }
726
694727 static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
695728 const Target *TheTarget = getTarget(Obj);
696729 // getTarget() will have already issued a diagnostic if necessary, so
887920
888921 // Print relocation for instruction.
889922 while (rel_cur != rel_end) {
890 bool hidden = rel_cur->getHidden();
923 bool hidden = getHidden(*rel_cur);
891924 uint64_t addr = rel_cur->getOffset();
892925 SmallString<16> name;
893926 SmallString<32> val;
927960 continue;
928961 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
929962 for (const RelocationRef &Reloc : Section.relocations()) {
930 bool hidden = Reloc.getHidden();
963 bool hidden = getHidden(Reloc);
931964 uint64_t address = Reloc.getOffset();
932965 SmallString<32> relocname;
933966 SmallString<32> valuestr;