1 //===- GeneralOptions.cpp -------------------------------------------------===//
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 #include <mcld/GeneralOptions.h>
10 #include <mcld/MC/MCLDInput.h>
11
12 using namespace mcld;
13
14 //===----------------------------------------------------------------------===//
15 // GeneralOptions
16 //===----------------------------------------------------------------------===//
GeneralOptions()17 GeneralOptions::GeneralOptions()
18 : m_pDefaultBitcode(NULL),
19 m_Verbose(-1),
20 m_MaxErrorNum(-1),
21 m_MaxWarnNum(-1),
22 m_ExecStack(Unknown),
23 m_CommPageSize(0x0),
24 m_MaxPageSize(0x0),
25 m_bCombReloc(true),
26 m_bNoUndefined(false),
27 m_bInitFirst(false),
28 m_bInterPose(false),
29 m_bLoadFltr(false),
30 m_bMulDefs(false),
31 m_bNoCopyReloc(false),
32 m_bNoDefaultLib(false),
33 m_bNoDelete(false),
34 m_bNoDLOpen(false),
35 m_bNoDump(false),
36 m_bRelro(false),
37 m_bNow(false),
38 m_bOrigin(false),
39 m_bTrace(false),
40 m_Bsymbolic(false),
41 m_Bgroup(false),
42 m_bPIE(false),
43 m_bColor(true),
44 m_bCreateEhFrameHdr(false),
45 m_bNMagic(false),
46 m_bOMagic(false),
47 m_bStripDebug(false),
48 m_bExportDynamic(false),
49 m_bWarnSharedTextrel(false),
50 m_bBinaryInput(false),
51 m_bDefineCommon(false),
52 m_bFatalWarnings(false),
53 m_bNewDTags(false),
54 m_bNoStdlib(false),
55 m_StripSymbols(KeepAllSymbols),
56 m_HashStyle(SystemV) {
57 }
58
~GeneralOptions()59 GeneralOptions::~GeneralOptions()
60 {
61 }
62
hasDefaultLDScript() const63 bool GeneralOptions::hasDefaultLDScript() const
64 {
65 return true;
66 }
67
defaultLDScript() const68 const char* GeneralOptions::defaultLDScript() const
69 {
70 return NULL;
71 }
72
setDefaultLDScript(const std::string & pFilename)73 void GeneralOptions::setDefaultLDScript(const std::string& pFilename)
74 {
75 }
76
sysroot() const77 const mcld::sys::fs::Path& GeneralOptions::sysroot() const
78 {
79 return m_SearchDirs.sysroot();
80 }
81
setSysroot(const mcld::sys::fs::Path & pSysroot)82 void GeneralOptions::setSysroot(const mcld::sys::fs::Path &pSysroot)
83 {
84 m_SearchDirs.setSysRoot(pSysroot);
85 }
86
hasSysroot() const87 bool GeneralOptions::hasSysroot() const
88 {
89 return !sysroot().empty();
90 }
91
setSOName(const std::string & pName)92 void GeneralOptions::setSOName(const std::string& pName)
93 {
94 size_t pos = pName.find_last_of(sys::fs::separator);
95 if (std::string::npos == pos)
96 m_SOName = pName;
97 else
98 m_SOName = pName.substr(pos + 1);
99 }
100
addZOption(const ZOption & pOption)101 void GeneralOptions::addZOption(const ZOption& pOption)
102 {
103 switch (pOption.kind()) {
104 case ZOption::CombReloc:
105 m_bCombReloc = true;
106 break;
107 case ZOption::NoCombReloc:
108 m_bCombReloc = false;
109 break;
110 case ZOption::Defs:
111 m_bNoUndefined = true;
112 break;
113 case ZOption::ExecStack:
114 m_ExecStack = YES;
115 break;
116 case ZOption::NoExecStack:
117 m_ExecStack = NO;
118 break;
119 case ZOption::InitFirst:
120 m_bInitFirst = true;
121 break;
122 case ZOption::InterPose:
123 m_bInterPose = true;
124 break;
125 case ZOption::LoadFltr:
126 m_bLoadFltr = true;
127 break;
128 case ZOption::MulDefs:
129 m_bMulDefs = true;
130 break;
131 case ZOption::NoCopyReloc:
132 m_bNoCopyReloc = true;
133 break;
134 case ZOption::NoDefaultLib:
135 m_bNoDefaultLib = true;
136 break;
137 case ZOption::NoDelete:
138 m_bNoDelete = true;
139 break;
140 case ZOption::NoDLOpen:
141 m_bNoDLOpen = true;
142 break;
143 case ZOption::NoDump:
144 m_bNoDump = true;
145 break;
146 case ZOption::NoRelro:
147 m_bRelro = false;
148 break;
149 case ZOption::Relro:
150 m_bRelro = true;
151 break;
152 case ZOption::Lazy:
153 m_bNow = false;
154 break;
155 case ZOption::Now:
156 m_bNow = true;
157 break;
158 case ZOption::Origin:
159 m_bOrigin = true;
160 break;
161 case ZOption::CommPageSize:
162 m_CommPageSize = pOption.pageSize();
163 break;
164 case ZOption::MaxPageSize:
165 m_MaxPageSize = pOption.pageSize();
166 break;
167 case ZOption::Unknown:
168 default:
169 assert(false && "Not a recognized -z option.");
170 break;
171 }
172 }
173