Coverage Report

Created: 2018-06-18 20:01

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