Home | History | Annotate | Download | only in MC
      1 //===- MCLDDriver.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 //
     10 // MCLDDriver plays the same role as GNU collect2 to prepare all implicit
     11 // parameters for MCLinker.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef MCLD_LDDRIVER_H
     16 #define MCLD_LDDRIVER_H
     17 #ifdef ENABLE_UNITTEST
     18 #include <gtest.h>
     19 #endif
     20 
     21 #include <mcld/LD/SectionMap.h>
     22 namespace mcld
     23 {
     24 
     25 class MCLinker;
     26 class MCLDInfo;
     27 class TargetLDBackend;
     28 
     29 //===----------------------------------------------------------------------===//
     30 /// MCLDDriver - MCLDDriver prepares parameters for MCLinker.
     31 ///
     32 class MCLDDriver
     33 {
     34 public:
     35   MCLDDriver(MCLDInfo& pLDInfo, TargetLDBackend& pLDBackend);
     36   ~MCLDDriver();
     37 
     38   /// normalize - normalize the input files
     39   void normalize();
     40 
     41   /// linkable - check the linkability of current MCLDInfo
     42   ///  Check list:
     43   ///  - check the Attributes are not violate the constaint
     44   ///  - check every Input has a correct Attribute
     45   bool linkable() const;
     46 
     47   /// initMCLinker - initialize MCLinker
     48   ///  Connect all components in MCLinker
     49   bool initMCLinker();
     50 
     51   /// readSections - read all input section headers
     52   bool readSections();
     53 
     54   /// mergeSections - put allinput sections into output sections
     55   bool mergeSections();
     56 
     57   /// readSymbolTables - read symbol tables from the input files.
     58   ///  for each input file, loads its symbol table from file.
     59   bool readSymbolTables();
     60 
     61   /// mergeSymbolTables - merge the symbol tables of input files into the
     62   /// output's symbol table.
     63   bool mergeSymbolTables();
     64 
     65   /// addStandardSymbols - shared object and executable files need some
     66   /// standard symbols
     67   ///   @return if there are some input symbols with the same name to the
     68   ///   standard symbols, return false
     69   bool addStandardSymbols();
     70 
     71   /// addTargetSymbols - some targets, such as MIPS and ARM, need some
     72   /// target-dependent symbols
     73   ///   @return if there are some input symbols with the same name to the
     74   ///   target symbols, return false
     75   bool addTargetSymbols();
     76 
     77   /// readRelocations - read all relocation entries
     78   bool readRelocations();
     79 
     80   /// prelayout - help backend to do some modification before layout
     81   bool prelayout();
     82 
     83   /// layout - linearly layout all output sections and reserve some space
     84   /// for GOT/PLT
     85   ///   Because we do not support instruction relaxing in this early version,
     86   ///   if there is a branch can not jump to its target, we return false
     87   ///   directly
     88   bool layout();
     89 
     90   /// postlayout - help backend to do some modification after layout
     91   bool postlayout();
     92 
     93   /// relocate - applying relocation entries and create relocation
     94   /// section in the output files
     95   /// Create relocation section, asking TargetLDBackend to
     96   /// read the relocation information into RelocationEntry
     97   /// and push_back into the relocation section
     98   bool relocate();
     99 
    100   /// finalizeSymbolValue - finalize the symbol value
    101   bool finalizeSymbolValue();
    102 
    103   /// emitOutput - emit the output file.
    104   bool emitOutput();
    105 
    106   /// postProcessing - do modificatiion after all processes
    107   bool postProcessing();
    108 
    109 private:
    110   MCLDInfo& m_LDInfo;
    111   TargetLDBackend &m_LDBackend;
    112   MCLinker* m_pLinker;
    113   SectionMap m_SectionMap;
    114 };
    115 
    116 } // end namespace mcld
    117 #endif
    118