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
23namespace mcld
24{
25
26class MCLinker;
27class MCLDInfo;
28class TargetLDBackend;
29class MemoryAreaFactory;
30
31/** \class MCLDDriver
32 *  \brief MCLDDriver prepares parameters for MCLinker.
33 */
34class MCLDDriver
35{
36public:
37  MCLDDriver(MCLDInfo& pLDInfo,
38             TargetLDBackend& pLDBackend,
39             MemoryAreaFactory& pAreaFactory);
40
41  ~MCLDDriver();
42
43  /// initMCLinker - initialize MCLinker
44  ///  Connect all components in MCLinker
45  bool initMCLinker();
46
47  /// initStdSections - initialize standard sections of the output file.
48  bool initStdSections();
49
50  /// normalize - normalize the input files
51  void normalize();
52
53  /// linkable - check the linkability of current MCLDInfo
54  ///  Check list:
55  ///  - check the Attributes are not violate the constaint
56  ///  - check every Input has a correct Attribute
57  bool linkable() const;
58
59  /// mergeSections - put allinput sections into output sections
60  bool mergeSections();
61
62  /// addStandardSymbols - shared object and executable files need some
63  /// standard symbols
64  ///   @return if there are some input symbols with the same name to the
65  ///   standard symbols, return false
66  bool addStandardSymbols();
67
68  /// addTargetSymbols - some targets, such as MIPS and ARM, need some
69  /// target-dependent symbols
70  ///   @return if there are some input symbols with the same name to the
71  ///   target symbols, return false
72  bool addTargetSymbols();
73
74  /// readRelocations - read all relocation entries
75  bool readRelocations();
76
77  /// prelayout - help backend to do some modification before layout
78  bool prelayout();
79
80  /// layout - linearly layout all output sections and reserve some space
81  /// for GOT/PLT
82  ///   Because we do not support instruction relaxing in this early version,
83  ///   if there is a branch can not jump to its target, we return false
84  ///   directly
85  bool layout();
86
87  /// postlayout - help backend to do some modification after layout
88  bool postlayout();
89
90  /// relocate - applying relocation entries and create relocation
91  /// section in the output files
92  /// Create relocation section, asking TargetLDBackend to
93  /// read the relocation information into RelocationEntry
94  /// and push_back into the relocation section
95  bool relocation();
96
97  /// finalizeSymbolValue - finalize the symbol value
98  bool finalizeSymbolValue();
99
100  /// emitOutput - emit the output file.
101  bool emitOutput();
102
103  /// postProcessing - do modificatiion after all processes
104  bool postProcessing();
105
106  /// getLinker - get internal MCLinker object
107  MCLinker* getLinker()
108  { return m_pLinker; }
109
110  /// getLinker - get internal MCLinker object
111  const MCLinker* getLinker() const
112  { return m_pLinker; }
113
114  /// hasInitLinker - has Linker been initialized?
115  bool hasInitLinker() const
116  { return (NULL != m_pLinker); }
117
118private:
119  MCLDInfo& m_LDInfo;
120  TargetLDBackend &m_LDBackend;
121  MCLinker* m_pLinker;
122  SectionMap m_SectionMap;
123  MemoryAreaFactory &m_AreaFactory;
124};
125
126} // end namespace mcld
127#endif
128