1 //===- StaticResolver.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_STATICRESOLVER_H 10 #define MCLD_LD_STATICRESOLVER_H 11 #include <string> 12 #include <mcld/LD/Resolver.h> 13 #include <mcld/LD/ResolveInfo.h> 14 15 namespace mcld 16 { 17 18 class NamePool; 19 20 /** \class StaticResolver 21 */ 22 class StaticResolver : public Resolver 23 { 24 public: 25 /** \enum LinkAction 26 * LinkAction follows BFD:linker.c (binary file descriptor). 27 * List all actions to take in the state table 28 */ 29 enum LinkAction 30 { 31 FAIL, /* abort. */ 32 NOACT, /* no action. */ 33 UND, /* override by symbol undefined symbol. */ 34 WEAK, /* override by symbol weak undefined. */ 35 DEF, /* override by symbol defined. */ 36 DEFW, /* override by symbol weak defined. */ 37 DEFD, /* override by symbol dynamic defined. */ 38 DEFWD, /* override by symbol dynamic weak defined. */ 39 MDEFD, /* mark symbol dynamic defined. */ 40 MDEFWD, /* mark symbol dynamic weak defined. */ 41 DUND, /* override dynamic defined symbol by undefined one. */ 42 DUNDW, /* oevrride dynamic defined symbol by weak undefined one. */ 43 COM, /* override by symbol common. */ 44 CREF, /* Possibly warn about common reference to defined symbol. */ 45 CDEF, /* redefine existing common symbol. */ 46 BIG, /* override by symbol common using largest size. */ 47 MBIG, /* mark common symbol by larger size. */ 48 IND, /* override by indirect symbol. */ 49 CIND, /* mark indirect symbol from existing common symbol. */ 50 MDEF, /* multiple definition error. */ 51 MIND, /* multiple indirect symbols. */ 52 REFC /* Mark indirect symbol referenced and then CYCLE. */ 53 }; 54 55 private: 56 // These are the values generated by the bit codes. 57 /** Encoding: 58 * D -> define 59 * U -> undefine 60 * d -> dynamic 61 * w -> weak 62 * C -> common 63 * I -> indirect 64 */ 65 enum 66 { 67 U = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, 68 w_U = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, 69 d_U = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, 70 wd_U = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, 71 D = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, 72 w_D = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, 73 d_D = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, 74 wd_D = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, 75 C = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, 76 w_C = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, 77 d_C = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, 78 wd_C = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, 79 I = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, 80 w_I = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, 81 d_I = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag, 82 wd_I = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag 83 }; 84 85 enum ORDINATE 86 { 87 U_ORD, 88 w_U_ORD, 89 d_U_ORD, 90 wd_U_ORD, 91 D_ORD, 92 w_D_ORD, 93 d_D_ORD, 94 wd_D_ORD, 95 C_ORD, 96 w_C_ORD, 97 Cs_ORD, 98 Is_ORD, 99 LAST_ORD 100 }; 101 102 public: 103 virtual ~StaticResolver(); 104 105 /// shouldOverride - Can resolver override the symbol pOld by the symbol pNew? 106 /// @return successfully resolved, return true; otherwise, return false. 107 /// @param pOld the symbol which may be overridden. 108 /// @param pNew the symbol which is used to replace pOld 109 virtual bool resolve(ResolveInfo & __restrict__ pOld, 110 const ResolveInfo & __restrict__ pNew, 111 bool &pOverride, LDSymbol::ValueType pValue) const; 112 113 private: getOrdinate(const ResolveInfo & pInfo)114 inline unsigned int getOrdinate(const ResolveInfo& pInfo) const { 115 if (pInfo.isAbsolute() && pInfo.isDyn()) 116 return d_D_ORD; 117 if (pInfo.isAbsolute()) 118 return D_ORD; 119 if (pInfo.isCommon() && pInfo.isDyn()) 120 return Cs_ORD; 121 if (pInfo.isCommon() && pInfo.isDefine()) 122 return C_ORD; 123 if (pInfo.isCommon() && pInfo.isWeak()) 124 return w_C_ORD; 125 if (pInfo.isIndirect()) 126 return Is_ORD; 127 return pInfo.info(); 128 } 129 }; 130 131 } // namespace of mcld 132 133 #endif 134 135