Coverage Report

Created: 2018-08-19 14:04

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Config.h
Line
Count
Source
1
//===- Config.h -------------------------------------------------*- C++ -*-===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLD_ELF_CONFIG_H
11
#define LLD_ELF_CONFIG_H
12
13
#include "lld/Common/ErrorHandler.h"
14
#include "llvm/ADT/MapVector.h"
15
#include "llvm/ADT/StringRef.h"
16
#include "llvm/ADT/StringSet.h"
17
#include "llvm/BinaryFormat/ELF.h"
18
#include "llvm/Support/CachePruning.h"
19
#include "llvm/Support/CodeGen.h"
20
#include "llvm/Support/Endian.h"
21
#include <vector>
22
23
namespace lld {
24
namespace elf {
25
26
class InputFile;
27
class InputSectionBase;
28
29
enum ELFKind {
30
  ELFNoneKind,
31
  ELF32LEKind,
32
  ELF32BEKind,
33
  ELF64LEKind,
34
  ELF64BEKind
35
};
36
37
// For --build-id.
38
enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
39
40
// For --discard-{all,locals,none}.
41
enum class DiscardPolicy { Default, All, Locals, None };
42
43
// For --icf={none,safe,all}.
44
enum class ICFLevel { None, Safe, All };
45
46
// For --strip-{all,debug}.
47
enum class StripPolicy { None, All, Debug };
48
49
// For --unresolved-symbols.
50
enum class UnresolvedPolicy { ReportError, Warn, Ignore };
51
52
// For --orphan-handling.
53
enum class OrphanHandlingPolicy { Place, Warn, Error };
54
55
// For --sort-section and linkerscript sorting rules.
56
enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
57
58
// For --target2
59
enum class Target2Policy { Abs, Rel, GotRel };
60
61
// For tracking ARM Float Argument PCS
62
enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };
63
64
struct SymbolVersion {
65
  llvm::StringRef Name;
66
  bool IsExternCpp;
67
  bool HasWildcard;
68
};
69
70
// This struct contains symbols version definition that
71
// can be found in version script if it is used for link.
72
struct VersionDefinition {
73
  llvm::StringRef Name;
74
  uint16_t Id = 0;
75
  std::vector<SymbolVersion> Globals;
76
  size_t NameOff = 0; // Offset in the string table
77
};
78
79
// This struct contains the global configuration for the linker.
80
// Most fields are direct mapping from the command line options
81
// and such fields have the same name as the corresponding options.
82
// Most fields are initialized by the driver.
83
struct Configuration {
84
  uint8_t OSABI = 0;
85
  llvm::CachePruningPolicy ThinLTOCachePolicy;
86
  llvm::StringMap<uint64_t> SectionStartMap;
87
  llvm::StringRef Chroot;
88
  llvm::StringRef DynamicLinker;
89
  llvm::StringRef DwoDir;
90
  llvm::StringRef Entry;
91
  llvm::StringRef Emulation;
92
  llvm::StringRef Fini;
93
  llvm::StringRef Init;
94
  llvm::StringRef LTOAAPipeline;
95
  llvm::StringRef LTONewPmPasses;
96
  llvm::StringRef LTOObjPath;
97
  llvm::StringRef LTOSampleProfile;
98
  llvm::StringRef MapFile;
99
  llvm::StringRef OutputFile;
100
  llvm::StringRef OptRemarksFilename;
101
  llvm::StringRef ProgName;
102
  llvm::StringRef SoName;
103
  llvm::StringRef Sysroot;
104
  llvm::StringRef ThinLTOCacheDir;
105
  llvm::StringRef ThinLTOIndexOnlyArg;
106
  std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
107
  std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
108
  std::string Rpath;
109
  std::vector<VersionDefinition> VersionDefinitions;
110
  std::vector<llvm::StringRef> AuxiliaryList;
111
  std::vector<llvm::StringRef> FilterList;
112
  std::vector<llvm::StringRef> SearchPaths;
113
  std::vector<llvm::StringRef> SymbolOrderingFile;
114
  std::vector<llvm::StringRef> Undefined;
115
  std::vector<SymbolVersion> DynamicList;
116
  std::vector<SymbolVersion> VersionScriptGlobals;
117
  std::vector<SymbolVersion> VersionScriptLocals;
118
  std::vector<uint8_t> BuildIdVector;
119
  llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
120
                  uint64_t>
121
      CallGraphProfile;
122
  bool AllowMultipleDefinition;
123
  bool AndroidPackDynRelocs;
124
  bool ARMHasBlx = false;
125
  bool ARMHasMovtMovw = false;
126
  bool ARMJ1J2BranchEncoding = false;
127
  bool AsNeeded = false;
128
  bool Bsymbolic;
129
  bool BsymbolicFunctions;
130
  bool CheckSections;
131
  bool CompressDebugSections;
132
  bool Cref;
133
  bool DefineCommon;
134
  bool Demangle = true;
135
  bool DisableVerify;
136
  bool EhFrameHdr;
137
  bool EmitRelocs;
138
  bool EnableNewDtags;
139
  bool ExecuteOnly;
140
  bool ExportDynamic;
141
  bool FixCortexA53Errata843419;
142
  bool FormatBinary = false;
143
  bool GcSections;
144
  bool GdbIndex;
145
  bool GnuHash = false;
146
  bool GnuUnique;
147
  bool HasDynamicList = false;
148
  bool HasDynSymTab;
149
  bool IgnoreDataAddressEquality;
150
  bool IgnoreFunctionAddressEquality;
151
  bool LTODebugPassManager;
152
  bool LTONewPassManager;
153
  bool MergeArmExidx;
154
  bool MipsN32Abi = false;
155
  bool NoinhibitExec;
156
  bool Nostdlib;
157
  bool OFormatBinary;
158
  bool Omagic;
159
  bool OptRemarksWithHotness;
160
  bool Pie;
161
  bool PrintGcSections;
162
  bool PrintIcfSections;
163
  bool Relocatable;
164
  bool RelrPackDynRelocs;
165
  bool SaveTemps;
166
  bool SingleRoRx;
167
  bool Shared;
168
  bool Static = false;
169
  bool SysvHash = false;
170
  bool Target1Rel;
171
  bool Trace;
172
  bool ThinLTOEmitImportsFiles;
173
  bool ThinLTOIndexOnly;
174
  bool UndefinedVersion;
175
  bool UseAndroidRelrTags = false;
176
  bool WarnBackrefs;
177
  bool WarnCommon;
178
  bool WarnMissingEntry;
179
  bool WarnSymbolOrdering;
180
  bool WriteAddends;
181
  bool ZCombreloc;
182
  bool ZCopyreloc;
183
  bool ZExecstack;
184
  bool ZHazardplt;
185
  bool ZInitfirst;
186
  bool ZKeepTextSectionPrefix;
187
  bool ZNodelete;
188
  bool ZNodlopen;
189
  bool ZNow;
190
  bool ZOrigin;
191
  bool ZRelro;
192
  bool ZRodynamic;
193
  bool ZText;
194
  bool ZRetpolineplt;
195
  bool ZWxneeded;
196
  DiscardPolicy Discard;
197
  ICFLevel ICF;
198
  OrphanHandlingPolicy OrphanHandling;
199
  SortSectionPolicy SortSection;
200
  StripPolicy Strip;
201
  UnresolvedPolicy UnresolvedSymbols;
202
  Target2Policy Target2;
203
  ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
204
  BuildIdKind BuildId = BuildIdKind::None;
205
  ELFKind EKind = ELFNoneKind;
206
  uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
207
  uint16_t EMachine = llvm::ELF::EM_NONE;
208
  llvm::Optional<uint64_t> ImageBase;
209
  uint64_t MaxPageSize;
210
  uint64_t MipsGotSize;
211
  uint64_t ZStackSize;
212
  unsigned LTOPartitions;
213
  unsigned LTOO;
214
  unsigned Optimize;
215
  unsigned ThinLTOJobs;
216
217
  // The following config options do not directly correspond to any
218
  // particualr command line options.
219
220
  // True if we need to pass through relocations in input files to the
221
  // output file. Usually false because we consume relocations.
222
  bool CopyRelocs;
223
224
  // True if the target is ELF64. False if ELF32.
225
  bool Is64;
226
227
  // True if the target is little-endian. False if big-endian.
228
  bool IsLE;
229
230
  // endianness::little if IsLE is true. endianness::big otherwise.
231
  llvm::support::endianness Endianness;
232
233
  // True if the target is the little-endian MIPS64.
234
  //
235
  // The reason why we have this variable only for the MIPS is because
236
  // we use this often.  Some ELF headers for MIPS64EL are in a
237
  // mixed-endian (which is horrible and I'd say that's a serious spec
238
  // bug), and we need to know whether we are reading MIPS ELF files or
239
  // not in various places.
240
  //
241
  // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
242
  // name whatever that means. A fun hypothesis is that "EL" is short for
243
  // little-endian written in the little-endian order, but I don't know
244
  // if that's true.)
245
  bool IsMips64EL;
246
247
  // Holds set of ELF header flags for the target.
248
  uint32_t EFlags = 0;
249
250
  // The ELF spec defines two types of relocation table entries, RELA and
251
  // REL. RELA is a triplet of (offset, info, addend) while REL is a
252
  // tuple of (offset, info). Addends for REL are implicit and read from
253
  // the location where the relocations are applied. So, REL is more
254
  // compact than RELA but requires a bit of more work to process.
255
  //
256
  // (From the linker writer's view, this distinction is not necessary.
257
  // If the ELF had chosen whichever and sticked with it, it would have
258
  // been easier to write code to process relocations, but it's too late
259
  // to change the spec.)
260
  //
261
  // Each ABI defines its relocation type. IsRela is true if target
262
  // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
263
  // few 32-bit ABIs are using RELA too.
264
  bool IsRela;
265
266
  // True if we are creating position-independent code.
267
  bool Pic;
268
269
  // 4 for ELF32, 8 for ELF64.
270
  int Wordsize;
271
};
272
273
// The only instance of Configuration struct.
274
extern Configuration *Config;
275
276
37
static inline void errorOrWarn(const Twine &Msg) {
277
37
  if (!Config->NoinhibitExec)
278
30
    error(Msg);
279
7
  else
280
7
    warn(Msg);
281
37
}
Unexecuted instantiation: AArch64ErrataFix.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: AArch64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: AMDGPU.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: ARM.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: AVR.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Hexagon.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Mips.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: MipsArchTree.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: PPC.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: PPC64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: RISCV.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: SPARCV9.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: X86.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: X86_64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: CallGraphSort.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Driver.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: DriverUtils.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: EhFrame.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Filesystem.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: GdbIndex.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: ICF.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: InputFiles.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: InputSection.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: LTO.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: LinkerScript.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: MapFile.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: MarkLive.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: OutputSections.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Relocations.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
276
22
static inline void errorOrWarn(const Twine &Msg) {
277
22
  if (!Config->NoinhibitExec)
278
20
    error(Msg);
279
2
  else
280
2
    warn(Msg);
281
22
}
Unexecuted instantiation: ScriptParser.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: SymbolTable.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Symbols.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: SyntheticSections.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Target.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: Thunks.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Writer.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
276
15
static inline void errorOrWarn(const Twine &Msg) {
277
15
  if (!Config->NoinhibitExec)
278
10
    error(Msg);
279
5
  else
280
5
    warn(Msg);
281
15
}
282
} // namespace elf
283
} // namespace lld
284
285
#endif