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