Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Config.h
Line
Count
Source
1
//===- Config.h -------------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLD_ELF_CONFIG_H
10
#define LLD_ELF_CONFIG_H
11
12
#include "lld/Common/ErrorHandler.h"
13
#include "llvm/ADT/MapVector.h"
14
#include "llvm/ADT/StringRef.h"
15
#include "llvm/ADT/StringSet.h"
16
#include "llvm/BinaryFormat/ELF.h"
17
#include "llvm/Support/CachePruning.h"
18
#include "llvm/Support/CodeGen.h"
19
#include "llvm/Support/Endian.h"
20
#include <atomic>
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 LTOCSProfileFile;
96
  llvm::StringRef LTONewPmPasses;
97
  llvm::StringRef LTOObjPath;
98
  llvm::StringRef LTOSampleProfile;
99
  llvm::StringRef MapFile;
100
  llvm::StringRef OutputFile;
101
  llvm::StringRef OptRemarksFilename;
102
  llvm::StringRef OptRemarksPasses;
103
  llvm::StringRef ProgName;
104
  llvm::StringRef PrintSymbolOrder;
105
  llvm::StringRef SoName;
106
  llvm::StringRef Sysroot;
107
  llvm::StringRef ThinLTOCacheDir;
108
  llvm::StringRef ThinLTOIndexOnlyArg;
109
  std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
110
  std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
111
  std::string Rpath;
112
  std::vector<VersionDefinition> VersionDefinitions;
113
  std::vector<llvm::StringRef> AuxiliaryList;
114
  std::vector<llvm::StringRef> FilterList;
115
  std::vector<llvm::StringRef> SearchPaths;
116
  std::vector<llvm::StringRef> SymbolOrderingFile;
117
  std::vector<llvm::StringRef> Undefined;
118
  std::vector<SymbolVersion> DynamicList;
119
  std::vector<SymbolVersion> VersionScriptGlobals;
120
  std::vector<SymbolVersion> VersionScriptLocals;
121
  std::vector<uint8_t> BuildIdVector;
122
  llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
123
                  uint64_t>
124
      CallGraphProfile;
125
  bool AllowMultipleDefinition;
126
  bool AllowShlibUndefined;
127
  bool AndroidPackDynRelocs;
128
  bool ARMHasBlx = false;
129
  bool ARMHasMovtMovw = false;
130
  bool ARMJ1J2BranchEncoding = false;
131
  bool AsNeeded = false;
132
  bool Bsymbolic;
133
  bool BsymbolicFunctions;
134
  bool CallGraphProfileSort;
135
  bool CheckSections;
136
  bool CompressDebugSections;
137
  bool Cref;
138
  bool DefineCommon;
139
  bool Demangle = true;
140
  bool DependentLibraries;
141
  bool DisableVerify;
142
  bool EhFrameHdr;
143
  bool EmitLLVM;
144
  bool EmitRelocs;
145
  bool EnableNewDtags;
146
  bool ExecuteOnly;
147
  bool ExportDynamic;
148
  bool FixCortexA53Errata843419;
149
  bool FormatBinary = false;
150
  bool GcSections;
151
  bool GdbIndex;
152
  bool GnuHash = false;
153
  bool GnuUnique;
154
  bool HasDynamicList = false;
155
  bool HasDynSymTab;
156
  bool IgnoreDataAddressEquality;
157
  bool IgnoreFunctionAddressEquality;
158
  bool LTOCSProfileGenerate;
159
  bool LTODebugPassManager;
160
  bool LTONewPassManager;
161
  bool MergeArmExidx;
162
  bool MipsN32Abi = false;
163
  bool Nmagic;
164
  bool NoinhibitExec;
165
  bool Nostdlib;
166
  bool OFormatBinary;
167
  bool Omagic;
168
  bool OptRemarksWithHotness;
169
  bool PicThunk;
170
  bool Pie;
171
  bool PrintGcSections;
172
  bool PrintIcfSections;
173
  bool Relocatable;
174
  bool RelrPackDynRelocs;
175
  bool SaveTemps;
176
  bool SingleRoRx;
177
  bool Shared;
178
  bool Static = false;
179
  bool SysvHash = false;
180
  bool Target1Rel;
181
  bool Trace;
182
  bool ThinLTOEmitImportsFiles;
183
  bool ThinLTOIndexOnly;
184
  bool TocOptimize;
185
  bool UndefinedVersion;
186
  bool UseAndroidRelrTags = false;
187
  bool WarnBackrefs;
188
  bool WarnCommon;
189
  bool WarnIfuncTextrel;
190
  bool WarnMissingEntry;
191
  bool WarnSymbolOrdering;
192
  bool WriteAddends;
193
  bool ZCombreloc;
194
  bool ZCopyreloc;
195
  bool ZExecstack;
196
  bool ZGlobal;
197
  bool ZHazardplt;
198
  bool ZIfuncNoplt;
199
  bool ZInitfirst;
200
  bool ZInterpose;
201
  bool ZKeepTextSectionPrefix;
202
  bool ZNodefaultlib;
203
  bool ZNodelete;
204
  bool ZNodlopen;
205
  bool ZNow;
206
  bool ZOrigin;
207
  bool ZRelro;
208
  bool ZRodynamic;
209
  bool ZText;
210
  bool ZRetpolineplt;
211
  bool ZWxneeded;
212
  DiscardPolicy Discard;
213
  ICFLevel ICF;
214
  OrphanHandlingPolicy OrphanHandling;
215
  SortSectionPolicy SortSection;
216
  StripPolicy Strip;
217
  UnresolvedPolicy UnresolvedSymbols;
218
  Target2Policy Target2;
219
  ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
220
  BuildIdKind BuildId = BuildIdKind::None;
221
  ELFKind EKind = ELFNoneKind;
222
  uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
223
  uint16_t EMachine = llvm::ELF::EM_NONE;
224
  llvm::Optional<uint64_t> ImageBase;
225
  uint64_t CommonPageSize;
226
  uint64_t MaxPageSize;
227
  uint64_t MipsGotSize;
228
  uint64_t ZStackSize;
229
  unsigned LTOPartitions;
230
  unsigned LTOO;
231
  unsigned Optimize;
232
  unsigned ThinLTOJobs;
233
  int32_t SplitStackAdjustSize;
234
235
  // The following config options do not directly correspond to any
236
  // particualr command line options.
237
238
  // True if we need to pass through relocations in input files to the
239
  // output file. Usually false because we consume relocations.
240
  bool CopyRelocs;
241
242
  // True if the target is ELF64. False if ELF32.
243
  bool Is64;
244
245
  // True if the target is little-endian. False if big-endian.
246
  bool IsLE;
247
248
  // endianness::little if IsLE is true. endianness::big otherwise.
249
  llvm::support::endianness Endianness;
250
251
  // True if the target is the little-endian MIPS64.
252
  //
253
  // The reason why we have this variable only for the MIPS is because
254
  // we use this often.  Some ELF headers for MIPS64EL are in a
255
  // mixed-endian (which is horrible and I'd say that's a serious spec
256
  // bug), and we need to know whether we are reading MIPS ELF files or
257
  // not in various places.
258
  //
259
  // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
260
  // name whatever that means. A fun hypothesis is that "EL" is short for
261
  // little-endian written in the little-endian order, but I don't know
262
  // if that's true.)
263
  bool IsMips64EL;
264
265
  // True if we need to set the DF_STATIC_TLS flag to an output file,
266
  // which works as a hint to the dynamic loader that the file contains
267
  // code compiled with the static TLS model. The thread-local variable
268
  // compiled with the static TLS model is faster but less flexible, and
269
  // it may not be loaded using dlopen().
270
  //
271
  // We set this flag to true when we see a relocation for the static TLS
272
  // model. Once this becomes true, it will never become false.
273
  //
274
  // Since the flag is updated by multi-threaded code, we use std::atomic.
275
  // (Writing to a variable is not considered thread-safe even if the
276
  // variable is boolean and we always set the same value from all threads.)
277
  std::atomic<bool> HasStaticTlsModel{false};
278
279
  // Holds set of ELF header flags for the target.
280
  uint32_t EFlags = 0;
281
282
  // The ELF spec defines two types of relocation table entries, RELA and
283
  // REL. RELA is a triplet of (offset, info, addend) while REL is a
284
  // tuple of (offset, info). Addends for REL are implicit and read from
285
  // the location where the relocations are applied. So, REL is more
286
  // compact than RELA but requires a bit of more work to process.
287
  //
288
  // (From the linker writer's view, this distinction is not necessary.
289
  // If the ELF had chosen whichever and sticked with it, it would have
290
  // been easier to write code to process relocations, but it's too late
291
  // to change the spec.)
292
  //
293
  // Each ABI defines its relocation type. IsRela is true if target
294
  // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
295
  // few 32-bit ABIs are using RELA too.
296
  bool IsRela;
297
298
  // True if we are creating position-independent code.
299
  bool Pic;
300
301
  // 4 for ELF32, 8 for ELF64.
302
  int Wordsize;
303
};
304
305
// The only instance of Configuration struct.
306
extern Configuration *Config;
307
308
1.87k
static inline void errorOrWarn(const Twine &Msg) {
309
1.87k
  if (!Config->NoinhibitExec)
310
1.86k
    error(Msg);
311
8
  else
312
8
    warn(Msg);
313
1.87k
}
Unexecuted instantiation: AArch64ErrataFix.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
AArch64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
308
1.82k
static inline void errorOrWarn(const Twine &Msg) {
309
1.82k
  if (!Config->NoinhibitExec)
310
1.82k
    error(Msg);
311
0
  else
312
0
    warn(Msg);
313
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
308
3
static inline void errorOrWarn(const Twine &Msg) {
309
3
  if (!Config->NoinhibitExec)
310
3
    error(Msg);
311
0
  else
312
0
    warn(Msg);
313
3
}
X86_64.cpp:lld::elf::errorOrWarn(llvm::Twine const&)
Line
Count
Source
308
12
static inline void errorOrWarn(const Twine &Msg) {
309
12
  if (!Config->NoinhibitExec)
310
11
    error(Msg);
311
1
  else
312
1
    warn(Msg);
313
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: 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
308
22
static inline void errorOrWarn(const Twine &Msg) {
309
22
  if (!Config->NoinhibitExec)
310
20
    error(Msg);
311
2
  else
312
2
    warn(Msg);
313
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
308
13
static inline void errorOrWarn(const Twine &Msg) {
309
13
  if (!Config->NoinhibitExec)
310
8
    error(Msg);
311
5
  else
312
5
    warn(Msg);
313
13
}
314
} // namespace elf
315
} // namespace lld
316
317
#endif