Coverage Report

Created: 2019-05-19 14:56

/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
// 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
// This file defines various types of Symbols.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLD_ELF_SYMBOLS_H
14
#define LLD_ELF_SYMBOLS_H
15
16
#include "InputFiles.h"
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
// This is a StringRef-like container that doesn't run strlen().
35
//
36
// ELF string tables contain a lot of null-terminated strings. Most of them
37
// are not necessary for the linker because they are names of local symbols,
38
// and the linker doesn't use local symbol names for name resolution. So, we
39
// use this class to represents strings read from string tables.
40
struct StringRefZ {
41
138k
  StringRefZ(const char *S) : Data(S), Size(-1) {}
42
20.1k
  StringRefZ(StringRef S) : Data(S.data()), Size(S.size()) {}
43
44
  const char *Data;
45
  const uint32_t Size;
46
};
47
48
// The base class for real symbol classes.
49
class Symbol {
50
public:
51
  enum Kind {
52
    PlaceholderKind,
53
    DefinedKind,
54
    CommonKind,
55
    SharedKind,
56
    UndefinedKind,
57
    LazyArchiveKind,
58
    LazyObjectKind,
59
  };
60
61
159k
  Kind kind() const { return static_cast<Kind>(SymbolKind); }
62
63
  // The file from which this symbol was created.
64
  InputFile *File;
65
66
protected:
67
  const char *NameData;
68
  mutable uint32_t NameSize;
69
70
public:
71
  uint32_t DynsymIndex = 0;
72
  uint32_t GotIndex = -1;
73
  uint32_t PltIndex = -1;
74
75
  uint32_t GlobalDynIndex = -1;
76
77
  // This field is a index to the symbol's version definition.
78
  uint32_t VerdefIndex = -1;
79
80
  // Version definition index.
81
  uint16_t VersionId;
82
83
  // An index into the .branch_lt section on PPC64.
84
  uint16_t PPC64BranchltIndex = -1;
85
86
  // Symbol binding. This is not overwritten by replaceSymbol to track
87
  // changes during resolution. In particular:
88
  //  - An undefined weak is still weak when it resolves to a shared library.
89
  //  - An undefined weak will not fetch archive members, but we have to
90
  //    remember it is weak.
91
  uint8_t Binding;
92
93
  // The following fields have the same meaning as the ELF symbol attributes.
94
  uint8_t Type;    // symbol type
95
  uint8_t StOther; // st_other field value
96
97
  uint8_t SymbolKind;
98
99
  // Symbol visibility. This is the computed minimum visibility of all
100
  // observed non-DSO symbols.
101
  unsigned Visibility : 2;
102
103
  // True if the symbol was used for linking and thus need to be added to the
104
  // output file's symbol table. This is true for all symbols except for
105
  // unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that
106
  // are unreferenced except by other bitcode objects.
107
  unsigned IsUsedInRegularObj : 1;
108
109
  // If this flag is true and the symbol has protected or default visibility, it
110
  // will appear in .dynsym. This flag is set by interposable DSO symbols in
111
  // executables, by most symbols in DSOs and executables built with
112
  // --export-dynamic, and by dynamic lists.
113
  unsigned ExportDynamic : 1;
114
115
  // False if LTO shouldn't inline whatever this symbol points to. If a symbol
116
  // is overwritten after LTO, LTO shouldn't inline the symbol because it
117
  // doesn't know the final contents of the symbol.
118
  unsigned CanInline : 1;
119
120
  // True if this symbol is specified by --trace-symbol option.
121
  unsigned Traced : 1;
122
123
  bool includeInDynsym() const;
124
  uint8_t computeBinding() const;
125
10.0k
  bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
126
127
30.2k
  bool isUndefined() const { return SymbolKind == UndefinedKind; }
128
17.6k
  bool isCommon() const { return SymbolKind == CommonKind; }
129
18.8M
  bool isDefined() const { return SymbolKind == DefinedKind; }
130
21.2k
  bool isShared() const { return SymbolKind == SharedKind; }
131
19.6k
  bool isPlaceholder() const { return SymbolKind == PlaceholderKind; }
132
133
442k
  bool isLocal() const { return Binding == llvm::ELF::STB_LOCAL; }
134
135
6.91k
  bool isLazy() const {
136
6.91k
    return SymbolKind == LazyArchiveKind || 
SymbolKind == LazyObjectKind6.76k
;
137
6.91k
  }
138
139
  // True if this is an undefined weak symbol. This only works once
140
  // all input files have been added.
141
8.72k
  bool isUndefWeak() const {
142
8.72k
    // See comment on lazy symbols for details.
143
8.72k
    return isWeak() && 
(320
isUndefined()320
||
isLazy()152
);
144
8.72k
  }
145
146
149k
  StringRef getName() const {
147
149k
    if (NameSize == (uint32_t)-1)
148
68.9k
      NameSize = strlen(NameData);
149
149k
    return {NameData, NameSize};
150
149k
  }
151
152
13
  void setName(StringRef S) {
153
13
    NameData = S.data();
154
13
    NameSize = S.size();
155
13
  }
156
157
  void parseSymbolVersion();
158
159
786
  bool isInGot() const { return GotIndex != -1U; }
160
12.3k
  bool isInPlt() const { return PltIndex != -1U; }
161
9
  bool isInPPC64Branchlt() const { return PPC64BranchltIndex != 0xffff; }
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 getPPC64LongBranchTableVA() const;
171
  uint64_t getPPC64LongBranchOffset() const;
172
  uint64_t getSize() const;
173
  OutputSection *getOutputSection() const;
174
175
private:
176
158k
  static bool isExportDynamic(Kind K, uint8_t Visibility) {
177
158k
    if (K == SharedKind)
178
897
      return Visibility == llvm::ELF::STV_DEFAULT;
179
157k
    return Config->Shared || 
Config->ExportDynamic152k
;
180
157k
  }
181
182
protected:
183
  Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
184
         uint8_t StOther, uint8_t Type)
185
      : File(File), NameData(Name.Data), NameSize(Name.Size), Binding(Binding),
186
        Type(Type), StOther(StOther), SymbolKind(K), Visibility(StOther & 3),
187
        IsUsedInRegularObj(!File || File->kind() == InputFile::ObjKind),
188
        ExportDynamic(isExportDynamic(K, Visibility)), CanInline(false),
189
        Traced(false), NeedsPltAddr(false), IsInIplt(false), GotInIgot(false),
190
        IsPreemptible(false), Used(!Config->GcSections), NeedsTocRestore(false),
191
158k
        ScriptDefined(false) {}
192
193
public:
194
  // True the symbol should point to its PLT entry.
195
  // For SharedSymbol only.
196
  unsigned NeedsPltAddr : 1;
197
198
  // True if this symbol is in the Iplt sub-section of the Plt and the Igot
199
  // sub-section of the .got.plt or .got.
200
  unsigned IsInIplt : 1;
201
202
  // True if this symbol needs a GOT entry and its GOT entry is actually in
203
  // Igot. This will be true only for certain non-preemptible ifuncs.
204
  unsigned GotInIgot : 1;
205
206
  // True if this symbol is preemptible at load time.
207
  unsigned IsPreemptible : 1;
208
209
  // True if an undefined or shared symbol is used from a live section.
210
  unsigned Used : 1;
211
212
  // True if a call to this symbol needs to be followed by a restore of the
213
  // PPC64 toc pointer.
214
  unsigned NeedsTocRestore : 1;
215
216
  // True if this symbol is defined by a linker script.
217
  unsigned ScriptDefined : 1;
218
219
169k
  bool isSection() const { return Type == llvm::ELF::STT_SECTION; }
220
137k
  bool isTls() const { return Type == llvm::ELF::STT_TLS; }
221
222
  bool isFunc() const { return Type == llvm::ELF::STT_FUNC; }
222
54.7k
  bool isGnuIFunc() const { return Type == llvm::ELF::STT_GNU_IFUNC; }
223
119
  bool isObject() const { return Type == llvm::ELF::STT_OBJECT; }
224
0
  bool isFile() const { return Type == llvm::ELF::STT_FILE; }
225
};
226
227
// Represents a symbol that is defined in the current output file.
228
class Defined : public Symbol {
229
public:
230
  Defined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
231
          uint8_t Type, uint64_t Value, uint64_t Size, SectionBase *Section)
232
      : Symbol(DefinedKind, File, Name, Binding, StOther, Type), Value(Value),
233
151k
        Size(Size), Section(Section) {}
234
235
18.8M
  static bool classof(const Symbol *S) { return S->isDefined(); }
236
237
  uint64_t Value;
238
  uint64_t Size;
239
  SectionBase *Section;
240
};
241
242
// Represents a common symbol.
243
//
244
// On Unix, it is traditionally allowed to write variable definitions
245
// without initialization expressions (such as "int foo;") to header
246
// files. Such definition is called "tentative definition".
247
//
248
// Using tentative definition is usually considered a bad practice
249
// because you should write only declarations (such as "extern int
250
// foo;") to header files. Nevertheless, the linker and the compiler
251
// have to do something to support bad code by allowing duplicate
252
// definitions for this particular case.
253
//
254
// Common symbols represent variable definitions without initializations.
255
// The compiler creates common symbols when it sees varaible definitions
256
// without initialization (you can suppress this behavior and let the
257
// compiler create a regular defined symbol by -fno-common).
258
//
259
// The linker allows common symbols to be replaced by regular defined
260
// symbols. If there are remaining common symbols after name resolution is
261
// complete, they are converted to regular defined symbols in a .bss
262
// section. (Therefore, the later passes don't see any CommonSymbols.)
263
class CommonSymbol : public Symbol {
264
public:
265
  CommonSymbol(InputFile *File, StringRefZ Name, uint8_t Binding,
266
               uint8_t StOther, uint8_t Type, uint64_t Alignment, uint64_t Size)
267
      : Symbol(CommonKind, File, Name, Binding, StOther, Type),
268
130
        Alignment(Alignment), Size(Size) {}
269
270
16.5k
  static bool classof(const Symbol *S) { return S->isCommon(); }
271
272
  uint32_t Alignment;
273
  uint64_t Size;
274
};
275
276
class Undefined : public Symbol {
277
public:
278
  Undefined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
279
            uint8_t Type)
280
5.37k
      : Symbol(UndefinedKind, File, Name, Binding, StOther, Type) {}
281
282
0
  static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; }
283
};
284
285
class SharedSymbol : public Symbol {
286
public:
287
33.1k
  static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
288
289
  SharedSymbol(InputFile &File, StringRef Name, uint8_t Binding,
290
               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
291
               uint32_t Alignment, uint32_t VerdefIndex)
292
      : Symbol(SharedKind, &File, Name, Binding, StOther, Type),
293
897
        Alignment(Alignment), Value(Value), Size(Size) {
294
897
    this->VerdefIndex = VerdefIndex;
295
897
    // GNU ifunc is a mechanism to allow user-supplied functions to
296
897
    // resolve PLT slot values at load-time. This is contrary to the
297
897
    // regular symbol resolution scheme in which symbols are resolved just
298
897
    // by name. Using this hook, you can program how symbols are solved
299
897
    // for you program. For example, you can make "memcpy" to be resolved
300
897
    // to a SSE-enabled version of memcpy only when a machine running the
301
897
    // program supports the SSE instruction set.
302
897
    //
303
897
    // Naturally, such symbols should always be called through their PLT
304
897
    // slots. What GNU ifunc symbols point to are resolver functions, and
305
897
    // calling them directly doesn't make sense (unless you are writing a
306
897
    // loader).
307
897
    //
308
897
    // For DSO symbols, we always call them through PLT slots anyway.
309
897
    // So there's no difference between GNU ifunc and regular function
310
897
    // symbols if they are in DSOs. So we can handle GNU_IFUNC as FUNC.
311
897
    if (this->Type == llvm::ELF::STT_GNU_IFUNC)
312
3
      this->Type = llvm::ELF::STT_FUNC;
313
897
  }
314
315
1.22k
  SharedFile &getFile() const { return *cast<SharedFile>(File); }
316
317
  uint32_t Alignment;
318
319
  uint64_t Value; // st_value
320
  uint64_t Size;  // st_size
321
};
322
323
// LazyArchive and LazyObject represent a symbols that is not yet in the link,
324
// but we know where to find it if needed. If the resolver finds both Undefined
325
// and Lazy for the same name, it will ask the Lazy to load a file.
326
//
327
// A special complication is the handling of weak undefined symbols. They should
328
// not load a file, but we have to remember we have seen both the weak undefined
329
// and the lazy. We represent that with a lazy symbol with a weak binding. This
330
// means that code looking for undefined symbols normally also has to take lazy
331
// symbols into consideration.
332
333
// This class represents a symbol defined in an archive file. It is
334
// created from an archive file header, and it knows how to load an
335
// object file from an archive to replace itself with a defined
336
// symbol.
337
class LazyArchive : public Symbol {
338
public:
339
  LazyArchive(InputFile &File, const llvm::object::Archive::Symbol S)
340
      : Symbol(LazyArchiveKind, &File, S.getName(), llvm::ELF::STB_GLOBAL,
341
               llvm::ELF::STV_DEFAULT, llvm::ELF::STT_NOTYPE),
342
193
        Sym(S) {}
343
344
43
  static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }
345
346
  InputFile *fetch() const;
347
  MemoryBufferRef getMemberBuffer();
348
349
private:
350
  const llvm::object::Archive::Symbol Sym;
351
};
352
353
// LazyObject symbols represents symbols in object files between
354
// --start-lib and --end-lib options.
355
class LazyObject : public Symbol {
356
public:
357
  LazyObject(InputFile &File, StringRef Name)
358
      : Symbol(LazyObjectKind, &File, Name, llvm::ELF::STB_GLOBAL,
359
35
               llvm::ELF::STV_DEFAULT, llvm::ELF::STT_NOTYPE) {}
360
361
4
  static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }
362
363
  InputFile *fetch() const;
364
};
365
366
// Some linker-generated symbols need to be created as
367
// Defined symbols.
368
struct ElfSym {
369
  // __bss_start
370
  static Defined *Bss;
371
372
  // etext and _etext
373
  static Defined *Etext1;
374
  static Defined *Etext2;
375
376
  // edata and _edata
377
  static Defined *Edata1;
378
  static Defined *Edata2;
379
380
  // end and _end
381
  static Defined *End1;
382
  static Defined *End2;
383
384
  // The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to
385
  // be at some offset from the base of the .got section, usually 0 or
386
  // the end of the .got.
387
  static Defined *GlobalOffsetTable;
388
389
  // _gp, _gp_disp and __gnu_local_gp symbols. Only for MIPS.
390
  static Defined *MipsGp;
391
  static Defined *MipsGpDisp;
392
  static Defined *MipsLocalGp;
393
394
  // __rel{,a}_iplt_{start,end} symbols.
395
  static Defined *RelaIpltStart;
396
  static Defined *RelaIpltEnd;
397
};
398
399
// A buffer class that is large enough to hold any Symbol-derived
400
// object. We allocate memory using this class and instantiate a symbol
401
// using the placement new.
402
union SymbolUnion {
403
  alignas(Defined) char A[sizeof(Defined)];
404
  alignas(CommonSymbol) char B[sizeof(CommonSymbol)];
405
  alignas(Undefined) char C[sizeof(Undefined)];
406
  alignas(SharedSymbol) char D[sizeof(SharedSymbol)];
407
  alignas(LazyArchive) char E[sizeof(LazyArchive)];
408
  alignas(LazyObject) char F[sizeof(LazyObject)];
409
};
410
411
template <typename T> struct AssertSymbol {
412
  static_assert(std::is_trivially_destructible<T>(),
413
                "Symbol types must be trivially destructible");
414
  static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
415
  static_assert(alignof(T) <= alignof(SymbolUnion),
416
                "SymbolUnion not aligned enough");
417
};
418
419
0
static inline void assertSymbols() {
420
0
  AssertSymbol<Defined>();
421
0
  AssertSymbol<CommonSymbol>();
422
0
  AssertSymbol<Undefined>();
423
0
  AssertSymbol<SharedSymbol>();
424
0
  AssertSymbol<LazyArchive>();
425
0
  AssertSymbol<LazyObject>();
426
0
}
Unexecuted instantiation: AArch64ErrataFix.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: AArch64.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: AMDGPU.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: ARM.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: AVR.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Hexagon.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Mips.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: MSP430.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: PPC.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: PPC64.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: SPARCV9.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: X86.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: X86_64.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: CallGraphSort.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: DWARF.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Driver.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: ICF.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: InputFiles.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: InputSection.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: LTO.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: LinkerScript.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: MapFile.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: MarkLive.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Relocations.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: ScriptParser.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: SymbolTable.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Symbols.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: SyntheticSections.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Target.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Thunks.cpp:lld::elf::assertSymbols()
Unexecuted instantiation: Writer.cpp:lld::elf::assertSymbols()
427
428
void printTraceSymbol(Symbol *Sym);
429
430
20.3k
static size_t getSymbolSize(const Symbol &Sym) {
431
20.3k
  switch (Sym.kind()) {
432
20.3k
  case Symbol::CommonKind:
433
110
    return sizeof(CommonSymbol);
434
20.3k
  case Symbol::DefinedKind:
435
17.3k
    return sizeof(Defined);
436
20.3k
  case Symbol::LazyArchiveKind:
437
106
    return sizeof(LazyArchive);
438
20.3k
  case Symbol::LazyObjectKind:
439
21
    return sizeof(LazyObject);
440
20.3k
  case Symbol::SharedKind:
441
857
    return sizeof(SharedSymbol);
442
20.3k
  case Symbol::UndefinedKind:
443
1.84k
    return sizeof(Undefined);
444
20.3k
  case Symbol::PlaceholderKind:
445
0
    return sizeof(Symbol);
446
0
  }
447
0
  llvm_unreachable("unknown symbol kind");
448
0
}
Unexecuted instantiation: AArch64ErrataFix.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: AArch64.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: AMDGPU.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: ARM.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: AVR.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Hexagon.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Mips.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: MSP430.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: PPC.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: PPC64.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: SPARCV9.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: X86.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: X86_64.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: CallGraphSort.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: DWARF.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Driver.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Line
Count
Source
430
20.3k
static size_t getSymbolSize(const Symbol &Sym) {
431
20.3k
  switch (Sym.kind()) {
432
20.3k
  case Symbol::CommonKind:
433
110
    return sizeof(CommonSymbol);
434
20.3k
  case Symbol::DefinedKind:
435
17.3k
    return sizeof(Defined);
436
20.3k
  case Symbol::LazyArchiveKind:
437
106
    return sizeof(LazyArchive);
438
20.3k
  case Symbol::LazyObjectKind:
439
21
    return sizeof(LazyObject);
440
20.3k
  case Symbol::SharedKind:
441
857
    return sizeof(SharedSymbol);
442
20.3k
  case Symbol::UndefinedKind:
443
1.84k
    return sizeof(Undefined);
444
20.3k
  case Symbol::PlaceholderKind:
445
0
    return sizeof(Symbol);
446
0
  }
447
0
  llvm_unreachable("unknown symbol kind");
448
0
}
Unexecuted instantiation: ICF.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: InputFiles.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: InputSection.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: LTO.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: LinkerScript.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: MapFile.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: MarkLive.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Relocations.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: ScriptParser.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: SymbolTable.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Symbols.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: SyntheticSections.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Target.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Thunks.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
Unexecuted instantiation: Writer.cpp:lld::elf::getSymbolSize(lld::elf::Symbol const&)
449
450
20.3k
inline void replaceSymbol(Symbol *Sym, const Symbol &New) {
451
20.3k
  using llvm::ELF::STT_TLS;
452
20.3k
453
20.3k
  // Symbols representing thread-local variables must be referenced by
454
20.3k
  // TLS-aware relocations, and non-TLS symbols must be reference by
455
20.3k
  // non-TLS relocations, so there's a clear distinction between TLS
456
20.3k
  // and non-TLS symbols. It is an error if the same symbol is defined
457
20.3k
  // as a TLS symbol in one file and as a non-TLS symbol in other file.
458
20.3k
  if (Sym->SymbolKind != Symbol::PlaceholderKind && 
!Sym->isLazy()2.27k
&&
459
20.3k
      
!New.isLazy()2.21k
) {
460
2.19k
    bool TlsMismatch = (Sym->Type == STT_TLS && 
New.Type != STT_TLS45
) ||
461
2.19k
                       (Sym->Type != STT_TLS && 
New.Type == STT_TLS2.15k
);
462
2.19k
    if (TlsMismatch)
463
1
      error("TLS attribute mismatch: " + toString(*Sym) + "\n>>> defined in " +
464
1
            toString(New.File) + "\n>>> defined in " + toString(Sym->File));
465
2.19k
  }
466
20.3k
467
20.3k
  Symbol Old = *Sym;
468
20.3k
  memcpy(Sym, &New, getSymbolSize(New));
469
20.3k
470
20.3k
  Sym->VersionId = Old.VersionId;
471
20.3k
  Sym->Visibility = Old.Visibility;
472
20.3k
  Sym->IsUsedInRegularObj = Old.IsUsedInRegularObj;
473
20.3k
  Sym->ExportDynamic = Old.ExportDynamic;
474
20.3k
  Sym->CanInline = Old.CanInline;
475
20.3k
  Sym->Traced = Old.Traced;
476
20.3k
  Sym->ScriptDefined = Old.ScriptDefined;
477
20.3k
478
20.3k
  // Print out a log message if --trace-symbol was specified.
479
20.3k
  // This is for debugging.
480
20.3k
  if (Sym->Traced)
481
59
    printTraceSymbol(Sym);
482
20.3k
}
483
484
void maybeWarnUnorderableSymbol(const Symbol *Sym);
485
} // namespace elf
486
} // namespace lld
487
488
#endif