[lld] r232081 - [Mips] Make `readAddend` a virtual member function to escape explicit

Simon Atanasyan simon at atanasyan.com
Thu Mar 12 11:53:06 PDT 2015


Author: atanasyan
Date: Thu Mar 12 13:53:06 2015
New Revision: 232081

URL: http://llvm.org/viewvc/llvm-project?rev=232081&view=rev
Log:
[Mips] Make `readAddend` a virtual member function to escape explicit
template class instantiation

No functional changes.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=232081&r1=232080&r2=232081&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Thu Mar 12 13:53:06 2015
@@ -231,8 +231,10 @@ private:
 
   Reference::Addend readAddend(const Elf_Rel &ri,
                                const ArrayRef<uint8_t> content) const {
-    return MipsRelocationHandler<ELFT>::readAddend(
-        ri.getType(isMips64EL()), content.data() + ri.r_offset);
+    const auto &rh =
+        this->_ctx.template getTargetHandler<ELFT>().getRelocationHandler();
+    return static_cast<const MipsRelocationHandler &>(rh)
+        .readAddend(ri.getType(isMips64EL()), content.data() + ri.r_offset);
   }
 
   uint32_t getPairRelocation(const Elf_Rel &rel) const {

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=232081&r1=232080&r2=232081&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Thu Mar 12 13:53:06 2015
@@ -29,6 +29,22 @@ struct MipsRelocationParams {
   uint8_t _shift; // Relocation's addendum left shift size
   bool _shuffle;  // Relocation's addendum/result needs to be shuffled
 };
+
+template <class ELFT> class RelocationHandler : public MipsRelocationHandler {
+public:
+  RelocationHandler(MipsLinkingContext &ctx) : _ctx(ctx) {}
+
+  std::error_code applyRelocation(ELFWriter &writer,
+                                  llvm::FileOutputBuffer &buf,
+                                  const lld::AtomLayout &atom,
+                                  const Reference &ref) const override;
+
+  Reference::Addend readAddend(Reference::KindValue kind,
+                               const uint8_t *content) const override;
+
+private:
+  MipsLinkingContext &_ctx;
+};
 }
 
 static MipsRelocationParams getRelocationParams(uint32_t rType) {
@@ -416,7 +432,7 @@ static void relocWrite(uint64_t data, co
 }
 
 template <class ELFT>
-std::error_code MipsRelocationHandler<ELFT>::applyRelocation(
+std::error_code RelocationHandler<ELFT>::applyRelocation(
     ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
     const Reference &ref) const {
   if (ref.kindNamespace() != lld::Reference::KindNamespace::ELF)
@@ -458,8 +474,8 @@ std::error_code MipsRelocationHandler<EL
 
 template <class ELFT>
 Reference::Addend
-MipsRelocationHandler<ELFT>::readAddend(Reference::KindValue kind,
-                                        const uint8_t *content) {
+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;
@@ -468,23 +484,18 @@ MipsRelocationHandler<ELFT>::readAddend(
 namespace lld {
 namespace elf {
 
-template class MipsRelocationHandler<Mips32ELType>;
-template class MipsRelocationHandler<Mips32BEType>;
-template class MipsRelocationHandler<Mips64ELType>;
-template class MipsRelocationHandler<Mips64BEType>;
-
 template <>
 std::unique_ptr<TargetRelocationHandler>
 createMipsRelocationHandler<Mips32ELType>(MipsLinkingContext &ctx) {
   return std::unique_ptr<TargetRelocationHandler>(
-      new MipsRelocationHandler<Mips32ELType>(ctx));
+      new RelocationHandler<Mips32ELType>(ctx));
 }
 
 template <>
 std::unique_ptr<TargetRelocationHandler>
 createMipsRelocationHandler<Mips64ELType>(MipsLinkingContext &ctx) {
   return std::unique_ptr<TargetRelocationHandler>(
-      new MipsRelocationHandler<Mips64ELType>(ctx));
+      new RelocationHandler<Mips64ELType>(ctx));
 }
 
 } // elf

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h?rev=232081&r1=232080&r2=232081&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.h Thu Mar 12 13:53:06 2015
@@ -15,24 +15,10 @@
 namespace lld {
 namespace elf {
 
-class MipsLinkingContext;
-template <class ELFT> class MipsTargetLayout;
-
-template <class ELFT>
 class MipsRelocationHandler : public TargetRelocationHandler {
 public:
-  MipsRelocationHandler(MipsLinkingContext &ctx) : _ctx(ctx) {}
-
-  std::error_code applyRelocation(ELFWriter &writer,
-                                  llvm::FileOutputBuffer &buf,
-                                  const lld::AtomLayout &atom,
-                                  const Reference &ref) const override;
-
-  static Reference::Addend readAddend(Reference::KindValue kind,
-                                      const uint8_t *content);
-
-private:
-  MipsLinkingContext &_ctx;
+  virtual Reference::Addend readAddend(Reference::KindValue kind,
+                                       const uint8_t *content) const = 0;
 };
 
 template <class ELFT>





More information about the llvm-commits mailing list