Index: lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h +++ lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h @@ -30,10 +30,6 @@ public: AArch64TargetHandler(AArch64LinkingContext &ctx); - AArch64TargetLayout &getTargetLayout() override { - return *_aarch64TargetLayout; - } - void registerRelocationNames(Registry ®istry) override; const AArch64TargetRelocationHandler &getRelocationHandler() const override { Index: lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h +++ lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h @@ -64,10 +64,6 @@ public: ARMTargetHandler(ARMLinkingContext &ctx); - ARMTargetLayout &getTargetLayout() override { - return *_armTargetLayout; - } - void registerRelocationNames(Registry ®istry) override; const ARMTargetRelocationHandler &getRelocationHandler() const override { Index: lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h +++ lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h @@ -113,10 +113,6 @@ return *_hexagonRelocationHandler; } - HexagonTargetLayout &getTargetLayout() override { - return *_hexagonTargetLayout; - } - std::unique_ptr getObjReader() override { return llvm::make_unique(_ctx); } Index: lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h =================================================================== --- lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h +++ lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h @@ -15,6 +15,8 @@ namespace lld { namespace elf { +template class MipsTargetLayout; + class MipsRelocationHandler : public TargetRelocationHandler { public: virtual Reference::Addend readAddend(Reference::KindValue kind, @@ -23,7 +25,7 @@ template std::unique_ptr -createMipsRelocationHandler(MipsLinkingContext &ctx); +createMipsRelocationHandler(MipsLinkingContext &ctx, MipsTargetLayout &layout); } // elf } // lld Index: lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp =================================================================== --- lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp +++ lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp @@ -32,7 +32,8 @@ template class RelocationHandler : public MipsRelocationHandler { public: - RelocationHandler(MipsLinkingContext &ctx) : _ctx(ctx) {} + RelocationHandler(MipsLinkingContext &ctx, MipsTargetLayout &layout) + : _ctx(ctx), _targetLayout(layout) {} std::error_code applyRelocation(ELFWriter &writer, llvm::FileOutputBuffer &buf, @@ -44,6 +45,7 @@ private: MipsLinkingContext &_ctx; + MipsTargetLayout &_targetLayout; }; } @@ -530,13 +532,10 @@ return std::error_code(); assert(ref.kindArch() == Reference::KindArch::Mips); - auto &targetLayout = static_cast &>( - _ctx.getTargetHandler().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 @@ template <> std::unique_ptr -createMipsRelocationHandler(MipsLinkingContext &ctx) { - return llvm::make_unique>(ctx); +createMipsRelocationHandler(MipsLinkingContext &ctx, + MipsTargetLayout &layout) { + return llvm::make_unique>(ctx, layout); } template <> std::unique_ptr -createMipsRelocationHandler(MipsLinkingContext &ctx) { - return llvm::make_unique>(ctx); +createMipsRelocationHandler(MipsLinkingContext &ctx, + MipsTargetLayout &layout) { + return llvm::make_unique>(ctx, layout); } } // elf Index: lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h +++ lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h @@ -110,9 +110,7 @@ MipsTargetHandler(MipsLinkingContext &ctx) : _ctx(ctx), _runtimeFile(new MipsRuntimeFile(ctx)), _targetLayout(new MipsTargetLayout(ctx)), - _relocationHandler(createMipsRelocationHandler(ctx)) {} - - MipsTargetLayout &getTargetLayout() override { return *_targetLayout; } + _relocationHandler(createMipsRelocationHandler(ctx, *_targetLayout)) {} std::unique_ptr getObjReader() override { return llvm::make_unique>(_ctx); Index: lib/ReaderWriter/ELF/TargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/TargetHandler.h +++ lib/ReaderWriter/ELF/TargetHandler.h @@ -54,9 +54,6 @@ /// of creating atoms and how the atoms are written to the output file. template class TargetHandler : public TargetHandlerBase { public: - /// The layout determined completely by the Target. - virtual TargetLayout &getTargetLayout() = 0; - /// Determine how relocations need to be applied. virtual const TargetRelocationHandler &getRelocationHandler() const = 0; Index: lib/ReaderWriter/ELF/X86/X86TargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/X86/X86TargetHandler.h +++ lib/ReaderWriter/ELF/X86/X86TargetHandler.h @@ -31,10 +31,6 @@ public: X86TargetHandler(X86LinkingContext &ctx); - X86TargetLayout &getTargetLayout() override { - return *_x86TargetLayout; - } - void registerRelocationNames(Registry ®istry) override; const X86TargetRelocationHandler &getRelocationHandler() const override { Index: lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h +++ lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h @@ -35,10 +35,6 @@ public: X86_64TargetHandler(X86_64LinkingContext &ctx); - X86_64TargetLayout &getTargetLayout() override { - return *_x86_64TargetLayout; - } - void registerRelocationNames(Registry ®istry) override; const X86_64TargetRelocationHandler &getRelocationHandler() const override {