llvm.org GIT mirror llvm / f8a35ff
Don't return error_code from a function that doesn't fail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241042 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
11 changed file(s) with 23 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
678678 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
679679 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
680680 uint64_t getRelocationType(DataRefImpl Rel) const override;
681 std::error_code
682 getRelocationTypeName(DataRefImpl Rel,
683 SmallVectorImpl &Result) const override;
681 void getRelocationTypeName(DataRefImpl Rel,
682 SmallVectorImpl &Result) const override;
683
684684 public:
685685 COFFObjectFile(MemoryBufferRef Object, std::error_code &EC);
686686 basic_symbol_iterator symbol_begin_impl() const override;
233233 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
234234 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
235235 uint64_t getRelocationType(DataRefImpl Rel) const override;
236 std::error_code
237 getRelocationTypeName(DataRefImpl Rel,
238 SmallVectorImpl &Result) const override;
236 void getRelocationTypeName(DataRefImpl Rel,
237 SmallVectorImpl &Result) const override;
239238
240239 uint32_t getSectionType(DataRefImpl Sec) const override;
241240 uint64_t getSectionFlags(DataRefImpl Sec) const override;
737736 }
738737
739738 template
740 std::error_code ELFObjectFile::getRelocationTypeName(
739 void ELFObjectFile::getRelocationTypeName(
741740 DataRefImpl Rel, SmallVectorImpl &Result) const {
742 const Elf_Shdr *sec = getRelSection(Rel);
743 uint32_t type;
744 if (sec->sh_type == ELF::SHT_REL)
745 type = getRel(Rel)->getType(EF.isMips64EL());
746 else
747 type = getRela(Rel)->getType(EF.isMips64EL());
748
741 uint32_t type = getRelocationType(Rel);
749742 EF.getRelocationTypeName(type, Result);
750 return std::error_code();
751743 }
752744
753745 template
240240 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
241241 section_iterator getRelocationSection(DataRefImpl Rel) const;
242242 uint64_t getRelocationType(DataRefImpl Rel) const override;
243 std::error_code
244 getRelocationTypeName(DataRefImpl Rel,
245 SmallVectorImpl &Result) const override;
243 void getRelocationTypeName(DataRefImpl Rel,
244 SmallVectorImpl &Result) const override;
246245 uint8_t getRelocationLength(DataRefImpl Rel) const;
247246
248247 // MachO specific.
5757 /// @brief Get a string that represents the type of this relocation.
5858 ///
5959 /// This is for display purposes only.
60 std::error_code getTypeName(SmallVectorImpl &Result) const;
61
60 void getTypeName(SmallVectorImpl &Result) const;
6261
6362 DataRefImpl getRawDataRefImpl() const;
6463 const ObjectFile *getObject() const;
237236 virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
238237 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
239238 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
240 virtual std::error_code
241 getRelocationTypeName(DataRefImpl Rel,
242 SmallVectorImpl &Result) const = 0;
239 virtual void getRelocationTypeName(DataRefImpl Rel,
240 SmallVectorImpl &Result) const = 0;
243241
244242 public:
245243 uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
456454 return OwningObject->getRelocationType(RelocationPimpl);
457455 }
458456
459 inline std::error_code
460 RelocationRef::getTypeName(SmallVectorImpl &Result) const {
457 inline void RelocationRef::getTypeName(SmallVectorImpl &Result) const {
461458 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
462459 }
463460
706706 object::RelocToApply R(V.visit(Type, Reloc, SymAddr));
707707 if (V.error()) {
708708 SmallString<32> Name;
709 std::error_code ec(Reloc.getTypeName(Name));
710 if (ec) {
711 errs() << "Aaaaaa! Nameless relocation! Aaaaaa!\n";
712 }
709 Reloc.getTypeName(Name);
713710 errs() << "error: failed to compute relocation: "
714711 << Name << "\n";
715712 continue;
10301030 Res = #reloc_type; \
10311031 break;
10321032
1033 std::error_code
1034 COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
1035 SmallVectorImpl &Result) const {
1033 void COFFObjectFile::getRelocationTypeName(
1034 DataRefImpl Rel, SmallVectorImpl &Result) const {
10361035 const coff_relocation *Reloc = toRel(Rel);
10371036 StringRef Res;
10381037 switch (getMachine()) {
11011100 Res = "Unknown";
11021101 }
11031102 Result.append(Res.begin(), Res.end());
1104 return std::error_code();
11051103 }
11061104
11071105 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
658658 return getAnyRelocationType(RE);
659659 }
660660
661 std::error_code
662 MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
663 SmallVectorImpl &Result) const {
661 void MachOObjectFile::getRelocationTypeName(
662 DataRefImpl Rel, SmallVectorImpl &Result) const {
664663 StringRef res;
665664 uint64_t RType = getRelocationType(Rel);
666665
766765 break;
767766 }
768767 Result.append(res.begin(), res.end());
769 return std::error_code();
770768 }
771769
772770 uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const {
213213 // NOTE: Caller takes ownership of returned string.
214214 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) {
215215 SmallVector ret;
216 if (std::error_code ec = (*unwrap(RI))->getTypeName(ret))
217 report_fatal_error(ec.message());
218
216 (*unwrap(RI))->getTypeName(ret);
219217 char *str = static_cast(malloc(ret.size()));
220218 std::copy(ret.begin(), ret.end(), str);
221219 return str;
930930
931931 // Stop when rel_cur's address is past the current instruction.
932932 if (addr >= Index + Size) break;
933 if (error(rel_cur->getTypeName(name))) goto skip_print_rel;
933 rel_cur->getTypeName(name);
934934 if (error(getRelocationValueString(*rel_cur, val)))
935935 goto skip_print_rel;
936936 outs() << format(Fmt.data(), SectionAddr + addr) << name
966966 SmallString<32> valuestr;
967967 if (hidden)
968968 continue;
969 if (error(Reloc.getTypeName(relocname)))
970 continue;
969 Reloc.getTypeName(relocname);
971970 if (error(getRelocationValueString(Reloc, valuestr)))
972971 continue;
973972 outs() << format(Fmt.data(), address) << " " << relocname << " "
806806 uint64_t RelocType = Reloc.getType();
807807 SmallString<32> RelocName;
808808 StringRef SymbolName;
809 if (error(Reloc.getTypeName(RelocName)))
810 return;
809 Reloc.getTypeName(RelocName);
811810 symbol_iterator Symbol = Reloc.getSymbol();
812811 if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
813812 return;
462462 const RelocationRef &Reloc) {
463463 uint64_t Offset = Reloc.getOffset();
464464 SmallString<32> RelocName;
465 if (error(Reloc.getTypeName(RelocName)))
466 return;
465 Reloc.getTypeName(RelocName);
467466
468467 DataRefImpl DR = Reloc.getRawDataRefImpl();
469468 MachO::any_relocation_info RE = Obj->getRelocation(DR);