llvm.org GIT mirror llvm / 7ede964
Don't return error_code from a function that doesn't fail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241033 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
13 changed file(s) with 26 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
677677 uint64_t &Res) const override;
678678 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
679679 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
680 std::error_code getRelocationType(DataRefImpl Rel,
681 uint64_t &Res) const override;
680 uint64_t getRelocationType(DataRefImpl Rel) const override;
682681 std::error_code
683682 getRelocationTypeName(DataRefImpl Rel,
684683 SmallVectorImpl &Result) const override;
232232 uint64_t &Res) const override;
233233 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
234234 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
235 std::error_code getRelocationType(DataRefImpl Rel,
236 uint64_t &Res) const override;
235 uint64_t getRelocationType(DataRefImpl Rel) const override;
237236 std::error_code
238237 getRelocationTypeName(DataRefImpl Rel,
239238 SmallVectorImpl &Result) const override;
724723 }
725724
726725 template
727 std::error_code ELFObjectFile::getRelocationType(DataRefImpl Rel,
728 uint64_t &Result) const {
726 uint64_t ELFObjectFile::getRelocationType(DataRefImpl Rel) const {
729727 const Elf_Shdr *sec = getRelSection(Rel);
730728 if (sec->sh_type == ELF::SHT_REL)
731 Result = getRel(Rel)->getType(EF.isMips64EL());
729 return getRel(Rel)->getType(EF.isMips64EL());
732730 else
733 Result = getRela(Rel)->getType(EF.isMips64EL());
734 return std::error_code();
731 return getRela(Rel)->getType(EF.isMips64EL());
735732 }
736733
737734 template
239239 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
240240 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
241241 section_iterator getRelocationSection(DataRefImpl Rel) const;
242 std::error_code getRelocationType(DataRefImpl Rel,
243 uint64_t &Res) const override;
242 uint64_t getRelocationType(DataRefImpl Rel) const override;
244243 std::error_code
245244 getRelocationTypeName(DataRefImpl Rel,
246245 SmallVectorImpl &Result) const override;
5252 std::error_code getAddress(uint64_t &Result) const;
5353 uint64_t getOffset() const;
5454 symbol_iterator getSymbol() const;
55 std::error_code getType(uint64_t &Result) const;
55 uint64_t getType() const;
5656
5757 /// @brief Indicates whether this relocation should hidden when listing
5858 /// relocations, usually because it is the trailing part of a multipart
241241 uint64_t &Res) const = 0;
242242 virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
243243 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
244 virtual std::error_code getRelocationType(DataRefImpl Rel,
245 uint64_t &Res) const = 0;
244 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
246245 virtual std::error_code
247246 getRelocationTypeName(DataRefImpl Rel,
248247 SmallVectorImpl &Result) const = 0;
463462 return OwningObject->getRelocationSymbol(RelocationPimpl);
464463 }
465464
466 inline std::error_code RelocationRef::getType(uint64_t &Result) const {
467 return OwningObject->getRelocationType(RelocationPimpl, Result);
465 inline uint64_t RelocationRef::getType() const {
466 return OwningObject->getRelocationType(RelocationPimpl);
468467 }
469468
470469 inline std::error_code
667667 uint64_t SectionSize = RelocatedSection->getSize();
668668 for (const RelocationRef &Reloc : Section.relocations()) {
669669 uint64_t Address = Reloc.getOffset();
670 uint64_t Type;
671 Reloc.getType(Type);
670 uint64_t Type = Reloc.getType();
672671 uint64_t SymAddr = 0;
673672 uint64_t SectionLoadAddress = 0;
674673 object::symbol_iterator Sym = Reloc.getSymbol();
771771 i != e;) {
772772 // The R_PPC64_ADDR64 relocation indicates the first field
773773 // of a .opd entry
774 uint64_t TypeFunc;
775 check(i->getType(TypeFunc));
774 uint64_t TypeFunc = i->getType();
776775 if (TypeFunc != ELF::R_PPC64_ADDR64) {
777776 ++i;
778777 continue;
789788 break;
790789
791790 // Just check if following relocation is a R_PPC64_TOC
792 uint64_t TypeTOC;
793 check(i->getType(TypeTOC));
791 uint64_t TypeTOC = i->getType();
794792 if (TypeTOC != ELF::R_PPC64_TOC)
795793 continue;
796794
10581056 unsigned SectionID, relocation_iterator RelI, const ObjectFile &O,
10591057 ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) {
10601058 const auto &Obj = cast(O);
1061 uint64_t RelType;
1062 Check(RelI->getType(RelType));
1059 uint64_t RelType = RelI->getType();
10631060 ErrorOr AddendOrErr = ELFRelocationRef(*RelI).getAddend();
10641061 int64_t Addend = AddendOrErr ? *AddendOrErr : 0;
10651062 elf_symbol_iterator Symbol = RelI->getSymbol();
124124 const bool IsExtern = SecI == Obj.section_end();
125125
126126 // Determine the Addend used to adjust the relocation value.
127 uint64_t RelType;
128 Check(RelI->getType(RelType));
127 uint64_t RelType = RelI->getType();
129128 uint64_t Offset = RelI->getOffset();
130129 uint64_t Addend = 0;
131130 SectionEntry &Section = Sections[SectionID];
989989 return symbol_iterator(SymbolRef(Ref, this));
990990 }
991991
992 std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
993 uint64_t &Res) const {
992 uint64_t COFFObjectFile::getRelocationType(DataRefImpl Rel) const {
994993 const coff_relocation* R = toRel(Rel);
995 Res = R->Type;
996 return std::error_code();
994 return R->Type;
997995 }
998996
999997 const coff_section *
653653 return section_iterator(getAnyRelocationSection(getRelocation(Rel)));
654654 }
655655
656 std::error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
657 uint64_t &Res) const {
656 uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const {
658657 MachO::any_relocation_info RE = getRelocation(Rel);
659 Res = getAnyRelocationType(RE);
660 return std::error_code();
658 return getAnyRelocationType(RE);
661659 }
662660
663661 std::error_code
664662 MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
665663 SmallVectorImpl &Result) const {
666664 StringRef res;
667 uint64_t RType;
668 getRelocationType(Rel, RType);
665 uint64_t RType = getRelocationType(Rel);
669666
670667 unsigned Arch = this->getArch();
671668
775772 std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
776773 bool &Result) const {
777774 unsigned Arch = getArch();
778 uint64_t Type;
779 getRelocationType(Rel, Type);
775 uint64_t Type = getRelocationType(Rel);
780776
781777 Result = false;
782778
790786 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
791787 DataRefImpl RelPrev = Rel;
792788 RelPrev.d.a--;
793 uint64_t PrevType;
794 getRelocationType(RelPrev, PrevType);
789 uint64_t PrevType = getRelocationType(RelPrev);
795790 if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
796791 Result = true;
797792 }
207207 }
208208
209209 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
210 uint64_t ret;
211 if (std::error_code ec = (*unwrap(RI))->getType(ret))
212 report_fatal_error(ec.message());
213 return ret;
210 return (*unwrap(RI))->getType();
214211 }
215212
216213 // NOTE: Caller takes ownership of returned string.
2525 X86_64ELFRelocationInfo(MCContext &Ctx) : MCRelocationInfo(Ctx) {}
2626
2727 const MCExpr *createExprForRelocation(RelocationRef Rel) override {
28 uint64_t RelType; Rel.getType(RelType);
28 uint64_t RelType = Rel.getType();
2929 elf_symbol_iterator SymI = Rel.getSymbol();
3030
3131 StringRef SymName; SymI->getName(SymName);
2626 const MCExpr *createExprForRelocation(RelocationRef Rel) override {
2727 const MachOObjectFile *Obj = cast(Rel.getObject());
2828
29 uint64_t RelType; Rel.getType(RelType);
29 uint64_t RelType = Rel.getType();
3030 symbol_iterator SymI = Rel.getSymbol();
3131
3232 StringRef SymName; SymI->getName(SymName);
803803 void COFFDumper::printRelocation(const SectionRef &Section,
804804 const RelocationRef &Reloc) {
805805 uint64_t Offset = Reloc.getOffset();
806 uint64_t RelocType;
806 uint64_t RelocType = Reloc.getType();
807807 SmallString<32> RelocName;
808808 StringRef SymbolName;
809 if (error(Reloc.getType(RelocType)))
810 return;
811809 if (error(Reloc.getTypeName(RelocName)))
812810 return;
813811 symbol_iterator Symbol = Reloc.getSymbol();