[Mips] Replace MipsRelocationHandler::readAddend() by a regular function

The readAddend() does not depend on MipsRelocationHandler and should not
be its member function.

llvm-svn: 234154
This commit is contained in:
Simon Atanasyan 2015-04-06 13:25:58 +00:00
parent 3a8691a27a
commit 58a7fd48dc
3 changed files with 14 additions and 21 deletions

View File

@ -244,9 +244,8 @@ private:
Reference::Addend readAddend(const Elf_Rel &ri,
const ArrayRef<uint8_t> content) const {
const auto &rh = this->_ctx.getTargetHandler().getRelocationHandler();
return static_cast<const MipsRelocationHandler &>(rh)
.readAddend(getPrimaryType(ri), content.data() + ri.r_offset);
return readMipsRelocAddend(getPrimaryType(ri),
content.data() + ri.r_offset);
}
uint32_t getPairRelocation(const Elf_Rel &rel) const {

View File

@ -40,9 +40,6 @@ public:
const lld::AtomLayout &atom,
const Reference &ref) const override;
Reference::Addend readAddend(Reference::KindValue kind,
const uint8_t *content) const override;
private:
MipsLinkingContext &_ctx;
MipsTargetLayout<ELFT> &_targetLayout;
@ -488,16 +485,15 @@ static ErrorOr<uint64_t> calculateRelocation(Reference::KindValue kind,
}
}
template <class ELFT>
static uint64_t relocRead(const MipsRelocationParams &params,
const uint8_t *loc) {
uint64_t data;
switch (params._size) {
case 4:
data = endian::read<uint32_t, ELFT::TargetEndianness, unaligned>(loc);
data = endian::read32le(loc);
break;
case 8:
data = endian::read<uint64_t, ELFT::TargetEndianness, unaligned>(loc);
data = endian::read64le(loc);
break;
default:
llvm_unreachable("Unexpected size");
@ -572,7 +568,7 @@ std::error_code RelocationHandler<ELFT>::applyRelocation(
}
auto params = getRelocationParams(op);
uint64_t ins = relocRead<ELFT>(params, location);
uint64_t ins = relocRead(params, location);
if (auto ec = adjustJumpOpCode(ins, tgtAddr, jumpMode))
return ec;
@ -583,15 +579,6 @@ std::error_code RelocationHandler<ELFT>::applyRelocation(
return std::error_code();
}
template <class ELFT>
Reference::Addend
RelocationHandler<ELFT>::readAddend(Reference::KindValue kind,
const uint8_t *content) const {
auto params = getRelocationParams(kind);
uint64_t ins = relocRead<ELFT>(params, content);
return (ins & params._mask) << params._shift;
}
namespace lld {
namespace elf {
@ -609,5 +596,12 @@ createMipsRelocationHandler<Mips64ELType>(MipsLinkingContext &ctx,
return llvm::make_unique<RelocationHandler<Mips64ELType>>(ctx, layout);
}
Reference::Addend readMipsRelocAddend(Reference::KindValue kind,
const uint8_t *content) {
auto params = getRelocationParams(kind);
uint64_t ins = relocRead(params, content);
return (ins & params._mask) << params._shift;
}
} // elf
} // lld

View File

@ -19,8 +19,6 @@ template<typename ELFT> class MipsTargetLayout;
class MipsRelocationHandler : public TargetRelocationHandler {
public:
virtual Reference::Addend readAddend(Reference::KindValue kind,
const uint8_t *content) const = 0;
};
template <class ELFT>
@ -28,6 +26,8 @@ std::unique_ptr<TargetRelocationHandler>
createMipsRelocationHandler(MipsLinkingContext &ctx,
MipsTargetLayout<ELFT> &layout);
Reference::Addend readMipsRelocAddend(Reference::KindValue kind,
const uint8_t *content);
} // elf
} // lld