GeneralOptions.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
1//===- GeneralOptions.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_GENERAL_OPTIONS_H
10#define MCLD_GENERAL_OPTIONS_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14#include <string>
15#include <mcld/Support/RealPath.h>
16#include <mcld/Support/FileSystem.h>
17#include <mcld/MC/SearchDirs.h>
18#include <mcld/MC/ZOption.h>
19
20namespace mcld {
21
22class Input;
23
24/** \class GeneralOptions
25 *  \brief GeneralOptions collects the options that not be one of the
26 *     - input files
27 *     - attribute of input files
28 *     - script options
29 */
30class GeneralOptions
31{
32public:
33  GeneralOptions();
34  ~GeneralOptions();
35
36  /// default link script
37  bool hasDefaultLDScript() const;
38  const char* defaultLDScript() const;
39  void setDefaultLDScript(const std::string& pFilename);
40
41  /// sysroot
42  const sys::fs::Path& sysroot() const;
43
44  void setSysroot(const sys::fs::Path &pPath);
45
46  /// search directory
47  SearchDirs& directories()
48  { return m_SearchDirs; }
49
50  const SearchDirs& directories() const
51  { return m_SearchDirs; }
52
53  /// trace
54  void setTrace(bool pEnableTrace = true)
55  { m_bTrace = pEnableTrace; }
56
57  bool trace() const
58  { return m_bTrace; }
59
60  void setBsymbolic(bool pBsymbolic = true)
61  { m_Bsymbolic = pBsymbolic; }
62
63  bool Bsymbolic() const
64  { return m_Bsymbolic; }
65
66  void setPIE(bool pPIE = true)
67  { m_bPIE = pPIE; }
68
69  bool isPIE() const
70  { return m_bPIE; }
71
72  void setBgroup(bool pBgroup = true)
73  { m_Bgroup = pBgroup; }
74
75  bool Bgroup() const
76  { return m_Bgroup; }
77
78  bool hasEntry() const
79  { return !m_Entry.empty(); }
80
81  void setEntry(const std::string& pEntry)
82  { m_Entry = pEntry; }
83
84  const std::string& entry() const
85  { return m_Entry; }
86
87  void setDyld(const std::string& pDyld)
88  { m_Dyld = pDyld; }
89
90  const std::string& dyld() const
91  { return m_Dyld; }
92
93  bool hasDyld() const
94  { return !m_Dyld.empty(); }
95
96  void setSOName(const std::string& pName);
97
98  const std::string& soname() const
99  { return m_SOName; }
100
101  void setAllowShlibUndefined(bool pEnabled = true)
102  { m_bAllowShlibUndefined = pEnabled; }
103
104  bool isAllowShlibUndefined() const
105  { return m_bAllowShlibUndefined; }
106
107  void setVerbose(int8_t pVerbose = -1)
108  { m_Verbose = pVerbose; }
109
110  int8_t verbose() const
111  { return m_Verbose; }
112
113  void setMaxErrorNum(int16_t pNum)
114  { m_MaxErrorNum = pNum; }
115
116  int16_t maxErrorNum() const
117  { return m_MaxErrorNum; }
118
119  void setMaxWarnNum(int16_t pNum)
120  { m_MaxWarnNum = pNum; }
121
122  int16_t maxWarnNum() const
123  { return m_MaxWarnNum; }
124
125  void setColor(bool pEnabled = true)
126  { m_bColor = pEnabled; }
127
128  bool color() const
129  { return m_bColor; }
130
131  void setNoUndefined(bool pEnable = true)
132  { m_bNoUndefined = pEnable; }
133
134  void setMulDefs(bool pEnable = true)
135  { m_bMulDefs = pEnable; }
136
137  void setEhFrameHdr(bool pEnable = true)
138  { m_bCreateEhFrameHdr = pEnable; }
139
140  ///  -----  the -z options  -----  ///
141  void addZOption(const mcld::ZOption& pOption);
142
143  bool hasCombReloc() const
144  { return m_bCombReloc; }
145
146  bool isNoUndefined() const
147  { return m_bNoUndefined; }
148
149  bool hasStackSet() const
150  { return (Unknown != m_ExecStack); }
151
152  bool hasExecStack() const
153  { return (YES == m_ExecStack); }
154
155  bool hasInitFirst() const
156  { return m_bInitFirst; }
157
158  bool hasInterPose() const
159  { return m_bInterPose; }
160
161  bool hasLoadFltr() const
162  { return m_bLoadFltr; }
163
164  bool hasMulDefs() const
165  { return m_bMulDefs; }
166
167  bool hasNoCopyReloc() const
168  { return m_bNoCopyReloc; }
169
170  bool hasNoDefaultLib() const
171  { return m_bNoDefaultLib; }
172
173  bool hasNoDelete() const
174  { return m_bNoDelete; }
175
176  bool hasNoDLOpen() const
177  { return m_bNoDLOpen; }
178
179  bool hasNoDump() const
180  { return m_bNoDump; }
181
182  bool hasRelro() const
183  { return m_bRelro; }
184
185  bool hasNow() const
186  { return m_bNow; }
187
188  bool hasOrigin() const
189  { return m_bOrigin; }
190
191  uint64_t commPageSize() const
192  { return m_CommPageSize; }
193
194  uint64_t maxPageSize() const
195  { return m_MaxPageSize; }
196
197  bool hasEhFrameHdr() const
198  { return m_bCreateEhFrameHdr; }
199
200  // -n, --nmagic
201  void setNMagic(bool pMagic = true)
202  { m_NMagic = pMagic; }
203
204  bool nnagic() const
205  { return m_NMagic; }
206
207  // -N, --omagic
208  void setOMagic(bool pMagic = true)
209  { m_OMagic = pMagic; }
210
211  bool omagic() const
212  { return m_OMagic; }
213
214  // -S, --strip-debug
215  void setStripDebug(bool pStripDebug = true)
216  { m_StripDebug = pStripDebug; }
217
218  bool stripDebug() const
219  { return m_StripDebug; }
220
221  // -E, --export-dynamic
222  void setExportDynamic(bool pExportDynamic = true)
223  { m_ExportDynamic = pExportDynamic; }
224
225  bool exportDynamic() const
226  { return m_ExportDynamic; }
227
228  // --warn-shared-textrel
229  void setWarnSharedTextrel(bool pWarnSharedTextrel = true)
230  { m_WarnSharedTextrel = pWarnSharedTextrel; }
231
232  bool warnSharedTextrel() const
233  { return m_WarnSharedTextrel; }
234
235private:
236  enum status {
237    YES,
238    NO,
239    Unknown
240  };
241
242private:
243  Input* m_pDefaultBitcode;
244  std::string m_DefaultLDScript;
245  SearchDirs m_SearchDirs;
246  std::string m_Entry;
247  std::string m_Dyld;
248  std::string m_SOName;
249  int8_t m_Verbose;            // --verbose[=0,1,2]
250  uint16_t m_MaxErrorNum;      // --error-limit=N
251  uint16_t m_MaxWarnNum;       // --warning-limit=N
252  status m_ExecStack;          // execstack, noexecstack
253  uint64_t m_CommPageSize;     // common-page-size=value
254  uint64_t m_MaxPageSize;      // max-page-size=value
255  bool m_bCombReloc     : 1;   // combreloc, nocombreloc
256  bool m_bNoUndefined   : 1;   // defs, --no-undefined
257  bool m_bInitFirst     : 1;   // initfirst
258  bool m_bInterPose     : 1;   // interpose
259  bool m_bLoadFltr      : 1;   // loadfltr
260  bool m_bMulDefs       : 1;   // muldefs
261  bool m_bNoCopyReloc   : 1;   // nocopyreloc
262  bool m_bNoDefaultLib  : 1;   // nodefaultlib
263  bool m_bNoDelete      : 1;   // nodelete
264  bool m_bNoDLOpen      : 1;   // nodlopen
265  bool m_bNoDump        : 1;   // nodump
266  bool m_bRelro         : 1;   // relro, norelro
267  bool m_bNow           : 1;   // lazy, now
268  bool m_bOrigin        : 1;   // origin
269  bool m_bTrace         : 1;   // --trace
270  bool m_Bsymbolic      : 1;   // --Bsymbolic
271  bool m_Bgroup         : 1;
272  bool m_bPIE           : 1;
273  bool m_bColor         : 1;   // --color[=true,false,auto]
274  bool m_bAllowShlibUndefined : 1; // --[no-]allow-shlib-undefined and
275  bool m_bCreateEhFrameHdr : 1;    // --eh-frame-hdr
276  bool m_NMagic; // -n, --nmagic
277  bool m_OMagic; // -N, --omagic
278  bool m_StripDebug; // -S, --strip-debug
279  bool m_ExportDynamic; //-E, --export-dynamic
280  bool m_WarnSharedTextrel; // --warn-shared-textrel
281};
282
283} // namespace of mcld
284
285#endif
286
287