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/Input.h"
11 #include "mcld/MC/ZOption.h"
12 #include <cassert>
13
14 namespace mcld {
15
16 //===----------------------------------------------------------------------===//
17 // GeneralOptions
18 //===----------------------------------------------------------------------===//
GeneralOptions()19 GeneralOptions::GeneralOptions()
20 : m_Verbose(-1),
21 m_MaxErrorNum(-1),
22 m_MaxWarnNum(-1),
23 m_NumSpareDTags(5),
24 m_ExecStack(Unknown),
25 m_NoUndefined(Unknown),
26 m_MulDefs(Unknown),
27 m_CommPageSize(0x0),
28 m_MaxPageSize(0x0),
29 m_bCombReloc(true),
30 m_bInitFirst(false),
31 m_bInterPose(false),
32 m_bLoadFltr(false),
33 m_bNoCopyReloc(false),
34 m_bNoDefaultLib(false),
35 m_bNoDelete(false),
36 m_bNoDLOpen(false),
37 m_bNoDump(false),
38 m_bRelro(false),
39 m_bNow(false),
40 m_bOrigin(false),
41 m_bTrace(false),
42 m_Bsymbolic(false),
43 m_Bgroup(false),
44 m_bPIE(false),
45 m_bColor(true),
46 m_bCreateEhFrameHdr(false),
47 m_bNMagic(false),
48 m_bOMagic(false),
49 m_bStripDebug(false),
50 m_bExportDynamic(false),
51 m_bWarnSharedTextrel(false),
52 m_bBinaryInput(false),
53 m_bDefineCommon(false),
54 m_bFatalWarnings(false),
55 m_bNewDTags(false),
56 m_bNoStdlib(false),
57 m_bWarnMismatch(true),
58 m_bGCSections(false),
59 m_bPrintGCSections(false),
60 m_bGenUnwindInfo(true),
61 m_bPrintICFSections(false),
62 m_ICF(ICF::None),
63 m_ICFIterations(2),
64 m_GPSize(8),
65 m_StripSymbols(StripSymbolMode::KeepAllSymbols),
66 m_HashStyle(HashStyle::SystemV) {
67 }
68
~GeneralOptions()69 GeneralOptions::~GeneralOptions() {
70 }
71
setSOName(const std::string & pName)72 void GeneralOptions::setSOName(const std::string& pName) {
73 size_t pos = pName.find_last_of(sys::fs::separator);
74 if (std::string::npos == pos)
75 m_SOName = pName;
76 else
77 m_SOName = pName.substr(pos + 1);
78 }
79
addZOption(const ZOption & pOption)80 void GeneralOptions::addZOption(const ZOption& pOption) {
81 switch (pOption.kind()) {
82 case ZOption::CombReloc:
83 m_bCombReloc = true;
84 break;
85 case ZOption::NoCombReloc:
86 m_bCombReloc = false;
87 break;
88 case ZOption::Defs:
89 m_NoUndefined = YES;
90 break;
91 case ZOption::ExecStack:
92 m_ExecStack = YES;
93 break;
94 case ZOption::NoExecStack:
95 m_ExecStack = NO;
96 break;
97 case ZOption::InitFirst:
98 m_bInitFirst = true;
99 break;
100 case ZOption::InterPose:
101 m_bInterPose = true;
102 break;
103 case ZOption::LoadFltr:
104 m_bLoadFltr = true;
105 break;
106 case ZOption::MulDefs:
107 m_MulDefs = YES;
108 break;
109 case ZOption::NoCopyReloc:
110 m_bNoCopyReloc = true;
111 break;
112 case ZOption::NoDefaultLib:
113 m_bNoDefaultLib = true;
114 break;
115 case ZOption::NoDelete:
116 m_bNoDelete = true;
117 break;
118 case ZOption::NoDLOpen:
119 m_bNoDLOpen = true;
120 break;
121 case ZOption::NoDump:
122 m_bNoDump = true;
123 break;
124 case ZOption::NoRelro:
125 m_bRelro = false;
126 break;
127 case ZOption::Relro:
128 m_bRelro = true;
129 break;
130 case ZOption::Lazy:
131 m_bNow = false;
132 break;
133 case ZOption::Now:
134 m_bNow = true;
135 break;
136 case ZOption::Origin:
137 m_bOrigin = true;
138 break;
139 case ZOption::CommPageSize:
140 m_CommPageSize = pOption.pageSize();
141 break;
142 case ZOption::MaxPageSize:
143 m_MaxPageSize = pOption.pageSize();
144 break;
145 case ZOption::Unknown:
146 default:
147 assert(false && "Not a recognized -z option.");
148 break;
149 }
150 }
151
isInExcludeLIBS(const Input & pInput) const152 bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const {
153 assert(pInput.type() == Input::Archive);
154
155 if (m_ExcludeLIBS.empty()) {
156 return false;
157 }
158
159 // Specifying "--exclude-libs ALL" excludes symbols in all archive libraries
160 // from automatic export.
161 if (m_ExcludeLIBS.count("ALL") != 0) {
162 return true;
163 }
164
165 std::string name(pInput.name());
166 name.append(".a");
167 if (m_ExcludeLIBS.count(name) != 0) {
168 return true;
169 }
170
171 return false;
172 }
173
174 } // namespace mcld
175