Home | History | Annotate | Download | only in MC
      1 //===- MCLinker.tcc -------------------------------------------------------===//
      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 
     10 /// addSymbol - add a symbol and resolve it immediately
     11 template<Input::Type FROM>
     12 LDSymbol* MCLinker::addSymbol(const llvm::StringRef& pName,
     13                               ResolveInfo::Type pType,
     14                               ResolveInfo::Desc pDesc,
     15                               ResolveInfo::Binding pBinding,
     16                               ResolveInfo::SizeType pSize,
     17                               LDSymbol::ValueType pValue,
     18                               FragmentRef* pFragmentRef,
     19                               ResolveInfo::Visibility pVisibility)
     20 {
     21   llvm::StringRef symbol_name = pName;
     22   if (!getLDInfo().scripts().renameMap().empty() &&
     23       ResolveInfo::Undefined == pDesc) {
     24     // If the renameMap is not empty, some symbols should be renamed.
     25     // --wrap and --portable defines the symbol rename map.
     26     ScriptOptions::SymbolRenameMap::iterator renameSym
     27                                 = getLDInfo().scripts().renameMap().find(pName);
     28     if (renameSym != getLDInfo().scripts().renameMap().end())
     29       symbol_name = renameSym.getEntry()->value();
     30   }
     31 
     32   if (FROM == Input::DynObj)
     33     return addSymbolFromDynObj(symbol_name,
     34                                pType,
     35                                pDesc,
     36                                pBinding,
     37                                pSize,
     38                                pValue,
     39                                pFragmentRef,
     40                                pVisibility);
     41 
     42   if (FROM == Input::Object)
     43     return addSymbolFromObject(symbol_name,
     44                                pType,
     45                                pDesc,
     46                                pBinding,
     47                                pSize,
     48                                pValue,
     49                                pFragmentRef,
     50                                pVisibility);
     51 
     52   llvm::report_fatal_error("add a symbol from unknown file type.\n");
     53   return NULL;
     54 }
     55 
     56 // defineSymbol - define a new symbol
     57 template<MCLinker::DefinePolicy POLICY, MCLinker::ResolvePolicy RESOLVE>
     58 LDSymbol* MCLinker::defineSymbol(const llvm::StringRef& pName,
     59                                  bool pIsDyn,
     60                                  ResolveInfo::Type pType,
     61                                  ResolveInfo::Desc pDesc,
     62                                  ResolveInfo::Binding pBinding,
     63                                  ResolveInfo::SizeType pSize,
     64                                  LDSymbol::ValueType pValue,
     65                                  FragmentRef* pFragmentRef,
     66                                  ResolveInfo::Visibility pVisibility)
     67 {
     68   // These if/return should be optimized by compiler.
     69   // This function is defined for clarity.
     70   if (MCLinker::Force == POLICY && MCLinker::Unresolve == RESOLVE)
     71     return defineSymbolForcefully(pName,
     72                                   pIsDyn,
     73                                   pType,
     74                                   pDesc,
     75                                   pBinding,
     76                                   pSize,
     77                                   pValue,
     78                                   pFragmentRef,
     79                                   pVisibility);
     80 
     81   if (MCLinker::AsRefered == POLICY && MCLinker::Unresolve == RESOLVE)
     82     return defineSymbolAsRefered(pName,
     83                                  pIsDyn,
     84                                  pType,
     85                                  pDesc,
     86                                  pBinding,
     87                                  pSize,
     88                                  pValue,
     89                                  pFragmentRef,
     90                                  pVisibility);
     91 
     92   if (MCLinker::Force == POLICY && MCLinker::Resolve == RESOLVE)
     93     return defineAndResolveSymbolForcefully(pName,
     94                                             pIsDyn,
     95                                             pType,
     96                                             pDesc,
     97                                             pBinding,
     98                                             pSize,
     99                                             pValue,
    100                                             pFragmentRef,
    101                                             pVisibility);
    102 
    103   if (MCLinker::AsRefered == POLICY && MCLinker::Resolve == RESOLVE)
    104     return defineAndResolveSymbolAsRefered(pName,
    105                                            pIsDyn,
    106                                            pType,
    107                                            pDesc,
    108                                            pBinding,
    109                                            pSize,
    110                                            pValue,
    111                                            pFragmentRef,
    112                                            pVisibility);
    113 }
    114 
    115