GeneralOptions.h revision 533eae20118036f425f27bf0536ef0ccbb090b65
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_GENERALOPTIONS_H
10#define MCLD_GENERALOPTIONS_H
11#include <string>
12#include <vector>
13#include <mcld/Support/RealPath.h>
14#include <mcld/Support/FileSystem.h>
15
16namespace mcld {
17
18class Input;
19class ZOption;
20
21/** \class GeneralOptions
22 *  \brief GeneralOptions collects the options that not be one of the
23 *     - input files
24 *     - attribute of input files
25 */
26class GeneralOptions
27{
28public:
29  enum StripSymbolMode {
30    KeepAllSymbols,
31    StripTemporaries,
32    StripLocals,
33    StripAllSymbols
34  };
35
36  enum HashStyle {
37    SystemV = 0x1,
38    GNU     = 0x2,
39    Both    = 0x3
40  };
41
42  typedef std::vector<std::string> RpathList;
43  typedef RpathList::iterator rpath_iterator;
44  typedef RpathList::const_iterator const_rpath_iterator;
45
46  typedef std::vector<std::string> ScriptList;
47  typedef ScriptList::iterator script_iterator;
48  typedef ScriptList::const_iterator const_script_iterator;
49
50  typedef std::vector<std::string> AuxiliaryList;
51  typedef AuxiliaryList::iterator aux_iterator;
52  typedef AuxiliaryList::const_iterator const_aux_iterator;
53
54public:
55  GeneralOptions();
56  ~GeneralOptions();
57
58  /// trace
59  void setTrace(bool pEnableTrace = true)
60  { m_bTrace = pEnableTrace; }
61
62  bool trace() const
63  { return m_bTrace; }
64
65  void setBsymbolic(bool pBsymbolic = true)
66  { m_Bsymbolic = pBsymbolic; }
67
68  bool Bsymbolic() const
69  { return m_Bsymbolic; }
70
71  void setPIE(bool pPIE = true)
72  { m_bPIE = pPIE; }
73
74  bool isPIE() const
75  { return m_bPIE; }
76
77  void setBgroup(bool pBgroup = true)
78  { m_Bgroup = pBgroup; }
79
80  bool Bgroup() const
81  { return m_Bgroup; }
82
83  void setDyld(const std::string& pDyld)
84  { m_Dyld = pDyld; }
85
86  const std::string& dyld() const
87  { return m_Dyld; }
88
89  bool hasDyld() const
90  { return !m_Dyld.empty(); }
91
92  void setSOName(const std::string& pName);
93
94  const std::string& soname() const
95  { return m_SOName; }
96
97  void setVerbose(int8_t pVerbose = -1)
98  { m_Verbose = pVerbose; }
99
100  int8_t verbose() const
101  { return m_Verbose; }
102
103  void setMaxErrorNum(int16_t pNum)
104  { m_MaxErrorNum = pNum; }
105
106  int16_t maxErrorNum() const
107  { return m_MaxErrorNum; }
108
109  void setMaxWarnNum(int16_t pNum)
110  { m_MaxWarnNum = pNum; }
111
112  int16_t maxWarnNum() const
113  { return m_MaxWarnNum; }
114
115  void setColor(bool pEnabled = true)
116  { m_bColor = pEnabled; }
117
118  bool color() const
119  { return m_bColor; }
120
121  void setNoUndefined(bool pEnable = true)
122  { m_NoUndefined = (pEnable?YES:NO); }
123
124  void setMulDefs(bool pEnable = true)
125  { m_MulDefs = (pEnable?YES:NO); }
126
127  void setEhFrameHdr(bool pEnable = true)
128  { m_bCreateEhFrameHdr = pEnable; }
129
130  ///  -----  the -z options  -----  ///
131  void addZOption(const mcld::ZOption& pOption);
132
133  bool hasCombReloc() const
134  { return m_bCombReloc; }
135
136  bool hasNoUndefined() const
137  { return (Unknown != m_NoUndefined); }
138
139  bool isNoUndefined() const
140  { return (YES == m_NoUndefined); }
141
142  bool hasStackSet() const
143  { return (Unknown != m_ExecStack); }
144
145  bool hasExecStack() const
146  { return (YES == m_ExecStack); }
147
148  bool hasInitFirst() const
149  { return m_bInitFirst; }
150
151  bool hasInterPose() const
152  { return m_bInterPose; }
153
154  bool hasLoadFltr() const
155  { return m_bLoadFltr; }
156
157  bool hasMulDefs() const
158  { return (Unknown != m_MulDefs); }
159
160  bool isMulDefs() const
161  { return (YES == m_MulDefs); }
162
163  bool hasNoCopyReloc() const
164  { return m_bNoCopyReloc; }
165
166  bool hasNoDefaultLib() const
167  { return m_bNoDefaultLib; }
168
169  bool hasNoDelete() const
170  { return m_bNoDelete; }
171
172  bool hasNoDLOpen() const
173  { return m_bNoDLOpen; }
174
175  bool hasNoDump() const
176  { return m_bNoDump; }
177
178  bool hasRelro() const
179  { return m_bRelro; }
180
181  bool hasNow() const
182  { return m_bNow; }
183
184  bool hasOrigin() const
185  { return m_bOrigin; }
186
187  uint64_t commPageSize() const
188  { return m_CommPageSize; }
189
190  uint64_t maxPageSize() const
191  { return m_MaxPageSize; }
192
193  bool hasEhFrameHdr() const
194  { return m_bCreateEhFrameHdr; }
195
196  // -n, --nmagic
197  void setNMagic(bool pMagic = true)
198  { m_bNMagic = pMagic; }
199
200  bool nmagic() const
201  { return m_bNMagic; }
202
203  // -N, --omagic
204  void setOMagic(bool pMagic = true)
205  { m_bOMagic = pMagic; }
206
207  bool omagic() const
208  { return m_bOMagic; }
209
210  // -S, --strip-debug
211  void setStripDebug(bool pStripDebug = true)
212  { m_bStripDebug = pStripDebug; }
213
214  bool stripDebug() const
215  { return m_bStripDebug; }
216
217  // -E, --export-dynamic
218  void setExportDynamic(bool pExportDynamic = true)
219  { m_bExportDynamic = pExportDynamic; }
220
221  bool exportDynamic() const
222  { return m_bExportDynamic; }
223
224  // --warn-shared-textrel
225  void setWarnSharedTextrel(bool pWarnSharedTextrel = true)
226  { m_bWarnSharedTextrel = pWarnSharedTextrel; }
227
228  bool warnSharedTextrel() const
229  { return m_bWarnSharedTextrel; }
230
231  void setBinaryInput(bool pBinaryInput = true)
232  { m_bBinaryInput = pBinaryInput; }
233
234  bool isBinaryInput() const
235  { return m_bBinaryInput; }
236
237  void setDefineCommon(bool pEnable = true)
238  { m_bDefineCommon = pEnable; }
239
240  bool isDefineCommon() const
241  { return m_bDefineCommon; }
242
243  void setFatalWarnings(bool pEnable = true)
244  { m_bFatalWarnings = pEnable; }
245
246  bool isFatalWarnings() const
247  { return m_bFatalWarnings; }
248
249  StripSymbolMode getStripSymbolMode() const
250  { return m_StripSymbols; }
251
252  void setStripSymbols(StripSymbolMode pMode)
253  { m_StripSymbols = pMode; }
254
255  void setNewDTags(bool pEnable = true)
256  { m_bNewDTags = pEnable; }
257
258  bool hasNewDTags() const
259  { return m_bNewDTags; }
260
261  void setNoStdlib(bool pEnable = true)
262  { m_bNoStdlib = pEnable; }
263
264  bool nostdlib() const
265  { return m_bNoStdlib; }
266
267  // -M, --print-map
268  void setPrintMap(bool pEnable = true)
269  { m_bPrintMap = pEnable; }
270
271  bool printMap() const
272  { return m_bPrintMap; }
273
274  void setWarnMismatch(bool pEnable = true)
275  { m_bWarnMismatch = pEnable; }
276
277  bool warnMismatch() const
278  { return m_bWarnMismatch; }
279
280  // --gc-sections
281  void setGCSections(bool pEnable = true)
282  { m_bGCSections = pEnable; }
283
284  bool GCSections() const
285  { return m_bGCSections; }
286
287  // --ld-generated-unwind-info
288  void setGenUnwindInfo(bool pEnable = true)
289  { m_bGenUnwindInfo = pEnable; }
290
291  bool genUnwindInfo() const
292  { return m_bGenUnwindInfo; }
293
294  // -G, max GP size option
295  void setGPSize(int gpsize)
296  { m_GPSize = gpsize; }
297
298  int getGPSize() const
299  { return m_GPSize; }
300
301  unsigned int getHashStyle() const { return m_HashStyle; }
302
303  void setHashStyle(unsigned int pStyle)
304  { m_HashStyle = pStyle; }
305
306  // -----  link-in rpath  ----- //
307  const RpathList& getRpathList() const { return m_RpathList; }
308  RpathList&       getRpathList()       { return m_RpathList; }
309
310  const_rpath_iterator rpath_begin() const { return m_RpathList.begin(); }
311  rpath_iterator       rpath_begin()       { return m_RpathList.begin(); }
312  const_rpath_iterator rpath_end  () const { return m_RpathList.end();   }
313  rpath_iterator       rpath_end  ()       { return m_RpathList.end();   }
314
315  // -----  link-in script  ----- //
316  const ScriptList& getScriptList() const { return m_ScriptList; }
317  ScriptList&       getScriptList()       { return m_ScriptList; }
318
319  const_script_iterator script_begin() const { return m_ScriptList.begin(); }
320  script_iterator       script_begin()       { return m_ScriptList.begin(); }
321  const_script_iterator script_end  () const { return m_ScriptList.end();   }
322  script_iterator       script_end  ()       { return m_ScriptList.end();   }
323
324  // -----  filter and auxiliary filter  ----- //
325  void setFilter(const std::string& pFilter)
326  { m_Filter = pFilter; }
327
328  const std::string& filter() const
329  { return m_Filter; }
330
331  bool hasFilter() const
332  { return !m_Filter.empty(); }
333
334  const AuxiliaryList& getAuxiliaryList() const { return m_AuxiliaryList; }
335  AuxiliaryList&       getAuxiliaryList()       { return m_AuxiliaryList; }
336
337  const_aux_iterator aux_begin() const { return m_AuxiliaryList.begin(); }
338  aux_iterator       aux_begin()       { return m_AuxiliaryList.begin(); }
339  const_aux_iterator aux_end  () const { return m_AuxiliaryList.end();   }
340  aux_iterator       aux_end  ()       { return m_AuxiliaryList.end();   }
341
342private:
343  enum status {
344    YES,
345    NO,
346    Unknown
347  };
348
349private:
350  std::string m_DefaultLDScript;
351  std::string m_Dyld;
352  std::string m_SOName;
353  int8_t m_Verbose;            // --verbose[=0,1,2]
354  uint16_t m_MaxErrorNum;      // --error-limit=N
355  uint16_t m_MaxWarnNum;       // --warning-limit=N
356  status m_ExecStack;          // execstack, noexecstack
357  status m_NoUndefined;        // defs, --no-undefined
358  status m_MulDefs;            // muldefs, --allow-multiple-definition
359  uint64_t m_CommPageSize;     // common-page-size=value
360  uint64_t m_MaxPageSize;      // max-page-size=value
361  bool m_bCombReloc     : 1;   // combreloc, nocombreloc
362  bool m_bInitFirst     : 1;   // initfirst
363  bool m_bInterPose     : 1;   // interpose
364  bool m_bLoadFltr      : 1;   // loadfltr
365  bool m_bNoCopyReloc   : 1;   // nocopyreloc
366  bool m_bNoDefaultLib  : 1;   // nodefaultlib
367  bool m_bNoDelete      : 1;   // nodelete
368  bool m_bNoDLOpen      : 1;   // nodlopen
369  bool m_bNoDump        : 1;   // nodump
370  bool m_bRelro         : 1;   // relro, norelro
371  bool m_bNow           : 1;   // lazy, now
372  bool m_bOrigin        : 1;   // origin
373  bool m_bTrace         : 1;   // --trace
374  bool m_Bsymbolic      : 1;   // --Bsymbolic
375  bool m_Bgroup         : 1;
376  bool m_bPIE           : 1;
377  bool m_bColor         : 1;   // --color[=true,false,auto]
378  bool m_bCreateEhFrameHdr : 1;    // --eh-frame-hdr
379  bool m_bNMagic : 1; // -n, --nmagic
380  bool m_bOMagic : 1; // -N, --omagic
381  bool m_bStripDebug : 1; // -S, --strip-debug
382  bool m_bExportDynamic :1; //-E, --export-dynamic
383  bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel
384  bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format]
385  bool m_bDefineCommon : 1; // -d, -dc, -dp
386  bool m_bFatalWarnings : 1; // --fatal-warnings
387  bool m_bNewDTags: 1; // --enable-new-dtags
388  bool m_bNoStdlib: 1; // -nostdlib
389  bool m_bPrintMap: 1; // --print-map
390  bool m_bWarnMismatch: 1; // --no-warn-mismatch
391  bool m_bGCSections: 1; // --gc-sections
392  bool m_bGenUnwindInfo: 1; // --ld-generated-unwind-info
393  uint32_t m_GPSize; // -G, --gpsize
394  StripSymbolMode m_StripSymbols;
395  RpathList m_RpathList;
396  ScriptList m_ScriptList;
397  unsigned int m_HashStyle;
398  std::string m_Filter;
399  AuxiliaryList m_AuxiliaryList;
400};
401
402} // namespace of mcld
403
404#endif
405
406