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