ELF: Remove TargetHandler::getTargetLayout.

Only MIPS used that member function, and by removing the use of the
function, I removed a static_cast. Seems like it's a win.

llvm-svn: 233748
This commit is contained in:
Rui Ueyama
2015-03-31 20:31:48 +00:00
parent 3dac3f7fe6
commit 1490b3512e
9 changed files with 15 additions and 37 deletions

View File

@@ -30,10 +30,6 @@ class AArch64TargetHandler final : public DefaultTargetHandler<AArch64ELFType> {
public:
AArch64TargetHandler(AArch64LinkingContext &ctx);
AArch64TargetLayout<AArch64ELFType> &getTargetLayout() override {
return *_aarch64TargetLayout;
}
void registerRelocationNames(Registry &registry) override;
const AArch64TargetRelocationHandler &getRelocationHandler() const override {

View File

@@ -64,10 +64,6 @@ class ARMTargetHandler final : public DefaultTargetHandler<ARMELFType> {
public:
ARMTargetHandler(ARMLinkingContext &ctx);
ARMTargetLayout<ARMELFType> &getTargetLayout() override {
return *_armTargetLayout;
}
void registerRelocationNames(Registry &registry) override;
const ARMTargetRelocationHandler &getRelocationHandler() const override {

View File

@@ -113,10 +113,6 @@ public:
return *_relocationHandler;
}
HexagonTargetLayout<HexagonELFType> &getTargetLayout() override {
return *_targetLayout;
}
std::unique_ptr<Reader> getObjReader() override {
return llvm::make_unique<HexagonELFObjectReader>(_ctx);
}

View File

@@ -32,7 +32,8 @@ struct MipsRelocationParams {
template <class ELFT> class RelocationHandler : public MipsRelocationHandler {
public:
RelocationHandler(MipsLinkingContext &ctx) : _ctx(ctx) {}
RelocationHandler(MipsLinkingContext &ctx, MipsTargetLayout<ELFT> &layout)
: _ctx(ctx), _targetLayout(layout) {}
std::error_code applyRelocation(ELFWriter &writer,
llvm::FileOutputBuffer &buf,
@@ -44,6 +45,7 @@ public:
private:
MipsLinkingContext &_ctx;
MipsTargetLayout<ELFT> &_targetLayout;
};
}
@@ -530,13 +532,10 @@ std::error_code RelocationHandler<ELFT>::applyRelocation(
return std::error_code();
assert(ref.kindArch() == Reference::KindArch::Mips);
auto &targetLayout = static_cast<MipsTargetLayout<ELFT> &>(
_ctx.getTargetHandler<ELFT>().getTargetLayout());
AtomLayout *gpAtom = targetLayout.getGP();
AtomLayout *gpAtom = _targetLayout.getGP();
uint64_t gpAddr = gpAtom ? gpAtom->_virtualAddr : 0;
AtomLayout *gpDispAtom = targetLayout.getGPDisp();
AtomLayout *gpDispAtom = _targetLayout.getGPDisp();
bool isGpDisp = gpDispAtom && ref.target() == gpDispAtom->_atom;
uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
@@ -598,14 +597,16 @@ namespace elf {
template <>
std::unique_ptr<TargetRelocationHandler>
createMipsRelocationHandler<Mips32ELType>(MipsLinkingContext &ctx) {
return llvm::make_unique<RelocationHandler<Mips32ELType>>(ctx);
createMipsRelocationHandler<Mips32ELType>(MipsLinkingContext &ctx,
MipsTargetLayout<Mips32ELType> &layout) {
return llvm::make_unique<RelocationHandler<Mips32ELType>>(ctx, layout);
}
template <>
std::unique_ptr<TargetRelocationHandler>
createMipsRelocationHandler<Mips64ELType>(MipsLinkingContext &ctx) {
return llvm::make_unique<RelocationHandler<Mips64ELType>>(ctx);
createMipsRelocationHandler<Mips64ELType>(MipsLinkingContext &ctx,
MipsTargetLayout<Mips64ELType> &layout) {
return llvm::make_unique<RelocationHandler<Mips64ELType>>(ctx, layout);
}
} // elf

View File

@@ -15,6 +15,8 @@
namespace lld {
namespace elf {
template<typename ELFT> class MipsTargetLayout;
class MipsRelocationHandler : public TargetRelocationHandler {
public:
virtual Reference::Addend readAddend(Reference::KindValue kind,
@@ -23,7 +25,7 @@ public:
template <class ELFT>
std::unique_ptr<TargetRelocationHandler>
createMipsRelocationHandler(MipsLinkingContext &ctx);
createMipsRelocationHandler(MipsLinkingContext &ctx, MipsTargetLayout<ELFT> &layout);
} // elf
} // lld

View File

@@ -110,9 +110,7 @@ public:
MipsTargetHandler(MipsLinkingContext &ctx)
: _ctx(ctx), _runtimeFile(new MipsRuntimeFile<ELFT>(ctx)),
_targetLayout(new MipsTargetLayout<ELFT>(ctx)),
_relocationHandler(createMipsRelocationHandler<ELFT>(ctx)) {}
MipsTargetLayout<ELFT> &getTargetLayout() override { return *_targetLayout; }
_relocationHandler(createMipsRelocationHandler<ELFT>(ctx, *_targetLayout)) {}
std::unique_ptr<Reader> getObjReader() override {
return llvm::make_unique<MipsELFObjectReader<ELFT>>(_ctx);

View File

@@ -54,9 +54,6 @@ public:
/// of creating atoms and how the atoms are written to the output file.
template <class ELFT> class TargetHandler : public TargetHandlerBase {
public:
/// The layout determined completely by the Target.
virtual TargetLayout<ELFT> &getTargetLayout() = 0;
/// Determine how relocations need to be applied.
virtual const TargetRelocationHandler &getRelocationHandler() const = 0;

View File

@@ -31,10 +31,6 @@ class X86TargetHandler final
public:
X86TargetHandler(X86LinkingContext &ctx);
X86TargetLayout<X86ELFType> &getTargetLayout() override {
return *_x86TargetLayout;
}
void registerRelocationNames(Registry &registry) override;
const X86TargetRelocationHandler &getRelocationHandler() const override {

View File

@@ -35,10 +35,6 @@ class X86_64TargetHandler
public:
X86_64TargetHandler(X86_64LinkingContext &ctx);
X86_64TargetLayout &getTargetLayout() override {
return *_x86_64TargetLayout;
}
void registerRelocationNames(Registry &registry) override;
const X86_64TargetRelocationHandler &getRelocationHandler() const override {