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