ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source);
public:
- virtual std::error_code getRelocationAddend(DataRefImpl Rel,
- int64_t &Res) const = 0;
+ virtual ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
+
+ // FIXME: This is a bit of a hack. Every caller should know if it expecting
+ // and addend or not.
+ virtual bool hasRelocationAddend(DataRefImpl Rel) const = 0;
+
virtual std::pair<symbol_iterator, symbol_iterator>
getELFDynamicSymbolIterators() const = 0;
section_iterator section_begin() const override;
section_iterator section_end() const override;
- std::error_code getRelocationAddend(DataRefImpl Rel,
- int64_t &Res) const override;
+ ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const override;
+ bool hasRelocationAddend(DataRefImpl Rel) const override;
uint64_t getSectionFlags(SectionRef Sec) const override;
uint32_t getSectionType(SectionRef Sec) const override;
}
template <class ELFT>
-std::error_code
-ELFObjectFile<ELFT>::getRelocationAddend(DataRefImpl Rel,
- int64_t &Result) const {
- const Elf_Shdr *sec = getRelSection(Rel);
- switch (sec->sh_type) {
- default:
- report_fatal_error("Invalid section type in Rel!");
- case ELF::SHT_REL: {
- Result = 0;
- return std::error_code();
- }
- case ELF::SHT_RELA: {
- Result = getRela(Rel)->r_addend;
- return std::error_code();
- }
- }
+ErrorOr<int64_t>
+ELFObjectFile<ELFT>::getRelocationAddend(DataRefImpl Rel) const {
+ if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
+ return object_error::parse_failed;
+ return (int64_t)getRela(Rel)->r_addend;
+}
+
+template <class ELFT>
+bool ELFObjectFile<ELFT>::hasRelocationAddend(DataRefImpl Rel) const {
+ return getRelSection(Rel)->sh_type == ELF::SHT_RELA;
}
template <class ELFT>
return EF.getHeader()->e_type == ELF::ET_REL;
}
-inline std::error_code getELFRelocationAddend(const RelocationRef R,
- int64_t &Addend) {
- const ObjectFile *Obj = R.getObjectFile();
- DataRefImpl DRI = R.getRawDataRefImpl();
- return cast<ELFObjectFileBase>(Obj)->getRelocationAddend(DRI, Addend);
-}
-
inline std::pair<symbol_iterator, symbol_iterator>
getELFDynamicSymbolIterators(const SymbolicFile *Obj) {
return cast<ELFObjectFileBase>(Obj)->getELFDynamicSymbolIterators();