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