Home | History | Annotate | Download | only in LD
      1 //===- Relocation.h ----------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #ifndef MCLD_LD_RELOCATION_H
     10 #define MCLD_LD_RELOCATION_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <llvm/ADT/ilist_node.h>
     15 #include <llvm/Support/DataTypes.h>
     16 
     17 #include <mcld/LD/Fragment.h>
     18 #include <mcld/LD/FragmentRef.h>
     19 #include <mcld/LD/ResolveInfo.h>
     20 #include <mcld/LD/LDSymbol.h>
     21 
     22 
     23 namespace mcld
     24 {
     25 class Layout;
     26 class RelocationFactory;
     27 class MCLDInfo;
     28 
     29 class Relocation : public Fragment
     30 {
     31 friend class RelocationFactory;
     32 
     33 public:
     34   typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead
     35   typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead
     36   typedef uint8_t Type;
     37 
     38 private:
     39   Relocation(Type pType,
     40              FragmentRef* pTargetRef,
     41              Address pAddend,
     42              DWord pTargetData);
     43 
     44 public:
     45   ~Relocation();
     46 
     47   /// type - relocation type
     48   Type type() const
     49   { return m_Type; }
     50 
     51   /// symValue - S value - the symbol address
     52   Address symValue() const;
     53 
     54   /// addend - A value
     55   Address addend() const
     56   { return m_Addend; }
     57 
     58   /// place - P value - address of the place being relocated
     59   Address place(const Layout& pLayout) const;
     60 
     61   /// symbol info - binding, type
     62   const ResolveInfo* symInfo() const
     63   { return m_pSymInfo; }
     64 
     65   /// symbol info - binding, type
     66   ResolveInfo* symInfo()
     67   { return m_pSymInfo; }
     68 
     69   /// target - the target data to relocate
     70   DWord& target();
     71 
     72   /// target - the target data to relocate
     73   const DWord& target() const;
     74 
     75   /// targetRef - the reference of the target data
     76   FragmentRef& targetRef()
     77   { return m_TargetAddress; }
     78 
     79   /// targetRef - the reference of the target data
     80   const FragmentRef& targetRef() const
     81   { return m_TargetAddress; }
     82 
     83   void apply(RelocationFactory& pRelocFactory, const MCLDInfo& pLDInfo);
     84 
     85   /// ----- modifiers ----- ///
     86   void setType(Type pType);
     87 
     88   void setAddend(Address pAddend);
     89 
     90   void setSymInfo(ResolveInfo* pSym);
     91 
     92   // Relocation is a kind of Fragment with type of FT_Reloc
     93   static bool classof(const Fragment *F)
     94   { return F->getKind() == Fragment::Relocation; }
     95   static bool classof(const Relocation *) { return true; }
     96 
     97 private:
     98   /// m_Type - the type of the relocation entries
     99   Type m_Type;
    100 
    101   /// m_TargetData - target data of the place being relocated
    102   DWord m_TargetData;
    103 
    104   /// m_pSymInfo - resolved symbol info of relocation target symbol
    105   ResolveInfo* m_pSymInfo;
    106 
    107   /// m_TargetAddress - FragmentRef of the place being relocated
    108   FragmentRef m_TargetAddress;
    109 
    110   /// m_Addend - the addend
    111   Address m_Addend;
    112 };
    113 
    114 } // namespace of mcld
    115 
    116 #endif
    117 
    118