Coverage Report

Created: 2019-01-18 03:29

/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 CallGraphProfileSort;
131
  bool CheckSections;
132
  bool CompressDebugSections;
133
  bool Cref;
134
  bool DefineCommon;
135
  bool Demangle = true;
136
  bool DisableVerify;
137
  bool EhFrameHdr;
138
  bool EmitLLVM;
139
  bool EmitRelocs;
140
  bool EnableNewDtags;
141
  bool ExecuteOnly;
142
  bool ExportDynamic;
143
  bool FixCortexA53Errata843419;
144
  bool FormatBinary = false;
145
  bool GcSections;
146
  bool GdbIndex;
147
  bool GnuHash = false;
148
  bool GnuUnique;
149
  bool HasDynamicList = false;
150
  bool HasDynSymTab;
151
  bool IgnoreDataAddressEquality;
152
  bool IgnoreFunctionAddressEquality;
153
  bool LTODebugPassManager;
154
  bool LTONewPassManager;
155
  bool MergeArmExidx;
156
  bool MipsN32Abi = false;
157
  bool NoinhibitExec;
158
  bool Nostdlib;
159
  bool OFormatBinary;
160
  bool Omagic;
161
  bool OptRemarksWithHotness;
162
  bool PicThunk;
163
  bool Pie;
164
  bool PrintGcSections;
165
  bool PrintIcfSections;
166
  bool Relocatable;
167
  bool RelrPackDynRelocs;
168
  bool SaveTemps;
169
  bool SingleRoRx;
170
  bool Shared;
171
  bool Static = false;
172
  bool SysvHash = false;
173
  bool Target1Rel;
174
  bool Trace;
175
  bool ThinLTOEmitImportsFiles;
176
  bool ThinLTOIndexOnly;
177
  bool TocOptimize;
178
  bool UndefinedVersion;
179
  bool UseAndroidRelrTags = false;
180
  bool WarnBackrefs;
181
  bool WarnCommon;
182
  bool WarnIfuncTextrel;
183
  bool WarnMissingEntry;
184
  bool WarnSymbolOrdering;
185
  bool WriteAddends;
186
  bool ZCombreloc;
187
  bool ZCopyreloc;
188
  bool ZExecstack;
189
  bool ZGlobal;
190
  bool ZHazardplt;
191
  bool ZInitfirst;
192
  bool ZInterpose;
193
  bool ZKeepTextSectionPrefix;
194
  bool ZNodefaultlib;
195
  bool ZNodelete;
196
  bool ZNodlopen;
197
  bool ZNow;
198
  bool ZOrigin;
199
  bool ZRelro;
200
  bool ZRodynamic;
201
  bool ZText;
202
  bool ZRetpolineplt;
203
  bool ZWxneeded;
204
  DiscardPolicy Discard;
205
  ICFLevel ICF;
206
  OrphanHandlingPolicy OrphanHandling;
207
  SortSectionPolicy SortSection;
208
  StripPolicy Strip;
209
  UnresolvedPolicy UnresolvedSymbols;
210
  Target2Policy Target2;
211
  ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
212
  BuildIdKind BuildId = BuildIdKind::None;
213
  ELFKind EKind = ELFNoneKind;
214
  uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
215
  uint16_t EMachine = llvm::ELF::EM_NONE;
216
  llvm::Optional<uint64_t> ImageBase;
217
  uint64_t MaxPageSize;
218
  uint64_t MipsGotSize;
219
  uint64_t ZStackSize;
220
  unsigned LTOPartitions;
221
  unsigned LTOO;
222
  unsigned Optimize;
223
  unsigned ThinLTOJobs;
224
  int32_t SplitStackAdjustSize;
225
226
  // The following config options do not directly correspond to any
227
  // particualr command line options.
228
229
  // True if we need to pass through relocations in input files to the
230
  // output file. Usually false because we consume relocations.
231
  bool CopyRelocs;
232
233
  // True if the target is ELF64. False if ELF32.
234
  bool Is64;
235
236
  // True if the target is little-endian. False if big-endian.
237
  bool IsLE;
238
239
  // endianness::little if IsLE is true. endianness::big otherwise.
240
  llvm::support::endianness Endianness;
241
242
  // True if the target is the little-endian MIPS64.
243
  //
244
  // The reason why we have this variable only for the MIPS is because
245
  // we use this often.  Some ELF headers for MIPS64EL are in a
246
  // mixed-endian (which is horrible and I'd say that's a serious spec
247
  // bug), and we need to know whether we are reading MIPS ELF files or
248
  // not in various places.
249
  //
250
  // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
251
  // name whatever that means. A fun hypothesis is that "EL" is short for
252
  // little-endian written in the little-endian order, but I don't know
253
  // if that's true.)
254
  bool IsMips64EL;
255
256
  // Holds set of ELF header flags for the target.
257
  uint32_t EFlags = 0;
258
259
  // The ELF spec defines two types of relocation table entries, RELA and
260
  // REL. RELA is a triplet of (offset, info, addend) while REL is a
261
  // tuple of (offset, info). Addends for REL are implicit and read from
262
  // the location where the relocations are applied. So, REL is more
263
  // compact than RELA but requires a bit of more work to process.
264
  //
265
  // (From the linker writer's view, this distinction is not necessary.
266
  // If the ELF had chosen whichever and sticked with it, it would have
267
  // been easier to write code to process relocations, but it's too late
268
  // to change the spec.)
269
  //
270
  // Each ABI defines its relocation type. IsRela is true if target
271
  // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
272
  // few 32-bit ABIs are using RELA too.
273
  bool IsRela;
274
275
  // True if we are creating position-independent code.
276
  bool Pic;
277
278
  // 4 for ELF32, 8 for ELF64.
279
  int Wordsize;
280
};
281
282
// The only instance of Configuration struct.
283
extern Configuration *Config;
284
285
1.87k
static inline void errorOrWarn(const Twine &Msg) {
286
1.87k
  if (!Config->NoinhibitExec)
287
1.86k
    error(Msg);
288
8
  else
289
8
    warn(Msg);
290
1.87k
}
Unexecuted instantiation: AArch64ErrataFix.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
AArch64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
285
1.82k
static inline void errorOrWarn(const Twine &Msg) {
286
1.82k
  if (!Config->NoinhibitExec)
287
1.82k
    error(Msg);
288
0
  else
289
0
    warn(Msg);
290
1.82k
}
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: MSP430.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&)
X86.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
285
3
static inline void errorOrWarn(const Twine &Msg) {
286
3
  if (!Config->NoinhibitExec)
287
3
    error(Msg);
288
0
  else
289
0
    warn(Msg);
290
3
}
X86_64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
285
12
static inline void errorOrWarn(const Twine &Msg) {
286
12
  if (!Config->NoinhibitExec)
287
11
    error(Msg);
288
1
  else
289
1
    warn(Msg);
290
12
}
Unexecuted instantiation: CallGraphSort.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Unexecuted instantiation: DWARF.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: 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
285
22
static inline void errorOrWarn(const Twine &Msg) {
286
22
  if (!Config->NoinhibitExec)
287
20
    error(Msg);
288
2
  else
289
2
    warn(Msg);
290
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
285
15
static inline void errorOrWarn(const Twine &Msg) {
286
15
  if (!Config->NoinhibitExec)
287
10
    error(Msg);
288
5
  else
289
5
    warn(Msg);
290
15
}
291
} // namespace elf
292
} // namespace lld
293
294
#endif