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