GeneralOptions.h revision 04c59f3b00def22b7c75f5a490c323cec58a7c71
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 setNumSpareDTags(uint32_t pNum) { 111 m_NumSpareDTags = pNum; 112 } 113 114 unsigned getNumSpareDTags() const { return m_NumSpareDTags; } 115 116 void setMulDefs(bool pEnable = true) { m_MulDefs = (pEnable ? YES : NO); } 117 118 void setEhFrameHdr(bool pEnable = true) { m_bCreateEhFrameHdr = pEnable; } 119 120 /// ----- the -z options ----- /// 121 void addZOption(const mcld::ZOption& pOption); 122 123 bool hasCombReloc() const { return m_bCombReloc; } 124 125 bool hasNoUndefined() const { return (Unknown != m_NoUndefined); } 126 127 bool isNoUndefined() const { return (YES == m_NoUndefined); } 128 129 bool hasStackSet() const { return (Unknown != m_ExecStack); } 130 131 bool hasExecStack() const { return (YES == m_ExecStack); } 132 133 bool hasInitFirst() const { return m_bInitFirst; } 134 135 bool hasInterPose() const { return m_bInterPose; } 136 137 bool hasLoadFltr() const { return m_bLoadFltr; } 138 139 bool hasMulDefs() const { return (Unknown != m_MulDefs); } 140 141 bool isMulDefs() const { return (YES == m_MulDefs); } 142 143 bool hasNoCopyReloc() const { return m_bNoCopyReloc; } 144 145 bool hasNoDefaultLib() const { return m_bNoDefaultLib; } 146 147 bool hasNoDelete() const { return m_bNoDelete; } 148 149 bool hasNoDLOpen() const { return m_bNoDLOpen; } 150 151 bool hasNoDump() const { return m_bNoDump; } 152 153 bool hasRelro() const { return m_bRelro; } 154 155 bool hasNow() const { return m_bNow; } 156 157 bool hasOrigin() const { return m_bOrigin; } 158 159 uint64_t commPageSize() const { return m_CommPageSize; } 160 161 uint64_t maxPageSize() const { return m_MaxPageSize; } 162 163 bool hasEhFrameHdr() const { return m_bCreateEhFrameHdr; } 164 165 // -n, --nmagic 166 void setNMagic(bool pMagic = true) { m_bNMagic = pMagic; } 167 168 bool nmagic() const { return m_bNMagic; } 169 170 // -N, --omagic 171 void setOMagic(bool pMagic = true) { m_bOMagic = pMagic; } 172 173 bool omagic() const { return m_bOMagic; } 174 175 // -S, --strip-debug 176 void setStripDebug(bool pStripDebug = true) { m_bStripDebug = pStripDebug; } 177 178 bool stripDebug() const { return m_bStripDebug; } 179 180 // -E, --export-dynamic 181 void setExportDynamic(bool pExportDynamic = true) { 182 m_bExportDynamic = pExportDynamic; 183 } 184 185 bool exportDynamic() const { return m_bExportDynamic; } 186 187 // --warn-shared-textrel 188 void setWarnSharedTextrel(bool pWarnSharedTextrel = true) { 189 m_bWarnSharedTextrel = pWarnSharedTextrel; 190 } 191 192 bool warnSharedTextrel() const { return m_bWarnSharedTextrel; } 193 194 void setBinaryInput(bool pBinaryInput = true) { 195 m_bBinaryInput = pBinaryInput; 196 } 197 198 bool isBinaryInput() const { return m_bBinaryInput; } 199 200 void setDefineCommon(bool pEnable = true) { m_bDefineCommon = pEnable; } 201 202 bool isDefineCommon() const { return m_bDefineCommon; } 203 204 void setFatalWarnings(bool pEnable = true) { m_bFatalWarnings = pEnable; } 205 206 bool isFatalWarnings() const { return m_bFatalWarnings; } 207 208 StripSymbolMode getStripSymbolMode() const { return m_StripSymbols; } 209 210 void setStripSymbols(StripSymbolMode pMode) { m_StripSymbols = pMode; } 211 212 void setNewDTags(bool pEnable = true) { m_bNewDTags = pEnable; } 213 214 bool hasNewDTags() const { return m_bNewDTags; } 215 216 void setNoStdlib(bool pEnable = true) { m_bNoStdlib = pEnable; } 217 218 bool nostdlib() const { return m_bNoStdlib; } 219 220 // -M, --print-map 221 void setPrintMap(bool pEnable = true) { m_bPrintMap = pEnable; } 222 223 bool printMap() const { return m_bPrintMap; } 224 225 void setWarnMismatch(bool pEnable = true) { m_bWarnMismatch = pEnable; } 226 227 bool warnMismatch() const { return m_bWarnMismatch; } 228 229 // --gc-sections 230 void setGCSections(bool pEnable = true) { m_bGCSections = pEnable; } 231 232 bool GCSections() const { return m_bGCSections; } 233 234 // --print-gc-sections 235 void setPrintGCSections(bool pEnable = true) { m_bPrintGCSections = pEnable; } 236 237 bool getPrintGCSections() const { return m_bPrintGCSections; } 238 239 // --ld-generated-unwind-info 240 void setGenUnwindInfo(bool pEnable = true) { m_bGenUnwindInfo = pEnable; } 241 242 bool genUnwindInfo() const { return m_bGenUnwindInfo; } 243 244 // -G, max GP size option 245 void setGPSize(int gpsize) { m_GPSize = gpsize; } 246 247 int getGPSize() const { return m_GPSize; } 248 249 unsigned int getHashStyle() const { return m_HashStyle; } 250 251 void setHashStyle(unsigned int pStyle) { m_HashStyle = pStyle; } 252 253 ICF getICFMode() const { return m_ICF; } 254 255 void setICFMode(ICF pMode) { m_ICF = pMode; } 256 257 size_t getICFIterations() const { return m_ICFIterations; } 258 259 void setICFIterations(size_t pNum) { m_ICFIterations = pNum; } 260 261 bool printICFSections() const { return m_bPrintICFSections; } 262 263 void setPrintICFSections(bool pPrintICFSections) { 264 m_bPrintICFSections = pPrintICFSections; 265 } 266 267 // ----- link-in rpath ----- // 268 const RpathList& getRpathList() const { return m_RpathList; } 269 RpathList& getRpathList() { return m_RpathList; } 270 271 const_rpath_iterator rpath_begin() const { return m_RpathList.begin(); } 272 rpath_iterator rpath_begin() { return m_RpathList.begin(); } 273 const_rpath_iterator rpath_end() const { return m_RpathList.end(); } 274 rpath_iterator rpath_end() { return m_RpathList.end(); } 275 276 // ----- link-in script ----- // 277 const ScriptList& getScriptList() const { return m_ScriptList; } 278 ScriptList& getScriptList() { return m_ScriptList; } 279 280 const_script_iterator script_begin() const { return m_ScriptList.begin(); } 281 script_iterator script_begin() { return m_ScriptList.begin(); } 282 const_script_iterator script_end() const { return m_ScriptList.end(); } 283 script_iterator script_end() { return m_ScriptList.end(); } 284 285 // ----- -u/--undefined, undefined symbols ----- // 286 const UndefSymList& getUndefSymList() const { return m_UndefSymList; } 287 UndefSymList& getUndefSymList() { return m_UndefSymList; } 288 289 const_undef_sym_iterator undef_sym_begin() const { 290 return m_UndefSymList.begin(); 291 } 292 undef_sym_iterator undef_sym_begin() { return m_UndefSymList.begin(); } 293 294 const_undef_sym_iterator undef_sym_end() const { 295 return m_UndefSymList.end(); 296 } 297 undef_sym_iterator undef_sym_end() { return m_UndefSymList.end(); } 298 299 // ----- filter and auxiliary filter ----- // 300 void setFilter(const std::string& pFilter) { m_Filter = pFilter; } 301 302 const std::string& filter() const { return m_Filter; } 303 304 bool hasFilter() const { return !m_Filter.empty(); } 305 306 const AuxiliaryList& getAuxiliaryList() const { return m_AuxiliaryList; } 307 AuxiliaryList& getAuxiliaryList() { return m_AuxiliaryList; } 308 309 const_aux_iterator aux_begin() const { return m_AuxiliaryList.begin(); } 310 aux_iterator aux_begin() { return m_AuxiliaryList.begin(); } 311 const_aux_iterator aux_end() const { return m_AuxiliaryList.end(); } 312 aux_iterator aux_end() { return m_AuxiliaryList.end(); } 313 314 // ----- exclude libs ----- // 315 ExcludeLIBS& excludeLIBS() { return m_ExcludeLIBS; } 316 317 bool isInExcludeLIBS(const Input& pInput) const; 318 319 const char* getVersionString() const { return PACKAGE_NAME " " MCLD_VERSION; } 320 321 private: 322 enum status { YES, NO, Unknown }; 323 324 private: 325 std::string m_DefaultLDScript; 326 std::string m_Dyld; 327 std::string m_SOName; 328 int8_t m_Verbose; // --verbose[=0,1,2] 329 uint16_t m_MaxErrorNum; // --error-limit=N 330 uint16_t m_MaxWarnNum; // --warning-limit=N 331 unsigned m_NumSpareDTags; // --spare-dynamic-tags 332 status m_ExecStack; // execstack, noexecstack 333 status m_NoUndefined; // defs, --no-undefined 334 status m_MulDefs; // muldefs, --allow-multiple-definition 335 uint64_t m_CommPageSize; // common-page-size=value 336 uint64_t m_MaxPageSize; // max-page-size=value 337 bool m_bCombReloc : 1; // combreloc, nocombreloc 338 bool m_bInitFirst : 1; // initfirst 339 bool m_bInterPose : 1; // interpose 340 bool m_bLoadFltr : 1; // loadfltr 341 bool m_bNoCopyReloc : 1; // nocopyreloc 342 bool m_bNoDefaultLib : 1; // nodefaultlib 343 bool m_bNoDelete : 1; // nodelete 344 bool m_bNoDLOpen : 1; // nodlopen 345 bool m_bNoDump : 1; // nodump 346 bool m_bRelro : 1; // relro, norelro 347 bool m_bNow : 1; // lazy, now 348 bool m_bOrigin : 1; // origin 349 bool m_bTrace : 1; // --trace 350 bool m_Bsymbolic : 1; // --Bsymbolic 351 bool m_Bgroup : 1; 352 bool m_bPIE : 1; 353 bool m_bColor : 1; // --color[=true,false,auto] 354 bool m_bCreateEhFrameHdr : 1; // --eh-frame-hdr 355 bool m_bNMagic : 1; // -n, --nmagic 356 bool m_bOMagic : 1; // -N, --omagic 357 bool m_bStripDebug : 1; // -S, --strip-debug 358 bool m_bExportDynamic : 1; // -E, --export-dynamic 359 bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel 360 bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format] 361 bool m_bDefineCommon : 1; // -d, -dc, -dp 362 bool m_bFatalWarnings : 1; // --fatal-warnings 363 bool m_bNewDTags : 1; // --enable-new-dtags 364 bool m_bNoStdlib : 1; // -nostdlib 365 bool m_bPrintMap : 1; // --print-map 366 bool m_bWarnMismatch : 1; // --no-warn-mismatch 367 bool m_bGCSections : 1; // --gc-sections 368 bool m_bPrintGCSections : 1; // --print-gc-sections 369 bool m_bGenUnwindInfo : 1; // --ld-generated-unwind-info 370 bool m_bPrintICFSections : 1; // --print-icf-sections 371 ICF m_ICF; 372 size_t m_ICFIterations; 373 uint32_t m_GPSize; // -G, --gpsize 374 StripSymbolMode m_StripSymbols; 375 RpathList m_RpathList; 376 ScriptList m_ScriptList; 377 UndefSymList m_UndefSymList; // -u [symbol], --undefined [symbol] 378 unsigned int m_HashStyle; 379 std::string m_Filter; 380 AuxiliaryList m_AuxiliaryList; 381 ExcludeLIBS m_ExcludeLIBS; 382}; 383 384} // namespace mcld 385 386#endif // MCLD_GENERALOPTIONS_H_ 387