Coverage Report

Created: 2018-10-23 15:26

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Symbols.h
Line
Count
Source (jump to first uncovered line)
1
//===- Symbols.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
// This file defines various types of Symbols.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLD_ELF_SYMBOLS_H
15
#define LLD_ELF_SYMBOLS_H
16
17
#include "InputSection.h"
18
#include "lld/Common/LLVM.h"
19
#include "lld/Common/Strings.h"
20
#include "llvm/Object/Archive.h"
21
#include "llvm/Object/ELF.h"
22
23
namespace lld {
24
namespace elf {
25
class Symbol;
26
class InputFile;
27
} // namespace elf
28
29
std::string toString(const elf::Symbol &);
30
std::string toString(const elf::InputFile *);
31
32
namespace elf {
33
34
class ArchiveFile;
35
class BitcodeFile;
36
class BssSection;
37
class InputFile;
38
class LazyObjFile;
39
template <class ELFT> class ObjFile;
40
class OutputSection;
41
template <class ELFT> class SharedFile;
42
43
// This is a StringRef-like container that doesn't run strlen().
44
//
45
// ELF string tables contain a lot of null-terminated strings. Most of them
46
// are not necessary for the linker because they are names of local symbols,
47
// and the linker doesn't use local symbol names for name resolution. So, we
48
// use this class to represents strings read from string tables.
49
struct StringRefZ {
50
136k
  StringRefZ(const char *S) : Data(S), Size(-1) {}
51
20.0k
  StringRefZ(StringRef S) : Data(S.data()), Size(S.size()) {}
52
53
  const char *Data;
54
  const uint32_t Size;
55
};
56
57
// The base class for real symbol classes.
58
class Symbol {
59
public:
60
  enum Kind {
61
    PlaceholderKind,
62
    DefinedKind,
63
    SharedKind,
64
    UndefinedKind,
65
    LazyArchiveKind,
66
    LazyObjectKind,
67
  };
68
69
119k
  Kind kind() const { return static_cast<Kind>(SymbolKind); }
70
71
  // The file from which this symbol was created.
72
  InputFile *File;
73
74
protected:
75
  const char *NameData;
76
  mutable uint32_t NameSize;
77
78
public:
79
  uint32_t DynsymIndex = 0;
80
  uint32_t GotIndex = -1;
81
  uint32_t PltIndex = -1;
82
  uint32_t GlobalDynIndex = -1;
83
84
  // This field is a index to the symbol's version definition.
85
  uint32_t VerdefIndex = -1;
86
87
  // Version definition index.
88
  uint16_t VersionId;
89
90
  // Symbol binding. This is not overwritten by replaceSymbol to track
91
  // changes during resolution. In particular:
92
  //  - An undefined weak is still weak when it resolves to a shared library.
93
  //  - An undefined weak will not fetch archive members, but we have to
94
  //    remember it is weak.
95
  uint8_t Binding;
96
97
  // The following fields have the same meaning as the ELF symbol attributes.
98
  uint8_t Type;    // symbol type
99
  uint8_t StOther; // st_other field value
100
101
  uint8_t SymbolKind;
102
103
  // Symbol visibility. This is the computed minimum visibility of all
104
  // observed non-DSO symbols.
105
  unsigned Visibility : 2;
106
107
  // True if the symbol was used for linking and thus need to be added to the
108
  // output file's symbol table. This is true for all symbols except for
109
  // unreferenced DSO symbols and bitcode symbols that are unreferenced except
110
  // by other bitcode objects.
111
  unsigned IsUsedInRegularObj : 1;
112
113
  // If this flag is true and the symbol has protected or default visibility, it
114
  // will appear in .dynsym. This flag is set by interposable DSO symbols in
115
  // executables, by most symbols in DSOs and executables built with
116
  // --export-dynamic, and by dynamic lists.
117
  unsigned ExportDynamic : 1;
118
119
  // False if LTO shouldn't inline whatever this symbol points to. If a symbol
120
  // is overwritten after LTO, LTO shouldn't inline the symbol because it
121
  // doesn't know the final contents of the symbol.
122
  unsigned CanInline : 1;
123
124
  // True if this symbol is specified by --trace-symbol option.
125
  unsigned Traced : 1;
126
127
  bool includeInDynsym() const;
128
  uint8_t computeBinding() const;
129
3.58k
  bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
130
131
15.4k
  bool isUndefined() const { return SymbolKind == UndefinedKind; }
132
18.8M
  bool isDefined() const { return SymbolKind == DefinedKind; }
133
489
  bool isShared() const { return SymbolKind == SharedKind; }
134
438k
  bool isLocal() const { return Binding == llvm::ELF::STB_LOCAL; }
135
136
2.10k
  bool isLazy() const {
137
2.10k
    return SymbolKind == LazyArchiveKind || 
SymbolKind == LazyObjectKind2.03k
;
138
2.10k
  }
139
140
  // True if this is an undefined weak symbol. This only works once
141
  // all input files have been added.
142
2.69k
  bool isUndefWeak() const {
143
2.69k
    // See comment on lazy symbols for details.
144
2.69k
    return isWeak() && 
(96
isUndefined()96
||
isLazy()33
);
145
2.69k
  }
146
147
177k
  StringRef getName() const {
148
177k
    if (NameSize == (uint32_t)-1)
149
133k
      NameSize = strlen(NameData);
150
177k
    return {NameData, NameSize};
151
177k
  }
152
153
12
  void setName(StringRef S) {
154
12
    NameData = S.data();
155
12
    NameSize = S.size();
156
12
  }
157
158
  void parseSymbolVersion();
159
160
754
  bool isInGot() const { return GotIndex != -1U; }
161
12.0k
  bool isInPlt() const { return PltIndex != -1U; }
162
163
  uint64_t getVA(int64_t Addend = 0) const;
164
165
  uint64_t getGotOffset() const;
166
  uint64_t getGotVA() const;
167
  uint64_t getGotPltOffset() const;
168
  uint64_t getGotPltVA() const;
169
  uint64_t getPltVA() const;
170
  uint64_t getPltOffset() const;
171
  uint64_t getSize() const;
172
  OutputSection *getOutputSection() const;
173
174
protected:
175
  Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
176
         uint8_t StOther, uint8_t Type)
177
      : File(File), NameData(Name.Data), NameSize(Name.Size), Binding(Binding),
178
        Type(Type), StOther(StOther), SymbolKind(K), NeedsPltAddr(false),
179
        IsInIplt(false), IsInIgot(false), IsPreemptible(false),
180
        Used(!Config->GcSections), NeedsTocRestore(false),
181
156k
        ScriptDefined(false) {}
182
183
public:
184
  // True the symbol should point to its PLT entry.
185
  // For SharedSymbol only.
186
  unsigned NeedsPltAddr : 1;
187
188
  // True if this symbol is in the Iplt sub-section of the Plt.
189
  unsigned IsInIplt : 1;
190
191
  // True if this symbol is in the Igot sub-section of the .got.plt or .got.
192
  unsigned IsInIgot : 1;
193
194
  // True if this symbol is preemptible at load time.
195
  unsigned IsPreemptible : 1;
196
197
  // True if an undefined or shared symbol is used from a live section.
198
  unsigned Used : 1;
199
200
  // True if a call to this symbol needs to be followed by a restore of the
201
  // PPC64 toc pointer.
202
  unsigned NeedsTocRestore : 1;
203
204
  // True if this symbol is defined by a linker script.
205
  unsigned ScriptDefined : 1;
206
207
167k
  bool isSection() const { return Type == llvm::ELF::STT_SECTION; }
208
135k
  bool isTls() const { return Type == llvm::ELF::STT_TLS; }
209
186
  bool isFunc() const { return Type == llvm::ELF::STT_FUNC; }
210
13.9k
  bool isGnuIFunc() const { return Type == llvm::ELF::STT_GNU_IFUNC; }
211
119
  bool isObject() const { return Type == llvm::ELF::STT_OBJECT; }
212
0
  bool isFile() const { return Type == llvm::ELF::STT_FILE; }
213
};
214
215
// Represents a symbol that is defined in the current output file.
216
class Defined : public Symbol {
217
public:
218
  Defined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
219
          uint8_t Type, uint64_t Value, uint64_t Size, SectionBase *Section)
220
      : Symbol(DefinedKind, File, Name, Binding, StOther, Type), Value(Value),
221
151k
        Size(Size), Section(Section) {}
222
223
18.8M
  static bool classof(const Symbol *S) { return S->isDefined(); }
224
225
  uint64_t Value;
226
  uint64_t Size;
227
  SectionBase *Section;
228
};
229
230
class Undefined : public Symbol {
231
public:
232
  Undefined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
233
            uint8_t Type)
234
4.63k
      : Symbol(UndefinedKind, File, Name, Binding, StOther, Type) {}
235
236
0
  static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; }
237
};
238
239
class SharedSymbol : public Symbol {
240
public:
241
16.9k
  static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
242
243
  SharedSymbol(InputFile &File, StringRef Name, uint8_t Binding,
244
               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
245
               uint32_t Alignment, uint32_t VerdefIndex)
246
      : Symbol(SharedKind, &File, Name, Binding, StOther, Type),
247
821
        Alignment(Alignment), Value(Value), Size(Size) {
248
821
    this->VerdefIndex = VerdefIndex;
249
821
    // GNU ifunc is a mechanism to allow user-supplied functions to
250
821
    // resolve PLT slot values at load-time. This is contrary to the
251
821
    // regular symbol resolution scheme in which symbols are resolved just
252
821
    // by name. Using this hook, you can program how symbols are solved
253
821
    // for you program. For example, you can make "memcpy" to be resolved
254
821
    // to a SSE-enabled version of memcpy only when a machine running the
255
821
    // program supports the SSE instruction set.
256
821
    //
257
821
    // Naturally, such symbols should always be called through their PLT
258
821
    // slots. What GNU ifunc symbols point to are resolver functions, and
259
821
    // calling them directly doesn't make sense (unless you are writing a
260
821
    // loader).
261
821
    //
262
821
    // For DSO symbols, we always call them through PLT slots anyway.
263
821
    // So there's no difference between GNU ifunc and regular function
264
821
    // symbols if they are in DSOs. So we can handle GNU_IFUNC as FUNC.
265
821
    if (this->Type == llvm::ELF::STT_GNU_IFUNC)
266
3
      this->Type = llvm::ELF::STT_FUNC;
267
821
  }
268
269
855
  template <class ELFT> SharedFile<ELFT> &getFile() const {
270
855
    return *cast<SharedFile<ELFT>>(File);
271
855
  }
lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >& lld::elf::SharedSymbol::getFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >() const
Line
Count
Source
269
133
  template <class ELFT> SharedFile<ELFT> &getFile() const {
270
133
    return *cast<SharedFile<ELFT>>(File);
271
133
  }
lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >& lld::elf::SharedSymbol::getFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >() const
Line
Count
Source
269
105
  template <class ELFT> SharedFile<ELFT> &getFile() const {
270
105
    return *cast<SharedFile<ELFT>>(File);
271
105
  }
lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >& lld::elf::SharedSymbol::getFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >() const
Line
Count
Source
269
583
  template <class ELFT> SharedFile<ELFT> &getFile() const {
270
583
    return *cast<SharedFile<ELFT>>(File);
271
583
  }
lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >& lld::elf::SharedSymbol::getFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >() const
Line
Count
Source
269
34
  template <class ELFT> SharedFile<ELFT> &getFile() const {
270
34
    return *cast<SharedFile<ELFT>>(File);
271
34
  }
272
273
  uint32_t Alignment;
274
275
  uint64_t Value; // st_value
276
  uint64_t Size;  // st_size
277
};
278
279
// LazyArchive and LazyObject represent a symbols that is not yet in the link,
280
// but we know where to find it if needed. If the resolver finds both Undefined
281
// and Lazy for the same name, it will ask the Lazy to load a file.
282
//
283
// A special complication is the handling of weak undefined symbols. They should
284
// not load a file, but we have to remember we have seen both the weak undefined
285
// and the lazy. We represent that with a lazy symbol with a weak binding. This
286
// means that code looking for undefined symbols normally also has to take lazy
287
// symbols into consideration.
288
289
// This class represents a symbol defined in an archive file. It is
290
// created from an archive file header, and it knows how to load an
291
// object file from an archive to replace itself with a defined
292
// symbol.
293
class LazyArchive : public Symbol {
294
public:
295
  LazyArchive(InputFile &File, uint8_t Type,
296
              const llvm::object::Archive::Symbol S)
297
      : Symbol(LazyArchiveKind, &File, S.getName(), llvm::ELF::STB_GLOBAL,
298
               llvm::ELF::STV_DEFAULT, Type),
299
105
        Sym(S) {}
300
301
42
  static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }
302
303
  InputFile *fetch();
304
  MemoryBufferRef getMemberBuffer();
305
306
private:
307
  const llvm::object::Archive::Symbol Sym;
308
};
309
310
// LazyObject symbols represents symbols in object files between
311
// --start-lib and --end-lib options.
312
class LazyObject : public Symbol {
313
public:
314
  LazyObject(InputFile &File, uint8_t Type, StringRef Name)
315
      : Symbol(LazyObjectKind, &File, Name, llvm::ELF::STB_GLOBAL,
316
21
               llvm::ELF::STV_DEFAULT, Type) {}
317
318
4
  static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }
319
};
320
321
// Some linker-generated symbols need to be created as
322
// Defined symbols.
323
struct ElfSym {
324
  // __bss_start
325
  static Defined *Bss;
326
327
  // etext and _etext
328
  static Defined *Etext1;
329
  static Defined *Etext2;
330
331
  // edata and _edata
332
  static Defined *Edata1;
333
  static Defined *Edata2;
334
335
  // end and _end
336
  static Defined *End1;
337
  static Defined *End2;
338
339
  // The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to
340
  // be at some offset from the base of the .got section, usually 0 or
341
  // the end of the .got.
342
  static Defined *GlobalOffsetTable;
343
344
  // _gp, _gp_disp and __gnu_local_gp symbols. Only for MIPS.
345
  static Defined *MipsGp;
346
  static Defined *MipsGpDisp;
347
  static Defined *MipsLocalGp;
348
349
  // __rela_iplt_end or __rel_iplt_end
350
  static Defined *RelaIpltEnd;
351
352
  // __global_pointer$ in RISC-V.
353
  static Defined *RISCVGlobalPointer;
354
};
355
356
// A buffer class that is large enough to hold any Symbol-derived
357
// object. We allocate memory using this class and instantiate a symbol
358
// using the placement new.
359
union SymbolUnion {
360
  alignas(Defined) char A[sizeof(Defined)];
361
  alignas(Undefined) char C[sizeof(Undefined)];
362
  alignas(SharedSymbol) char D[sizeof(SharedSymbol)];
363
  alignas(LazyArchive) char E[sizeof(LazyArchive)];
364
  alignas(LazyObject) char F[sizeof(LazyObject)];
365
};
366
367
void printTraceSymbol(Symbol *Sym);
368
369
template <typename T, typename... ArgT>
370
19.5k
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
19.5k
  using llvm::ELF::STT_TLS;
372
19.5k
373
19.5k
  static_assert(std::is_trivially_destructible<T>(),
374
19.5k
                "Symbol types must be trivially destructible");
375
19.5k
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
19.5k
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
19.5k
                "SymbolUnion not aligned enough");
378
19.5k
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
19.5k
         "Not a Symbol");
380
19.5k
381
19.5k
  Symbol Sym = *S;
382
19.5k
383
19.5k
  new (S) T(std::forward<ArgT>(Arg)...);
384
19.5k
385
19.5k
  S->VersionId = Sym.VersionId;
386
19.5k
  S->Visibility = Sym.Visibility;
387
19.5k
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
19.5k
  S->ExportDynamic = Sym.ExportDynamic;
389
19.5k
  S->CanInline = Sym.CanInline;
390
19.5k
  S->Traced = Sym.Traced;
391
19.5k
  S->ScriptDefined = Sym.ScriptDefined;
392
19.5k
393
19.5k
  // Symbols representing thread-local variables must be referenced by
394
19.5k
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
19.5k
  // non-TLS relocations, so there's a clear distinction between TLS
396
19.5k
  // and non-TLS symbols. It is an error if the same symbol is defined
397
19.5k
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
19.5k
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS45
) ||
399
19.5k
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS19.5k
);
400
19.5k
401
19.5k
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch2.05k
&&
!Sym.isLazy()2
)
402
1
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
1
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
19.5k
405
19.5k
  // Print out a log message if --trace-symbol was specified.
406
19.5k
  // This is for debugging.
407
19.5k
  if (S->Traced)
408
54
    printTraceSymbol(S);
409
19.5k
}
Driver.cpp:void lld::elf::replaceSymbol<lld::elf::Undefined, std::nullptr_t, llvm::StringRef, llvm::ELF::$_8, unsigned char&, unsigned char&>(lld::elf::Symbol*, std::nullptr_t&&, llvm::StringRef&&, llvm::ELF::$_8&&, unsigned char&&&, unsigned char&&&)
Line
Count
Source
370
26
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
26
  using llvm::ELF::STT_TLS;
372
26
373
26
  static_assert(std::is_trivially_destructible<T>(),
374
26
                "Symbol types must be trivially destructible");
375
26
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
26
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
26
                "SymbolUnion not aligned enough");
378
26
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
26
         "Not a Symbol");
380
26
381
26
  Symbol Sym = *S;
382
26
383
26
  new (S) T(std::forward<ArgT>(Arg)...);
384
26
385
26
  S->VersionId = Sym.VersionId;
386
26
  S->Visibility = Sym.Visibility;
387
26
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
26
  S->ExportDynamic = Sym.ExportDynamic;
389
26
  S->CanInline = Sym.CanInline;
390
26
  S->Traced = Sym.Traced;
391
26
  S->ScriptDefined = Sym.ScriptDefined;
392
26
393
26
  // Symbols representing thread-local variables must be referenced by
394
26
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
26
  // non-TLS relocations, so there's a clear distinction between TLS
396
26
  // and non-TLS symbols. It is an error if the same symbol is defined
397
26
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
26
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
26
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
26
401
26
  if (Sym.SymbolKind != Symbol::PlaceholderKind && TlsMismatch && 
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
26
405
26
  // Print out a log message if --trace-symbol was specified.
406
26
  // This is for debugging.
407
26
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
26
}
LTO.cpp:void lld::elf::replaceSymbol<lld::elf::Undefined, std::nullptr_t, llvm::StringRef, llvm::ELF::$_3, llvm::ELF::$_4, unsigned char&>(lld::elf::Symbol*, std::nullptr_t&&, llvm::StringRef&&, llvm::ELF::$_3&&, llvm::ELF::$_4&&, unsigned char&&&)
Line
Count
Source
370
265
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
265
  using llvm::ELF::STT_TLS;
372
265
373
265
  static_assert(std::is_trivially_destructible<T>(),
374
265
                "Symbol types must be trivially destructible");
375
265
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
265
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
265
                "SymbolUnion not aligned enough");
378
265
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
265
         "Not a Symbol");
380
265
381
265
  Symbol Sym = *S;
382
265
383
265
  new (S) T(std::forward<ArgT>(Arg)...);
384
265
385
265
  S->VersionId = Sym.VersionId;
386
265
  S->Visibility = Sym.Visibility;
387
265
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
265
  S->ExportDynamic = Sym.ExportDynamic;
389
265
  S->CanInline = Sym.CanInline;
390
265
  S->Traced = Sym.Traced;
391
265
  S->ScriptDefined = Sym.ScriptDefined;
392
265
393
265
  // Symbols representing thread-local variables must be referenced by
394
265
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
265
  // non-TLS relocations, so there's a clear distinction between TLS
396
265
  // and non-TLS symbols. It is an error if the same symbol is defined
397
265
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
265
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS1
) ||
399
265
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS264
);
400
265
401
265
  if (Sym.SymbolKind != Symbol::PlaceholderKind && TlsMismatch && 
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
265
405
265
  // Print out a log message if --trace-symbol was specified.
406
265
  // This is for debugging.
407
265
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
265
}
LinkerScript.cpp:void lld::elf::replaceSymbol<lld::elf::Defined, std::nullptr_t, llvm::StringRef&, llvm::ELF::$_1, unsigned char&, llvm::ELF::$_2, int, int, std::nullptr_t>(lld::elf::Symbol*, std::nullptr_t&&, llvm::StringRef&&&, llvm::ELF::$_1&&, unsigned char&&&, llvm::ELF::$_2&&, int&&, int&&, std::nullptr_t&&)
Line
Count
Source
370
333
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
333
  using llvm::ELF::STT_TLS;
372
333
373
333
  static_assert(std::is_trivially_destructible<T>(),
374
333
                "Symbol types must be trivially destructible");
375
333
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
333
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
333
                "SymbolUnion not aligned enough");
378
333
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
333
         "Not a Symbol");
380
333
381
333
  Symbol Sym = *S;
382
333
383
333
  new (S) T(std::forward<ArgT>(Arg)...);
384
333
385
333
  S->VersionId = Sym.VersionId;
386
333
  S->Visibility = Sym.Visibility;
387
333
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
333
  S->ExportDynamic = Sym.ExportDynamic;
389
333
  S->CanInline = Sym.CanInline;
390
333
  S->Traced = Sym.Traced;
391
333
  S->ScriptDefined = Sym.ScriptDefined;
392
333
393
333
  // Symbols representing thread-local variables must be referenced by
394
333
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
333
  // non-TLS relocations, so there's a clear distinction between TLS
396
333
  // and non-TLS symbols. It is an error if the same symbol is defined
397
333
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
333
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
333
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
333
401
333
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch121
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
333
405
333
  // Print out a log message if --trace-symbol was specified.
406
333
  // This is for debugging.
407
333
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
333
}
LinkerScript.cpp:void lld::elf::replaceSymbol<lld::elf::Defined, std::nullptr_t, llvm::StringRef&, llvm::ELF::$_1, unsigned char&, llvm::ELF::$_2, unsigned long long&, int, lld::elf::SectionBase*&>(lld::elf::Symbol*, std::nullptr_t&&, llvm::StringRef&&&, llvm::ELF::$_1&&, unsigned char&&&, llvm::ELF::$_2&&, unsigned long long&&&, int&&, lld::elf::SectionBase*&&&)
Line
Count
Source
370
334
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
334
  using llvm::ELF::STT_TLS;
372
334
373
334
  static_assert(std::is_trivially_destructible<T>(),
374
334
                "Symbol types must be trivially destructible");
375
334
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
334
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
334
                "SymbolUnion not aligned enough");
378
334
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
334
         "Not a Symbol");
380
334
381
334
  Symbol Sym = *S;
382
334
383
334
  new (S) T(std::forward<ArgT>(Arg)...);
384
334
385
334
  S->VersionId = Sym.VersionId;
386
334
  S->Visibility = Sym.Visibility;
387
334
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
334
  S->ExportDynamic = Sym.ExportDynamic;
389
334
  S->CanInline = Sym.CanInline;
390
334
  S->Traced = Sym.Traced;
391
334
  S->ScriptDefined = Sym.ScriptDefined;
392
334
393
334
  // Symbols representing thread-local variables must be referenced by
394
334
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
334
  // non-TLS relocations, so there's a clear distinction between TLS
396
334
  // and non-TLS symbols. It is an error if the same symbol is defined
397
334
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
334
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
334
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
334
401
334
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch333
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
334
405
334
  // Print out a log message if --trace-symbol was specified.
406
334
  // This is for debugging.
407
334
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
334
}
void lld::elf::replaceSymbol<lld::elf::Defined, lld::elf::InputFile*&, llvm::StringRef, unsigned char&, unsigned char&, unsigned char&, unsigned long long&, unsigned long long&, lld::elf::SectionBase*&>(lld::elf::Symbol*, lld::elf::InputFile*&&&, llvm::StringRef&&, unsigned char&&&, unsigned char&&&, unsigned char&&&, unsigned long long&&&, unsigned long long&&&, lld::elf::SectionBase*&&&)
Line
Count
Source
370
110
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
110
  using llvm::ELF::STT_TLS;
372
110
373
110
  static_assert(std::is_trivially_destructible<T>(),
374
110
                "Symbol types must be trivially destructible");
375
110
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
110
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
110
                "SymbolUnion not aligned enough");
378
110
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
110
         "Not a Symbol");
380
110
381
110
  Symbol Sym = *S;
382
110
383
110
  new (S) T(std::forward<ArgT>(Arg)...);
384
110
385
110
  S->VersionId = Sym.VersionId;
386
110
  S->Visibility = Sym.Visibility;
387
110
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
110
  S->ExportDynamic = Sym.ExportDynamic;
389
110
  S->CanInline = Sym.CanInline;
390
110
  S->Traced = Sym.Traced;
391
110
  S->ScriptDefined = Sym.ScriptDefined;
392
110
393
110
  // Symbols representing thread-local variables must be referenced by
394
110
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
110
  // non-TLS relocations, so there's a clear distinction between TLS
396
110
  // and non-TLS symbols. It is an error if the same symbol is defined
397
110
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
110
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
110
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
110
401
110
  if (Sym.SymbolKind != Symbol::PlaceholderKind && TlsMismatch && 
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
110
405
110
  // Print out a log message if --trace-symbol was specified.
406
110
  // This is for debugging.
407
110
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
110
}
void lld::elf::replaceSymbol<lld::elf::Defined, lld::elf::InputFile*, llvm::StringRef&, unsigned char&, unsigned char&, unsigned char&, int, unsigned long long&, lld::elf::BssSection*&>(lld::elf::Symbol*, lld::elf::InputFile*&&, llvm::StringRef&&&, unsigned char&&&, unsigned char&&&, unsigned char&&&, int&&, unsigned long long&&&, lld::elf::BssSection*&&&)
Line
Count
Source
370
110
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
110
  using llvm::ELF::STT_TLS;
372
110
373
110
  static_assert(std::is_trivially_destructible<T>(),
374
110
                "Symbol types must be trivially destructible");
375
110
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
110
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
110
                "SymbolUnion not aligned enough");
378
110
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
110
         "Not a Symbol");
380
110
381
110
  Symbol Sym = *S;
382
110
383
110
  new (S) T(std::forward<ArgT>(Arg)...);
384
110
385
110
  S->VersionId = Sym.VersionId;
386
110
  S->Visibility = Sym.Visibility;
387
110
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
110
  S->ExportDynamic = Sym.ExportDynamic;
389
110
  S->CanInline = Sym.CanInline;
390
110
  S->Traced = Sym.Traced;
391
110
  S->ScriptDefined = Sym.ScriptDefined;
392
110
393
110
  // Symbols representing thread-local variables must be referenced by
394
110
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
110
  // non-TLS relocations, so there's a clear distinction between TLS
396
110
  // and non-TLS symbols. It is an error if the same symbol is defined
397
110
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
110
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
110
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
110
401
110
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch11
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
110
405
110
  // Print out a log message if --trace-symbol was specified.
406
110
  // This is for debugging.
407
110
  if (S->Traced)
408
5
    printTraceSymbol(S);
409
110
}
void lld::elf::replaceSymbol<lld::elf::Defined, lld::elf::InputFile*&, llvm::StringRef&, unsigned char&, unsigned char&, unsigned char&, unsigned long long&, unsigned long long&, lld::elf::SectionBase*&>(lld::elf::Symbol*, lld::elf::InputFile*&&&, llvm::StringRef&&&, unsigned char&&&, unsigned char&&&, unsigned char&&&, unsigned long long&&&, unsigned long long&&&, lld::elf::SectionBase*&&&)
Line
Count
Source
370
15.7k
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
15.7k
  using llvm::ELF::STT_TLS;
372
15.7k
373
15.7k
  static_assert(std::is_trivially_destructible<T>(),
374
15.7k
                "Symbol types must be trivially destructible");
375
15.7k
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
15.7k
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
15.7k
                "SymbolUnion not aligned enough");
378
15.7k
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
15.7k
         "Not a Symbol");
380
15.7k
381
15.7k
  Symbol Sym = *S;
382
15.7k
383
15.7k
  new (S) T(std::forward<ArgT>(Arg)...);
384
15.7k
385
15.7k
  S->VersionId = Sym.VersionId;
386
15.7k
  S->Visibility = Sym.Visibility;
387
15.7k
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
15.7k
  S->ExportDynamic = Sym.ExportDynamic;
389
15.7k
  S->CanInline = Sym.CanInline;
390
15.7k
  S->Traced = Sym.Traced;
391
15.7k
  S->ScriptDefined = Sym.ScriptDefined;
392
15.7k
393
15.7k
  // Symbols representing thread-local variables must be referenced by
394
15.7k
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
15.7k
  // non-TLS relocations, so there's a clear distinction between TLS
396
15.7k
  // and non-TLS symbols. It is an error if the same symbol is defined
397
15.7k
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
15.7k
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS13
) ||
399
15.7k
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS15.7k
);
400
15.7k
401
15.7k
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch745
&&
!Sym.isLazy()2
)
402
1
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
1
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
15.7k
405
15.7k
  // Print out a log message if --trace-symbol was specified.
406
15.7k
  // This is for debugging.
407
15.7k
  if (S->Traced)
408
20
    printTraceSymbol(S);
409
15.7k
}
void lld::elf::replaceSymbol<lld::elf::Defined, lld::elf::BitcodeFile*, llvm::StringRef&, unsigned char&, unsigned char&, unsigned char&, int, int, std::nullptr_t>(lld::elf::Symbol*, lld::elf::BitcodeFile*&&, llvm::StringRef&&&, unsigned char&&&, unsigned char&&&, unsigned char&&&, int&&, int&&, std::nullptr_t&&)
Line
Count
Source
370
270
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
270
  using llvm::ELF::STT_TLS;
372
270
373
270
  static_assert(std::is_trivially_destructible<T>(),
374
270
                "Symbol types must be trivially destructible");
375
270
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
270
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
270
                "SymbolUnion not aligned enough");
378
270
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
270
         "Not a Symbol");
380
270
381
270
  Symbol Sym = *S;
382
270
383
270
  new (S) T(std::forward<ArgT>(Arg)...);
384
270
385
270
  S->VersionId = Sym.VersionId;
386
270
  S->Visibility = Sym.Visibility;
387
270
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
270
  S->ExportDynamic = Sym.ExportDynamic;
389
270
  S->CanInline = Sym.CanInline;
390
270
  S->Traced = Sym.Traced;
391
270
  S->ScriptDefined = Sym.ScriptDefined;
392
270
393
270
  // Symbols representing thread-local variables must be referenced by
394
270
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
270
  // non-TLS relocations, so there's a clear distinction between TLS
396
270
  // and non-TLS symbols. It is an error if the same symbol is defined
397
270
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
270
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
270
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
270
401
270
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch71
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
270
405
270
  // Print out a log message if --trace-symbol was specified.
406
270
  // This is for debugging.
407
270
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
270
}
void lld::elf::replaceSymbol<lld::elf::Undefined, lld::elf::InputFile*&, llvm::StringRef&, unsigned char&, unsigned char&, unsigned char&>(lld::elf::Symbol*, lld::elf::InputFile*&&&, llvm::StringRef&&&, unsigned char&&&, unsigned char&&&, unsigned char&&&)
Line
Count
Source
370
1.42k
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
1.42k
  using llvm::ELF::STT_TLS;
372
1.42k
373
1.42k
  static_assert(std::is_trivially_destructible<T>(),
374
1.42k
                "Symbol types must be trivially destructible");
375
1.42k
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
1.42k
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
1.42k
                "SymbolUnion not aligned enough");
378
1.42k
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
1.42k
         "Not a Symbol");
380
1.42k
381
1.42k
  Symbol Sym = *S;
382
1.42k
383
1.42k
  new (S) T(std::forward<ArgT>(Arg)...);
384
1.42k
385
1.42k
  S->VersionId = Sym.VersionId;
386
1.42k
  S->Visibility = Sym.Visibility;
387
1.42k
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
1.42k
  S->ExportDynamic = Sym.ExportDynamic;
389
1.42k
  S->CanInline = Sym.CanInline;
390
1.42k
  S->Traced = Sym.Traced;
391
1.42k
  S->ScriptDefined = Sym.ScriptDefined;
392
1.42k
393
1.42k
  // Symbols representing thread-local variables must be referenced by
394
1.42k
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
1.42k
  // non-TLS relocations, so there's a clear distinction between TLS
396
1.42k
  // and non-TLS symbols. It is an error if the same symbol is defined
397
1.42k
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
1.42k
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
1.42k
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
1.42k
401
1.42k
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch2
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
1.42k
405
1.42k
  // Print out a log message if --trace-symbol was specified.
406
1.42k
  // This is for debugging.
407
1.42k
  if (S->Traced)
408
18
    printTraceSymbol(S);
409
1.42k
}
SymbolTable.cpp:void lld::elf::replaceSymbol<lld::elf::LazyArchive, lld::elf::ArchiveFile&, llvm::ELF::$_0, llvm::object::Archive::Symbol const&>(lld::elf::Symbol*, lld::elf::ArchiveFile&&&, llvm::ELF::$_0&&, llvm::object::Archive::Symbol const&&&)
Line
Count
Source
370
91
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
91
  using llvm::ELF::STT_TLS;
372
91
373
91
  static_assert(std::is_trivially_destructible<T>(),
374
91
                "Symbol types must be trivially destructible");
375
91
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
91
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
91
                "SymbolUnion not aligned enough");
378
91
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
91
         "Not a Symbol");
380
91
381
91
  Symbol Sym = *S;
382
91
383
91
  new (S) T(std::forward<ArgT>(Arg)...);
384
91
385
91
  S->VersionId = Sym.VersionId;
386
91
  S->Visibility = Sym.Visibility;
387
91
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
91
  S->ExportDynamic = Sym.ExportDynamic;
389
91
  S->CanInline = Sym.CanInline;
390
91
  S->Traced = Sym.Traced;
391
91
  S->ScriptDefined = Sym.ScriptDefined;
392
91
393
91
  // Symbols representing thread-local variables must be referenced by
394
91
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
91
  // non-TLS relocations, so there's a clear distinction between TLS
396
91
  // and non-TLS symbols. It is an error if the same symbol is defined
397
91
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
91
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
91
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
91
401
91
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch0
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
91
405
91
  // Print out a log message if --trace-symbol was specified.
406
91
  // This is for debugging.
407
91
  if (S->Traced)
408
2
    printTraceSymbol(S);
409
91
}
void lld::elf::replaceSymbol<lld::elf::LazyArchive, lld::elf::ArchiveFile&, unsigned char&, llvm::object::Archive::Symbol const&>(lld::elf::Symbol*, lld::elf::ArchiveFile&&&, unsigned char&&&, llvm::object::Archive::Symbol const&&&)
Line
Count
Source
370
14
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
14
  using llvm::ELF::STT_TLS;
372
14
373
14
  static_assert(std::is_trivially_destructible<T>(),
374
14
                "Symbol types must be trivially destructible");
375
14
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
14
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
14
                "SymbolUnion not aligned enough");
378
14
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
14
         "Not a Symbol");
380
14
381
14
  Symbol Sym = *S;
382
14
383
14
  new (S) T(std::forward<ArgT>(Arg)...);
384
14
385
14
  S->VersionId = Sym.VersionId;
386
14
  S->Visibility = Sym.Visibility;
387
14
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
14
  S->ExportDynamic = Sym.ExportDynamic;
389
14
  S->CanInline = Sym.CanInline;
390
14
  S->Traced = Sym.Traced;
391
14
  S->ScriptDefined = Sym.ScriptDefined;
392
14
393
14
  // Symbols representing thread-local variables must be referenced by
394
14
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
14
  // non-TLS relocations, so there's a clear distinction between TLS
396
14
  // and non-TLS symbols. It is an error if the same symbol is defined
397
14
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
14
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS2
) ||
399
14
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS12
);
400
14
401
14
  if (Sym.SymbolKind != Symbol::PlaceholderKind && TlsMismatch && 
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
14
405
14
  // Print out a log message if --trace-symbol was specified.
406
14
  // This is for debugging.
407
14
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
14
}
SymbolTable.cpp:void lld::elf::replaceSymbol<lld::elf::LazyObject, lld::elf::LazyObjFile&, llvm::ELF::$_0, llvm::StringRef&>(lld::elf::Symbol*, lld::elf::LazyObjFile&&&, llvm::ELF::$_0&&, llvm::StringRef&&&)
Line
Count
Source
370
20
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
20
  using llvm::ELF::STT_TLS;
372
20
373
20
  static_assert(std::is_trivially_destructible<T>(),
374
20
                "Symbol types must be trivially destructible");
375
20
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
20
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
20
                "SymbolUnion not aligned enough");
378
20
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
20
         "Not a Symbol");
380
20
381
20
  Symbol Sym = *S;
382
20
383
20
  new (S) T(std::forward<ArgT>(Arg)...);
384
20
385
20
  S->VersionId = Sym.VersionId;
386
20
  S->Visibility = Sym.Visibility;
387
20
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
20
  S->ExportDynamic = Sym.ExportDynamic;
389
20
  S->CanInline = Sym.CanInline;
390
20
  S->Traced = Sym.Traced;
391
20
  S->ScriptDefined = Sym.ScriptDefined;
392
20
393
20
  // Symbols representing thread-local variables must be referenced by
394
20
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
20
  // non-TLS relocations, so there's a clear distinction between TLS
396
20
  // and non-TLS symbols. It is an error if the same symbol is defined
397
20
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
20
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
20
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
20
401
20
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch0
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
20
405
20
  // Print out a log message if --trace-symbol was specified.
406
20
  // This is for debugging.
407
20
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
20
}
void lld::elf::replaceSymbol<lld::elf::LazyObject, lld::elf::LazyObjFile&, unsigned char&, llvm::StringRef&>(lld::elf::Symbol*, lld::elf::LazyObjFile&&&, unsigned char&&&, llvm::StringRef&&&)
Line
Count
Source
370
1
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
1
  using llvm::ELF::STT_TLS;
372
1
373
1
  static_assert(std::is_trivially_destructible<T>(),
374
1
                "Symbol types must be trivially destructible");
375
1
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
1
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
1
                "SymbolUnion not aligned enough");
378
1
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
1
         "Not a Symbol");
380
1
381
1
  Symbol Sym = *S;
382
1
383
1
  new (S) T(std::forward<ArgT>(Arg)...);
384
1
385
1
  S->VersionId = Sym.VersionId;
386
1
  S->Visibility = Sym.Visibility;
387
1
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
1
  S->ExportDynamic = Sym.ExportDynamic;
389
1
  S->CanInline = Sym.CanInline;
390
1
  S->Traced = Sym.Traced;
391
1
  S->ScriptDefined = Sym.ScriptDefined;
392
1
393
1
  // Symbols representing thread-local variables must be referenced by
394
1
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
1
  // non-TLS relocations, so there's a clear distinction between TLS
396
1
  // and non-TLS symbols. It is an error if the same symbol is defined
397
1
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
1
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS0
) ||
399
1
                     (Sym.Type != STT_TLS && S->Type == STT_TLS);
400
1
401
1
  if (Sym.SymbolKind != Symbol::PlaceholderKind && TlsMismatch && 
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
1
405
1
  // Print out a log message if --trace-symbol was specified.
406
1
  // This is for debugging.
407
1
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
1
}
void lld::elf::replaceSymbol<lld::elf::SharedSymbol, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >&, llvm::StringRef&, unsigned char, unsigned char const&, unsigned char, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> const&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> const&, unsigned int&, unsigned int&>(lld::elf::Symbol*, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >&&&, llvm::StringRef&&&, unsigned char&&, unsigned char const&&&, unsigned char&&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> const&&&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> const&&&, unsigned int&&&, unsigned int&&&)
Line
Count
Source
370
114
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
114
  using llvm::ELF::STT_TLS;
372
114
373
114
  static_assert(std::is_trivially_destructible<T>(),
374
114
                "Symbol types must be trivially destructible");
375
114
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
114
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
114
                "SymbolUnion not aligned enough");
378
114
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
114
         "Not a Symbol");
380
114
381
114
  Symbol Sym = *S;
382
114
383
114
  new (S) T(std::forward<ArgT>(Arg)...);
384
114
385
114
  S->VersionId = Sym.VersionId;
386
114
  S->Visibility = Sym.Visibility;
387
114
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
114
  S->ExportDynamic = Sym.ExportDynamic;
389
114
  S->CanInline = Sym.CanInline;
390
114
  S->Traced = Sym.Traced;
391
114
  S->ScriptDefined = Sym.ScriptDefined;
392
114
393
114
  // Symbols representing thread-local variables must be referenced by
394
114
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
114
  // non-TLS relocations, so there's a clear distinction between TLS
396
114
  // and non-TLS symbols. It is an error if the same symbol is defined
397
114
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
114
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS7
) ||
399
114
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS107
);
400
114
401
114
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch62
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
114
405
114
  // Print out a log message if --trace-symbol was specified.
406
114
  // This is for debugging.
407
114
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
114
}
void lld::elf::replaceSymbol<lld::elf::SharedSymbol, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >&, llvm::StringRef&, unsigned char, unsigned char const&, unsigned char, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> const&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> const&, unsigned int&, unsigned int&>(lld::elf::Symbol*, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >&&&, llvm::StringRef&&&, unsigned char&&, unsigned char const&&&, unsigned char&&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> const&&&, llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> const&&&, unsigned int&&&, unsigned int&&&)
Line
Count
Source
370
100
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
100
  using llvm::ELF::STT_TLS;
372
100
373
100
  static_assert(std::is_trivially_destructible<T>(),
374
100
                "Symbol types must be trivially destructible");
375
100
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
100
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
100
                "SymbolUnion not aligned enough");
378
100
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
100
         "Not a Symbol");
380
100
381
100
  Symbol Sym = *S;
382
100
383
100
  new (S) T(std::forward<ArgT>(Arg)...);
384
100
385
100
  S->VersionId = Sym.VersionId;
386
100
  S->Visibility = Sym.Visibility;
387
100
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
100
  S->ExportDynamic = Sym.ExportDynamic;
389
100
  S->CanInline = Sym.CanInline;
390
100
  S->Traced = Sym.Traced;
391
100
  S->ScriptDefined = Sym.ScriptDefined;
392
100
393
100
  // Symbols representing thread-local variables must be referenced by
394
100
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
100
  // non-TLS relocations, so there's a clear distinction between TLS
396
100
  // and non-TLS symbols. It is an error if the same symbol is defined
397
100
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
100
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS2
) ||
399
100
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS98
);
400
100
401
100
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch28
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
100
405
100
  // Print out a log message if --trace-symbol was specified.
406
100
  // This is for debugging.
407
100
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
100
}
void lld::elf::replaceSymbol<lld::elf::SharedSymbol, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >&, llvm::StringRef&, unsigned char, unsigned char const&, unsigned char, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> const&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> const&, unsigned int&, unsigned int&>(lld::elf::Symbol*, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >&&&, llvm::StringRef&&&, unsigned char&&, unsigned char const&&&, unsigned char&&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> const&&&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> const&&&, unsigned int&&&, unsigned int&&&)
Line
Count
Source
370
498
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
498
  using llvm::ELF::STT_TLS;
372
498
373
498
  static_assert(std::is_trivially_destructible<T>(),
374
498
                "Symbol types must be trivially destructible");
375
498
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
498
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
498
                "SymbolUnion not aligned enough");
378
498
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
498
         "Not a Symbol");
380
498
381
498
  Symbol Sym = *S;
382
498
383
498
  new (S) T(std::forward<ArgT>(Arg)...);
384
498
385
498
  S->VersionId = Sym.VersionId;
386
498
  S->Visibility = Sym.Visibility;
387
498
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
498
  S->ExportDynamic = Sym.ExportDynamic;
389
498
  S->CanInline = Sym.CanInline;
390
498
  S->Traced = Sym.Traced;
391
498
  S->ScriptDefined = Sym.ScriptDefined;
392
498
393
498
  // Symbols representing thread-local variables must be referenced by
394
498
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
498
  // non-TLS relocations, so there's a clear distinction between TLS
396
498
  // and non-TLS symbols. It is an error if the same symbol is defined
397
498
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
498
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS13
) ||
399
498
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS485
);
400
498
401
498
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch247
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
498
405
498
  // Print out a log message if --trace-symbol was specified.
406
498
  // This is for debugging.
407
498
  if (S->Traced)
408
9
    printTraceSymbol(S);
409
498
}
void lld::elf::replaceSymbol<lld::elf::SharedSymbol, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >&, llvm::StringRef&, unsigned char, unsigned char const&, unsigned char, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> const&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> const&, unsigned int&, unsigned int&>(lld::elf::Symbol*, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >&&&, llvm::StringRef&&&, unsigned char&&, unsigned char const&&&, unsigned char&&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> const&&&, llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> const&&&, unsigned int&&&, unsigned int&&&)
Line
Count
Source
370
109
void replaceSymbol(Symbol *S, ArgT &&... Arg) {
371
109
  using llvm::ELF::STT_TLS;
372
109
373
109
  static_assert(std::is_trivially_destructible<T>(),
374
109
                "Symbol types must be trivially destructible");
375
109
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
376
109
  static_assert(alignof(T) <= alignof(SymbolUnion),
377
109
                "SymbolUnion not aligned enough");
378
109
  assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
379
109
         "Not a Symbol");
380
109
381
109
  Symbol Sym = *S;
382
109
383
109
  new (S) T(std::forward<ArgT>(Arg)...);
384
109
385
109
  S->VersionId = Sym.VersionId;
386
109
  S->Visibility = Sym.Visibility;
387
109
  S->IsUsedInRegularObj = Sym.IsUsedInRegularObj;
388
109
  S->ExportDynamic = Sym.ExportDynamic;
389
109
  S->CanInline = Sym.CanInline;
390
109
  S->Traced = Sym.Traced;
391
109
  S->ScriptDefined = Sym.ScriptDefined;
392
109
393
109
  // Symbols representing thread-local variables must be referenced by
394
109
  // TLS-aware relocations, and non-TLS symbols must be reference by
395
109
  // non-TLS relocations, so there's a clear distinction between TLS
396
109
  // and non-TLS symbols. It is an error if the same symbol is defined
397
109
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
398
109
  bool TlsMismatch = (Sym.Type == STT_TLS && 
S->Type != STT_TLS7
) ||
399
109
                     (Sym.Type != STT_TLS && 
S->Type == STT_TLS102
);
400
109
401
109
  if (Sym.SymbolKind != Symbol::PlaceholderKind && 
TlsMismatch21
&&
!Sym.isLazy()0
)
402
0
    error("TLS attribute mismatch: " + toString(Sym) + "\n>>> defined in " +
403
0
          toString(Sym.File) + "\n>>> defined in " + toString(S->File));
404
109
405
109
  // Print out a log message if --trace-symbol was specified.
406
109
  // This is for debugging.
407
109
  if (S->Traced)
408
0
    printTraceSymbol(S);
409
109
}
410
411
void warnUnorderableSymbol(const Symbol *Sym);
412
} // namespace elf
413
} // namespace lld
414
415
#endif