• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_StripSymbols(StripSymbolMode::KeepAllSymbols),
65       m_HashStyle(HashStyle::SystemV) {
66 }
67 
~GeneralOptions()68 GeneralOptions::~GeneralOptions() {
69 }
70 
setSOName(const std::string & pName)71 void GeneralOptions::setSOName(const std::string& pName) {
72   size_t pos = pName.find_last_of(sys::fs::separator);
73   if (std::string::npos == pos)
74     m_SOName = pName;
75   else
76     m_SOName = pName.substr(pos + 1);
77 }
78 
addZOption(const ZOption & pOption)79 void GeneralOptions::addZOption(const ZOption& pOption) {
80   switch (pOption.kind()) {
81     case ZOption::CombReloc:
82       m_bCombReloc = true;
83       break;
84     case ZOption::NoCombReloc:
85       m_bCombReloc = false;
86       break;
87     case ZOption::Defs:
88       m_NoUndefined = YES;
89       break;
90     case ZOption::ExecStack:
91       m_ExecStack = YES;
92       break;
93     case ZOption::NoExecStack:
94       m_ExecStack = NO;
95       break;
96     case ZOption::InitFirst:
97       m_bInitFirst = true;
98       break;
99     case ZOption::InterPose:
100       m_bInterPose = true;
101       break;
102     case ZOption::LoadFltr:
103       m_bLoadFltr = true;
104       break;
105     case ZOption::MulDefs:
106       m_MulDefs = YES;
107       break;
108     case ZOption::NoCopyReloc:
109       m_bNoCopyReloc = true;
110       break;
111     case ZOption::NoDefaultLib:
112       m_bNoDefaultLib = true;
113       break;
114     case ZOption::NoDelete:
115       m_bNoDelete = true;
116       break;
117     case ZOption::NoDLOpen:
118       m_bNoDLOpen = true;
119       break;
120     case ZOption::NoDump:
121       m_bNoDump = true;
122       break;
123     case ZOption::NoRelro:
124       m_bRelro = false;
125       break;
126     case ZOption::Relro:
127       m_bRelro = true;
128       break;
129     case ZOption::Lazy:
130       m_bNow = false;
131       break;
132     case ZOption::Now:
133       m_bNow = true;
134       break;
135     case ZOption::Origin:
136       m_bOrigin = true;
137       break;
138     case ZOption::CommPageSize:
139       m_CommPageSize = pOption.pageSize();
140       break;
141     case ZOption::MaxPageSize:
142       m_MaxPageSize = pOption.pageSize();
143       break;
144     case ZOption::Unknown:
145     default:
146       assert(false && "Not a recognized -z option.");
147       break;
148   }
149 }
150 
isInExcludeLIBS(const Input & pInput) const151 bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const {
152   assert(pInput.type() == Input::Archive);
153 
154   if (m_ExcludeLIBS.empty()) {
155     return false;
156   }
157 
158   // Specifying "--exclude-libs ALL" excludes symbols in all archive libraries
159   // from automatic export.
160   if (m_ExcludeLIBS.count("ALL") != 0) {
161     return true;
162   }
163 
164   std::string name(pInput.name());
165   name.append(".a");
166   if (m_ExcludeLIBS.count(name) != 0) {
167     return true;
168   }
169 
170   return false;
171 }
172 
173 }  // namespace mcld
174