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