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 LD_RELOCATION_H
     10 #define 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 #include <mcld/MC/MCFragmentRef.h>
     17 #include <mcld/LD/ResolveInfo.h>
     18 #include <mcld/LD/LDSymbol.h>
     19 
     20 
     21 namespace mcld
     22 {
     23 class Layout;
     24 class RelocationFactory;
     25 class MCLDInfo;
     26 
     27 class Relocation : public llvm::MCFragment
     28 {
     29 friend class RelocationFactory;
     30 
     31 public:
     32   typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead
     33   typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead
     34   typedef uint8_t Type;
     35 
     36 private:
     37   Relocation(Type pType,
     38              MCFragmentRef* pTargetRef,
     39              Address pAddend,
     40              DWord pTargetData);
     41 
     42 public:
     43   ~Relocation();
     44 
     45   /// type - relocation type
     46   Type type() const
     47   { return m_Type; }
     48 
     49   /// symValue - S value - the symbol address
     50   Address symValue() const;
     51 
     52   /// addend - A value
     53   Address addend() const
     54   { return m_Addend; }
     55 
     56   /// place - P value - address of the place being relocated
     57   Address place(const Layout& pLayout) const;
     58 
     59   /// symbol info - binding, type
     60   const ResolveInfo* symInfo() const
     61   { return m_pSymInfo; }
     62 
     63   /// symbol info - binding, type
     64   ResolveInfo* symInfo()
     65   { return m_pSymInfo; }
     66 
     67   /// target - the target data to relocate
     68   DWord& target();
     69 
     70   /// target - the target data to relocate
     71   const DWord& target() const;
     72 
     73   /// targetRef - the reference of the target data
     74   MCFragmentRef& targetRef()
     75   { return m_TargetAddress; }
     76 
     77   /// targetRef - the reference of the target data
     78   const MCFragmentRef& targetRef() const
     79   { return m_TargetAddress; }
     80 
     81   void apply(RelocationFactory& pRelocFactory, const MCLDInfo& pLDInfo);
     82 
     83   /// ----- modifiers ----- ///
     84   void setType(Type pType);
     85 
     86   void setAddend(Address pAddend);
     87 
     88   void setSymInfo(ResolveInfo* pSym);
     89 
     90   // Relocation is a kind of MCFragment with type of FT_Reloc
     91   static bool classof(const MCFragment *F)
     92   { return F->getKind() == MCFragment::FT_Reloc;}
     93   static bool classof(const Relocation *) { return true; }
     94 
     95 private:
     96   /// m_Type - the type of the relocation entries
     97   Type m_Type;
     98 
     99   /// m_TargetData - target data of the place being relocated
    100   DWord m_TargetData;
    101 
    102   /// m_pSymInfo - resolved symbol info of relocation target symbol
    103   ResolveInfo* m_pSymInfo;
    104 
    105   /// m_TargetAddress - MCFragmentRef of the place being relocated
    106   MCFragmentRef m_TargetAddress;
    107 
    108   /// m_Addend - the addend
    109   Address m_Addend;
    110 };
    111 
    112 } // namespace of mcld
    113 
    114 #endif
    115