Coverage Report

Created: 2018-01-17 21:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/SymbolTable.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SymbolTable.cpp ----------------------------------------------------===//
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
// Symbol table is a bag of all known symbols. We put all symbols of
11
// all input files to the symbol table. The symbol table is basically
12
// a hash table with the logic to resolve symbol name conflicts using
13
// the symbol types.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#include "SymbolTable.h"
18
#include "Config.h"
19
#include "LinkerScript.h"
20
#include "Symbols.h"
21
#include "SyntheticSections.h"
22
#include "lld/Common/ErrorHandler.h"
23
#include "lld/Common/Memory.h"
24
#include "lld/Common/Strings.h"
25
#include "llvm/ADT/STLExtras.h"
26
27
using namespace llvm;
28
using namespace llvm::object;
29
using namespace llvm::ELF;
30
31
using namespace lld;
32
using namespace lld::elf;
33
34
SymbolTable *elf::Symtab;
35
36
5
static InputFile *getFirstElf() {
37
5
  if (!ObjectFiles.empty())
38
3
    return ObjectFiles[0];
39
2
  if (!SharedFiles.empty())
40
2
    return SharedFiles[0];
41
0
  return nullptr;
42
0
}
43
44
// All input object files must be for the same architecture
45
// (e.g. it does not make sense to link x86 object files with
46
// MIPS object files.) This function checks for that error.
47
1.37k
static bool isCompatible(InputFile *F) {
48
1.37k
  if (!F->isElf() && 
!isa<BitcodeFile>(F)134
)
49
51
    return true;
50
1.32k
51
1.32k
  if (F->EKind == Config->EKind && 
F->EMachine == Config->EMachine1.31k
) {
52
1.31k
    if (Config->EMachine != EM_MIPS)
53
1.20k
      return true;
54
112
    if (isMipsN32Abi(F) == Config->MipsN32Abi)
55
110
      return true;
56
9
  }
57
9
58
9
  if (!Config->Emulation.empty())
59
4
    error(toString(F) + " is incompatible with " + Config->Emulation);
60
5
  else
61
5
    error(toString(F) + " is incompatible with " + toString(getFirstElf()));
62
9
  return false;
63
9
}
64
65
// Add symbols in File to the symbol table.
66
1.37k
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67
1.37k
  if (!isCompatible(File))
68
9
    return;
69
1.36k
70
1.36k
  // Binary file
71
1.36k
  if (auto *F = dyn_cast<BinaryFile>(File)) {
72
3
    BinaryFiles.push_back(F);
73
3
    F->parse();
74
3
    return;
75
3
  }
76
1.36k
77
1.36k
  // .a file
78
1.36k
  if (auto *F = dyn_cast<ArchiveFile>(File)) {
79
39
    F->parse<ELFT>();
80
39
    return;
81
39
  }
82
1.32k
83
1.32k
  // Lazy object file
84
1.32k
  if (auto *F = dyn_cast<LazyObjFile>(File)) {
85
9
    F->parse<ELFT>();
86
9
    return;
87
9
  }
88
1.31k
89
1.31k
  if (Config->Trace)
90
6
    message(toString(File));
91
1.31k
92
1.31k
  // .so file
93
1.31k
  if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94
149
    // DSOs are uniquified not by filename but by soname.
95
149
    F->parseSoName();
96
149
    if (errorCount() || !SoNames.insert(F->SoName).second)
97
2
      return;
98
147
    SharedFiles.push_back(F);
99
147
    F->parseRest();
100
147
    return;
101
147
  }
102
1.16k
103
1.16k
  // LLVM bitcode file
104
1.16k
  if (auto *F = dyn_cast<BitcodeFile>(File)) {
105
82
    BitcodeFiles.push_back(F);
106
82
    F->parse<ELFT>(ComdatGroups);
107
82
    return;
108
82
  }
109
1.08k
110
1.08k
  // Regular object file
111
1.08k
  ObjectFiles.push_back(File);
112
1.08k
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
113
1.08k
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::InputFile*)
Line
Count
Source
66
173
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67
173
  if (!isCompatible(File))
68
4
    return;
69
169
70
169
  // Binary file
71
169
  if (auto *F = dyn_cast<BinaryFile>(File)) {
72
0
    BinaryFiles.push_back(F);
73
0
    F->parse();
74
0
    return;
75
0
  }
76
169
77
169
  // .a file
78
169
  if (auto *F = dyn_cast<ArchiveFile>(File)) {
79
1
    F->parse<ELFT>();
80
1
    return;
81
1
  }
82
168
83
168
  // Lazy object file
84
168
  if (auto *F = dyn_cast<LazyObjFile>(File)) {
85
0
    F->parse<ELFT>();
86
0
    return;
87
0
  }
88
168
89
168
  if (Config->Trace)
90
0
    message(toString(File));
91
168
92
168
  // .so file
93
168
  if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94
35
    // DSOs are uniquified not by filename but by soname.
95
35
    F->parseSoName();
96
35
    if (errorCount() || !SoNames.insert(F->SoName).second)
97
1
      return;
98
34
    SharedFiles.push_back(F);
99
34
    F->parseRest();
100
34
    return;
101
34
  }
102
133
103
133
  // LLVM bitcode file
104
133
  if (auto *F = dyn_cast<BitcodeFile>(File)) {
105
0
    BitcodeFiles.push_back(F);
106
0
    F->parse<ELFT>(ComdatGroups);
107
0
    return;
108
0
  }
109
133
110
133
  // Regular object file
111
133
  ObjectFiles.push_back(File);
112
133
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
113
133
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::InputFile*)
Line
Count
Source
66
82
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67
82
  if (!isCompatible(File))
68
2
    return;
69
80
70
80
  // Binary file
71
80
  if (auto *F = dyn_cast<BinaryFile>(File)) {
72
0
    BinaryFiles.push_back(F);
73
0
    F->parse();
74
0
    return;
75
0
  }
76
80
77
80
  // .a file
78
80
  if (auto *F = dyn_cast<ArchiveFile>(File)) {
79
0
    F->parse<ELFT>();
80
0
    return;
81
0
  }
82
80
83
80
  // Lazy object file
84
80
  if (auto *F = dyn_cast<LazyObjFile>(File)) {
85
0
    F->parse<ELFT>();
86
0
    return;
87
0
  }
88
80
89
80
  if (Config->Trace)
90
0
    message(toString(File));
91
80
92
80
  // .so file
93
80
  if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94
8
    // DSOs are uniquified not by filename but by soname.
95
8
    F->parseSoName();
96
8
    if (errorCount() || !SoNames.insert(F->SoName).second)
97
0
      return;
98
8
    SharedFiles.push_back(F);
99
8
    F->parseRest();
100
8
    return;
101
8
  }
102
72
103
72
  // LLVM bitcode file
104
72
  if (auto *F = dyn_cast<BitcodeFile>(File)) {
105
0
    BitcodeFiles.push_back(F);
106
0
    F->parse<ELFT>(ComdatGroups);
107
0
    return;
108
0
  }
109
72
110
72
  // Regular object file
111
72
  ObjectFiles.push_back(File);
112
72
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
113
72
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >(lld::elf::InputFile*)
Line
Count
Source
66
1.07k
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67
1.07k
  if (!isCompatible(File))
68
1
    return;
69
1.07k
70
1.07k
  // Binary file
71
1.07k
  if (auto *F = dyn_cast<BinaryFile>(File)) {
72
3
    BinaryFiles.push_back(F);
73
3
    F->parse();
74
3
    return;
75
3
  }
76
1.07k
77
1.07k
  // .a file
78
1.07k
  if (auto *F = dyn_cast<ArchiveFile>(File)) {
79
37
    F->parse<ELFT>();
80
37
    return;
81
37
  }
82
1.03k
83
1.03k
  // Lazy object file
84
1.03k
  if (auto *F = dyn_cast<LazyObjFile>(File)) {
85
9
    F->parse<ELFT>();
86
9
    return;
87
9
  }
88
1.02k
89
1.02k
  if (Config->Trace)
90
6
    message(toString(File));
91
1.02k
92
1.02k
  // .so file
93
1.02k
  if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94
102
    // DSOs are uniquified not by filename but by soname.
95
102
    F->parseSoName();
96
102
    if (errorCount() || !SoNames.insert(F->SoName).second)
97
1
      return;
98
101
    SharedFiles.push_back(F);
99
101
    F->parseRest();
100
101
    return;
101
101
  }
102
927
103
927
  // LLVM bitcode file
104
927
  if (auto *F = dyn_cast<BitcodeFile>(File)) {
105
82
    BitcodeFiles.push_back(F);
106
82
    F->parse<ELFT>(ComdatGroups);
107
82
    return;
108
82
  }
109
845
110
845
  // Regular object file
111
845
  ObjectFiles.push_back(File);
112
845
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
113
845
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >(lld::elf::InputFile*)
Line
Count
Source
66
40
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67
40
  if (!isCompatible(File))
68
2
    return;
69
38
70
38
  // Binary file
71
38
  if (auto *F = dyn_cast<BinaryFile>(File)) {
72
0
    BinaryFiles.push_back(F);
73
0
    F->parse();
74
0
    return;
75
0
  }
76
38
77
38
  // .a file
78
38
  if (auto *F = dyn_cast<ArchiveFile>(File)) {
79
1
    F->parse<ELFT>();
80
1
    return;
81
1
  }
82
37
83
37
  // Lazy object file
84
37
  if (auto *F = dyn_cast<LazyObjFile>(File)) {
85
0
    F->parse<ELFT>();
86
0
    return;
87
0
  }
88
37
89
37
  if (Config->Trace)
90
0
    message(toString(File));
91
37
92
37
  // .so file
93
37
  if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94
4
    // DSOs are uniquified not by filename but by soname.
95
4
    F->parseSoName();
96
4
    if (errorCount() || !SoNames.insert(F->SoName).second)
97
0
      return;
98
4
    SharedFiles.push_back(F);
99
4
    F->parseRest();
100
4
    return;
101
4
  }
102
33
103
33
  // LLVM bitcode file
104
33
  if (auto *F = dyn_cast<BitcodeFile>(File)) {
105
0
    BitcodeFiles.push_back(F);
106
0
    F->parse<ELFT>(ComdatGroups);
107
0
    return;
108
0
  }
109
33
110
33
  // Regular object file
111
33
  ObjectFiles.push_back(File);
112
33
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
113
33
}
114
115
// This function is where all the optimizations of link-time
116
// optimization happens. When LTO is in use, some input files are
117
// not in native object file format but in the LLVM bitcode format.
118
// This function compiles bitcode files into a few big native files
119
// using LLVM functions and replaces bitcode symbols with the results.
120
// Because all bitcode files that the program consists of are passed
121
// to the compiler at once, it can do whole-program optimization.
122
941
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123
941
  if (BitcodeFiles.empty())
124
885
    return;
125
56
126
56
  // Compile bitcode files and replace bitcode symbols.
127
56
  LTO.reset(new BitcodeCompiler);
128
56
  for (BitcodeFile *F : BitcodeFiles)
129
80
    LTO->add(*F);
130
56
131
76
  for (InputFile *File : LTO->compile()) {
132
76
    DenseSet<CachedHashStringRef> DummyGroups;
133
76
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
134
76
    ObjectFiles.push_back(File);
135
76
  }
136
56
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
122
118
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123
118
  if (BitcodeFiles.empty())
124
118
    return;
125
0
126
0
  // Compile bitcode files and replace bitcode symbols.
127
0
  LTO.reset(new BitcodeCompiler);
128
0
  for (BitcodeFile *F : BitcodeFiles)
129
0
    LTO->add(*F);
130
0
131
0
  for (InputFile *File : LTO->compile()) {
132
0
    DenseSet<CachedHashStringRef> DummyGroups;
133
0
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
134
0
    ObjectFiles.push_back(File);
135
0
  }
136
0
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
122
52
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123
52
  if (BitcodeFiles.empty())
124
52
    return;
125
0
126
0
  // Compile bitcode files and replace bitcode symbols.
127
0
  LTO.reset(new BitcodeCompiler);
128
0
  for (BitcodeFile *F : BitcodeFiles)
129
0
    LTO->add(*F);
130
0
131
0
  for (InputFile *File : LTO->compile()) {
132
0
    DenseSet<CachedHashStringRef> DummyGroups;
133
0
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
134
0
    ObjectFiles.push_back(File);
135
0
  }
136
0
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
122
743
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123
743
  if (BitcodeFiles.empty())
124
687
    return;
125
56
126
56
  // Compile bitcode files and replace bitcode symbols.
127
56
  LTO.reset(new BitcodeCompiler);
128
56
  for (BitcodeFile *F : BitcodeFiles)
129
80
    LTO->add(*F);
130
56
131
76
  for (InputFile *File : LTO->compile()) {
132
76
    DenseSet<CachedHashStringRef> DummyGroups;
133
76
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
134
76
    ObjectFiles.push_back(File);
135
76
  }
136
56
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
122
28
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123
28
  if (BitcodeFiles.empty())
124
28
    return;
125
0
126
0
  // Compile bitcode files and replace bitcode symbols.
127
0
  LTO.reset(new BitcodeCompiler);
128
0
  for (BitcodeFile *F : BitcodeFiles)
129
0
    LTO->add(*F);
130
0
131
0
  for (InputFile *File : LTO->compile()) {
132
0
    DenseSet<CachedHashStringRef> DummyGroups;
133
0
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
134
0
    ObjectFiles.push_back(File);
135
0
  }
136
0
}
137
138
Defined *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
139
71
                                  uint8_t Binding) {
140
71
  Symbol *Sym =
141
71
      addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, nullptr, nullptr);
142
71
  return cast<Defined>(Sym);
143
71
}
144
145
// Set a flag for --trace-symbol so that we can print out a log message
146
// if a new symbol with the same name is inserted into the symbol table.
147
20
void SymbolTable::trace(StringRef Name) {
148
20
  SymMap.insert({CachedHashStringRef(Name), -1});
149
20
}
150
151
// Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
152
// Used to implement --wrap.
153
9
template <class ELFT> void SymbolTable::addSymbolWrap(StringRef Name) {
154
9
  Symbol *Sym = find(Name);
155
9
  if (!Sym)
156
2
    return;
157
7
  Symbol *Real = addUndefined<ELFT>(Saver.save("__real_" + Name));
158
7
  Symbol *Wrap = addUndefined<ELFT>(Saver.save("__wrap_" + Name));
159
7
  WrappedSymbols.push_back({Sym, Real, Wrap});
160
7
161
7
  // We want to tell LTO not to inline symbols to be overwritten
162
7
  // because LTO doesn't know the final symbol contents after renaming.
163
7
  Real->CanInline = false;
164
7
  Sym->CanInline = false;
165
7
166
7
  // Tell LTO not to eliminate these symbols.
167
7
  Sym->IsUsedInRegularObj = true;
168
7
  Wrap->IsUsedInRegularObj = true;
169
7
}
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolWrap<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef)
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolWrap<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef)
void lld::elf::SymbolTable::addSymbolWrap<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef)
Line
Count
Source
153
9
template <class ELFT> void SymbolTable::addSymbolWrap(StringRef Name) {
154
9
  Symbol *Sym = find(Name);
155
9
  if (!Sym)
156
2
    return;
157
7
  Symbol *Real = addUndefined<ELFT>(Saver.save("__real_" + Name));
158
7
  Symbol *Wrap = addUndefined<ELFT>(Saver.save("__wrap_" + Name));
159
7
  WrappedSymbols.push_back({Sym, Real, Wrap});
160
7
161
7
  // We want to tell LTO not to inline symbols to be overwritten
162
7
  // because LTO doesn't know the final symbol contents after renaming.
163
7
  Real->CanInline = false;
164
7
  Sym->CanInline = false;
165
7
166
7
  // Tell LTO not to eliminate these symbols.
167
7
  Sym->IsUsedInRegularObj = true;
168
7
  Wrap->IsUsedInRegularObj = true;
169
7
}
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolWrap<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef)
170
171
// Apply symbol renames created by -wrap. The renames are created
172
// before LTO in addSymbolWrap() to have a chance to inform LTO (if
173
// LTO is running) not to include these symbols in IPO. Now that the
174
// symbols are finalized, we can perform the replacement.
175
936
void SymbolTable::applySymbolWrap() {
176
936
  // This function rotates 3 symbols:
177
936
  //
178
936
  // __real_sym becomes sym
179
936
  // sym        becomes __wrap_sym
180
936
  // __wrap_sym becomes __real_sym
181
936
  //
182
936
  // The last part is special in that we don't want to change what references to
183
936
  // __wrap_sym point to, we just want have __real_sym in the symbol table.
184
936
185
936
  for (WrappedSymbol &W : WrappedSymbols) {
186
7
    // First, make a copy of __real_sym.
187
7
    Symbol *Real = nullptr;
188
7
    if (W.Real->isDefined()) {
189
5
      Real = (Symbol *)make<SymbolUnion>();
190
5
      memcpy(Real, W.Real, sizeof(SymbolUnion));
191
5
    }
192
7
193
7
    // Replace __real_sym with sym and sym with __wrap_sym.
194
7
    memcpy(W.Real, W.Sym, sizeof(SymbolUnion));
195
7
    memcpy(W.Sym, W.Wrap, sizeof(SymbolUnion));
196
7
197
7
    // We now have two copies of __wrap_sym. Drop one.
198
7
    W.Wrap->IsUsedInRegularObj = false;
199
7
200
7
    if (Real)
201
5
      SymVector.push_back(Real);
202
7
  }
203
936
}
204
205
13.5k
static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
206
13.5k
  if (VA == STV_DEFAULT)
207
13.5k
    return VB;
208
33
  if (VB == STV_DEFAULT)
209
21
    return VA;
210
12
  return std::min(VA, VB);
211
12
}
212
213
// Find an existing symbol or create and insert a new one.
214
13.6k
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
215
13.6k
  // <name>@@<version> means the symbol is the default version. In that
216
13.6k
  // case <name>@@<version> will be used to resolve references to <name>.
217
13.6k
  //
218
13.6k
  // Since this is a hot path, the following string search code is
219
13.6k
  // optimized for speed. StringRef::find(char) is much faster than
220
13.6k
  // StringRef::find(StringRef).
221
13.6k
  size_t Pos = Name.find('@');
222
13.6k
  if (Pos != StringRef::npos && 
Pos + 1 < Name.size()34
&&
Name[Pos + 1] == '@'34
)
223
6
    Name = Name.take_front(Pos);
224
13.6k
225
13.6k
  auto P = SymMap.insert({CachedHashStringRef(Name), (int)SymVector.size()});
226
13.6k
  int &SymIndex = P.first->second;
227
13.6k
  bool IsNew = P.second;
228
13.6k
  bool Traced = false;
229
13.6k
230
13.6k
  if (SymIndex == -1) {
231
16
    SymIndex = SymVector.size();
232
16
    IsNew = Traced = true;
233
16
  }
234
13.6k
235
13.6k
  Symbol *Sym;
236
13.6k
  if (IsNew) {
237
12.9k
    Sym = (Symbol *)make<SymbolUnion>();
238
12.9k
    Sym->InVersionScript = false;
239
12.9k
    Sym->Visibility = STV_DEFAULT;
240
12.9k
    Sym->IsUsedInRegularObj = false;
241
12.9k
    Sym->ExportDynamic = false;
242
12.9k
    Sym->CanInline = true;
243
12.9k
    Sym->Traced = Traced;
244
12.9k
    Sym->VersionId = Config->DefaultSymbolVersion;
245
12.9k
    SymVector.push_back(Sym);
246
12.9k
  } else {
247
715
    Sym = SymVector[SymIndex];
248
715
  }
249
13.6k
  return {Sym, IsNew};
250
13.6k
}
251
252
// Find an existing symbol or create and insert a new one, then apply the given
253
// attributes.
254
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name, uint8_t Type,
255
                                              uint8_t Visibility,
256
                                              bool CanOmitFromDynSym,
257
13.5k
                                              InputFile *File) {
258
13.5k
  Symbol *S;
259
13.5k
  bool WasInserted;
260
13.5k
  std::tie(S, WasInserted) = insert(Name);
261
13.5k
262
13.5k
  // Merge in the new symbol's visibility.
263
13.5k
  S->Visibility = getMinVisibility(S->Visibility, Visibility);
264
13.5k
265
13.5k
  if (!CanOmitFromDynSym && 
(13.2k
Config->Shared13.2k
||
Config->ExportDynamic11.9k
))
266
1.28k
    S->ExportDynamic = true;
267
13.5k
268
13.5k
  if (!File || 
File->kind() == InputFile::ObjKind12.8k
)
269
13.0k
    S->IsUsedInRegularObj = true;
270
13.5k
271
13.5k
  if (!WasInserted && 
S->Type != Symbol::UnknownType667
&&
272
13.5k
      
((Type == STT_TLS) != S->isTls())649
) {
273
1
    error("TLS attribute mismatch: " + toString(*S) + "\n>>> defined in " +
274
1
          toString(S->File) + "\n>>> defined in " + toString(File));
275
1
  }
276
13.5k
277
13.5k
  return {S, WasInserted};
278
13.5k
}
279
280
44
template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
281
44
  return addUndefined<ELFT>(Name, STB_GLOBAL, STV_DEFAULT,
282
44
                            /*Type*/ 0,
283
44
                            /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
284
44
}
Unexecuted instantiation: lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef)
Unexecuted instantiation: lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef)
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef)
Line
Count
Source
280
44
template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
281
44
  return addUndefined<ELFT>(Name, STB_GLOBAL, STV_DEFAULT,
282
44
                            /*Type*/ 0,
283
44
                            /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
284
44
}
Unexecuted instantiation: lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef)
285
286
13.1k
static uint8_t getVisibility(uint8_t StOther) { return StOther & 3; }
287
288
template <class ELFT>
289
Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
290
                                  uint8_t StOther, uint8_t Type,
291
647
                                  bool CanOmitFromDynSym, InputFile *File) {
292
647
  Symbol *S;
293
647
  bool WasInserted;
294
647
  uint8_t Visibility = getVisibility(StOther);
295
647
  std::tie(S, WasInserted) =
296
647
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
297
647
  // An undefined symbol with non default visibility must be satisfied
298
647
  // in the same DSO.
299
647
  if (WasInserted || 
(126
isa<SharedSymbol>(S)126
&&
Visibility != STV_DEFAULT16
)) {
300
522
    replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
301
522
    return S;
302
522
  }
303
125
  if (S->isShared() || 
S->isLazy()110
||
(106
S->isUndefined()106
&&
Binding != STB_WEAK31
))
304
48
    S->Binding = Binding;
305
125
  if (Binding != STB_WEAK) {
306
114
    if (auto *SS = dyn_cast<SharedSymbol>(S))
307
13
      if (!Config->GcSections)
308
11
        SS->getFile<ELFT>().IsNeeded = true;
309
114
  }
310
125
  if (auto *L = dyn_cast<Lazy>(S)) {
311
4
    // An undefined weak will not fetch archive members. See comment on Lazy in
312
4
    // Symbols.h for the details.
313
4
    if (Binding == STB_WEAK)
314
1
      L->Type = Type;
315
3
    else if (InputFile *F = L->fetch())
316
2
      addFile<ELFT>(F);
317
4
  }
318
125
  return S;
319
125
}
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef, unsigned char, unsigned char, unsigned char, bool, lld::elf::InputFile*)
Line
Count
Source
291
89
                                  bool CanOmitFromDynSym, InputFile *File) {
292
89
  Symbol *S;
293
89
  bool WasInserted;
294
89
  uint8_t Visibility = getVisibility(StOther);
295
89
  std::tie(S, WasInserted) =
296
89
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
297
89
  // An undefined symbol with non default visibility must be satisfied
298
89
  // in the same DSO.
299
89
  if (WasInserted || 
(18
isa<SharedSymbol>(S)18
&&
Visibility != STV_DEFAULT8
)) {
300
71
    replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
301
71
    return S;
302
71
  }
303
18
  if (S->isShared() || 
S->isLazy()10
||
(10
S->isUndefined()10
&&
Binding != STB_WEAK0
))
304
8
    S->Binding = Binding;
305
18
  if (Binding != STB_WEAK) {
306
17
    if (auto *SS = dyn_cast<SharedSymbol>(S))
307
7
      if (!Config->GcSections)
308
7
        SS->getFile<ELFT>().IsNeeded = true;
309
17
  }
310
18
  if (auto *L = dyn_cast<Lazy>(S)) {
311
0
    // An undefined weak will not fetch archive members. See comment on Lazy in
312
0
    // Symbols.h for the details.
313
0
    if (Binding == STB_WEAK)
314
0
      L->Type = Type;
315
0
    else if (InputFile *F = L->fetch())
316
0
      addFile<ELFT>(F);
317
0
  }
318
18
  return S;
319
18
}
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, unsigned char, unsigned char, unsigned char, bool, lld::elf::InputFile*)
Line
Count
Source
291
38
                                  bool CanOmitFromDynSym, InputFile *File) {
292
38
  Symbol *S;
293
38
  bool WasInserted;
294
38
  uint8_t Visibility = getVisibility(StOther);
295
38
  std::tie(S, WasInserted) =
296
38
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
297
38
  // An undefined symbol with non default visibility must be satisfied
298
38
  // in the same DSO.
299
38
  if (WasInserted || 
(5
isa<SharedSymbol>(S)5
&&
Visibility != STV_DEFAULT0
)) {
300
33
    replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
301
33
    return S;
302
33
  }
303
5
  if (S->isShared() || S->isLazy() || (S->isUndefined() && 
Binding != STB_WEAK0
))
304
0
    S->Binding = Binding;
305
5
  if (Binding != STB_WEAK) {
306
5
    if (auto *SS = dyn_cast<SharedSymbol>(S))
307
0
      if (!Config->GcSections)
308
0
        SS->getFile<ELFT>().IsNeeded = true;
309
5
  }
310
5
  if (auto *L = dyn_cast<Lazy>(S)) {
311
0
    // An undefined weak will not fetch archive members. See comment on Lazy in
312
0
    // Symbols.h for the details.
313
0
    if (Binding == STB_WEAK)
314
0
      L->Type = Type;
315
0
    else if (InputFile *F = L->fetch())
316
0
      addFile<ELFT>(F);
317
0
  }
318
5
  return S;
319
5
}
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, unsigned char, unsigned char, unsigned char, bool, lld::elf::InputFile*)
Line
Count
Source
291
506
                                  bool CanOmitFromDynSym, InputFile *File) {
292
506
  Symbol *S;
293
506
  bool WasInserted;
294
506
  uint8_t Visibility = getVisibility(StOther);
295
506
  std::tie(S, WasInserted) =
296
506
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
297
506
  // An undefined symbol with non default visibility must be satisfied
298
506
  // in the same DSO.
299
506
  if (WasInserted || 
(103
isa<SharedSymbol>(S)103
&&
Visibility != STV_DEFAULT8
)) {
300
404
    replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
301
404
    return S;
302
404
  }
303
102
  if (S->isShared() || 
S->isLazy()95
||
(91
S->isUndefined()91
&&
Binding != STB_WEAK31
))
304
40
    S->Binding = Binding;
305
102
  if (Binding != STB_WEAK) {
306
92
    if (auto *SS = dyn_cast<SharedSymbol>(S))
307
6
      if (!Config->GcSections)
308
4
        SS->getFile<ELFT>().IsNeeded = true;
309
92
  }
310
102
  if (auto *L = dyn_cast<Lazy>(S)) {
311
4
    // An undefined weak will not fetch archive members. See comment on Lazy in
312
4
    // Symbols.h for the details.
313
4
    if (Binding == STB_WEAK)
314
1
      L->Type = Type;
315
3
    else if (InputFile *F = L->fetch())
316
2
      addFile<ELFT>(F);
317
4
  }
318
102
  return S;
319
102
}
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef, unsigned char, unsigned char, unsigned char, bool, lld::elf::InputFile*)
Line
Count
Source
291
14
                                  bool CanOmitFromDynSym, InputFile *File) {
292
14
  Symbol *S;
293
14
  bool WasInserted;
294
14
  uint8_t Visibility = getVisibility(StOther);
295
14
  std::tie(S, WasInserted) =
296
14
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
297
14
  // An undefined symbol with non default visibility must be satisfied
298
14
  // in the same DSO.
299
14
  if (WasInserted || 
(0
isa<SharedSymbol>(S)0
&&
Visibility != STV_DEFAULT0
)) {
300
14
    replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
301
14
    return S;
302
14
  }
303
0
  if (S->isShared() || S->isLazy() || (S->isUndefined() && Binding != STB_WEAK))
304
0
    S->Binding = Binding;
305
0
  if (Binding != STB_WEAK) {
306
0
    if (auto *SS = dyn_cast<SharedSymbol>(S))
307
0
      if (!Config->GcSections)
308
0
        SS->getFile<ELFT>().IsNeeded = true;
309
0
  }
310
0
  if (auto *L = dyn_cast<Lazy>(S)) {
311
0
    // An undefined weak will not fetch archive members. See comment on Lazy in
312
0
    // Symbols.h for the details.
313
0
    if (Binding == STB_WEAK)
314
0
      L->Type = Type;
315
0
    else if (InputFile *F = L->fetch())
316
0
      addFile<ELFT>(F);
317
0
  }
318
0
  return S;
319
0
}
320
321
// Using .symver foo,foo@@VER unfortunately creates two symbols: foo and
322
// foo@@VER. We want to effectively ignore foo, so give precedence to
323
// foo@@VER.
324
// FIXME: If users can transition to using
325
// .symver foo,foo@@@VER
326
// we can delete this hack.
327
48
static int compareVersion(Symbol *S, StringRef Name) {
328
48
  bool A = Name.contains("@@");
329
48
  bool B = S->getName().contains("@@");
330
48
  if (A && 
!B0
)
331
0
    return 1;
332
48
  if (!A && B)
333
0
    return -1;
334
48
  return 0;
335
48
}
336
337
// We have a new defined symbol with the specified binding. Return 1 if the new
338
// symbol should win, -1 if the new symbol should lose, or 0 if both symbols are
339
// strong defined symbols.
340
static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding,
341
12.4k
                          StringRef Name) {
342
12.4k
  if (WasInserted)
343
12.1k
    return 1;
344
335
  if (!S->isDefined())
345
287
    return 1;
346
48
  if (int R = compareVersion(S, Name))
347
0
    return R;
348
48
  if (Binding == STB_WEAK)
349
10
    return -1;
350
38
  if (S->isWeak())
351
12
    return 1;
352
26
  return 0;
353
26
}
354
355
// We have a new non-common defined symbol with the specified binding. Return 1
356
// if the new symbol should win, -1 if the new symbol should lose, or 0 if there
357
// is a conflict. If the new symbol wins, also update the binding.
358
static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding,
359
                                   bool IsAbsolute, uint64_t Value,
360
12.4k
                                   StringRef Name) {
361
12.4k
  if (int Cmp = compareDefined(S, WasInserted, Binding, Name))
362
12.3k
    return Cmp;
363
20
  if (auto *R = dyn_cast<Defined>(S)) {
364
20
    if (R->Section && 
isa<BssSection>(R->Section)19
) {
365
2
      // Non-common symbols take precedence over common symbols.
366
2
      if (Config->WarnCommon)
367
1
        warn("common " + S->getName() + " is overridden");
368
2
      return 1;
369
2
    }
370
18
    if (R->Section == nullptr && 
Binding == STB_GLOBAL1
&&
IsAbsolute1
&&
371
18
        
R->Value == Value0
)
372
0
      return -1;
373
18
  }
374
18
  return 0;
375
18
}
376
377
Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, uint32_t Alignment,
378
                               uint8_t Binding, uint8_t StOther, uint8_t Type,
379
72
                               InputFile &File) {
380
72
  Symbol *S;
381
72
  bool WasInserted;
382
72
  std::tie(S, WasInserted) = insert(N, Type, getVisibility(StOther),
383
72
                                    /*CanOmitFromDynSym*/ false, &File);
384
72
  int Cmp = compareDefined(S, WasInserted, Binding, N);
385
72
  if (Cmp > 0) {
386
62
    auto *Bss = make<BssSection>("COMMON", Size, Alignment);
387
62
    Bss->File = &File;
388
62
    Bss->Live = !Config->GcSections;
389
62
    InputSections.push_back(Bss);
390
62
391
62
    replaceSymbol<Defined>(S, &File, N, Binding, StOther, Type, 0, Size, Bss);
392
62
  } else 
if (10
Cmp == 010
) {
393
6
    auto *D = cast<Defined>(S);
394
6
    auto *Bss = dyn_cast_or_null<BssSection>(D->Section);
395
6
    if (!Bss) {
396
1
      // Non-common symbols take precedence over common symbols.
397
1
      if (Config->WarnCommon)
398
0
        warn("common " + S->getName() + " is overridden");
399
1
      return S;
400
1
    }
401
5
402
5
    if (Config->WarnCommon)
403
3
      warn("multiple common of " + D->getName());
404
5
405
5
    Bss->Alignment = std::max(Bss->Alignment, Alignment);
406
5
    if (Size > Bss->Size) {
407
5
      D->File = Bss->File = &File;
408
5
      D->Size = Bss->Size = Size;
409
5
    }
410
5
  }
411
72
  
return S71
;
412
72
}
413
414
18
static void warnOrError(const Twine &Msg) {
415
18
  if (Config->AllowMultipleDefinition)
416
3
    warn(Msg);
417
15
  else
418
15
    error(Msg);
419
18
}
420
421
1
static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
422
1
  warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
423
1
              toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
424
1
}
425
426
static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
427
17
                            uint64_t ErrOffset) {
428
17
  Defined *D = cast<Defined>(Sym);
429
17
  if (!D->Section || !ErrSec) {
430
0
    reportDuplicate(Sym, ErrSec ? ErrSec->File : nullptr);
431
0
    return;
432
0
  }
433
17
434
17
  // Construct and print an error message in the form of:
435
17
  //
436
17
  //   ld.lld: error: duplicate symbol: foo
437
17
  //   >>> defined at bar.c:30
438
17
  //   >>>            bar.o (/home/alice/src/bar.o)
439
17
  //   >>> defined at baz.c:563
440
17
  //   >>>            baz.o in archive libbaz.a
441
17
  auto *Sec1 = cast<InputSectionBase>(D->Section);
442
17
  std::string Src1 = Sec1->getSrcMsg(*Sym, D->Value);
443
17
  std::string Obj1 = Sec1->getObjMsg(D->Value);
444
17
  std::string Src2 = ErrSec->getSrcMsg(*Sym, ErrOffset);
445
17
  std::string Obj2 = ErrSec->getObjMsg(ErrOffset);
446
17
447
17
  std::string Msg = "duplicate symbol: " + toString(*Sym) + "\n>>> defined at ";
448
17
  if (!Src1.empty())
449
5
    Msg += Src1 + "\n>>>            ";
450
17
  Msg += Obj1 + "\n>>> defined at ";
451
17
  if (!Src2.empty())
452
5
    Msg += Src2 + "\n>>>            ";
453
17
  Msg += Obj2;
454
17
  warnOrError(Msg);
455
17
}
456
457
Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
458
                                uint64_t Value, uint64_t Size, uint8_t Binding,
459
12.3k
                                SectionBase *Section, InputFile *File) {
460
12.3k
  Symbol *S;
461
12.3k
  bool WasInserted;
462
12.3k
  std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
463
12.3k
                                    /*CanOmitFromDynSym*/ false, File);
464
12.3k
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
465
12.3k
                                    Value, Name);
466
12.3k
  if (Cmp > 0)
467
12.2k
    replaceSymbol<Defined>(S, File, Name, Binding, StOther, Type, Value, Size,
468
12.2k
                           Section);
469
23
  else if (Cmp == 0)
470
17
    reportDuplicate(S, dyn_cast_or_null<InputSectionBase>(Section), Value);
471
12.3k
  return S;
472
12.3k
}
473
474
template <typename ELFT>
475
void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> &File,
476
                            const typename ELFT::Sym &Sym, uint32_t Alignment,
477
350
                            uint32_t VerdefIndex) {
478
350
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
479
350
  // as the visibility, which will leave the visibility in the symbol table
480
350
  // unchanged.
481
350
  Symbol *S;
482
350
  bool WasInserted;
483
350
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
484
350
                                    /*CanOmitFromDynSym*/ true, &File);
485
350
  // Make sure we preempt DSO symbols with default visibility.
486
350
  if (Sym.getVisibility() == STV_DEFAULT)
487
345
    S->ExportDynamic = true;
488
350
489
350
  // An undefined symbol with non default visibility must be satisfied
490
350
  // in the same DSO.
491
350
  if (WasInserted ||
492
350
      
(179
(179
S->isUndefined()179
||
S->isLazy()17
) &&
S->Visibility == STV_DEFAULT162
)) {
493
331
    uint8_t Binding = S->Binding;
494
331
    replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
495
331
                                Sym.getType(), Sym.st_value, Sym.st_size,
496
331
                                Alignment, VerdefIndex);
497
331
    if (!WasInserted) {
498
160
      S->Binding = Binding;
499
160
      if (!S->isWeak() && 
!Config->GcSections154
)
500
148
        File.IsNeeded = true;
501
160
    }
502
331
  }
503
350
}
void lld::elf::SymbolTable::addShared<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >&, llvm::object::ELFType<(llvm::support::endianness)1, false>::Sym const&, unsigned int, unsigned int)
Line
Count
Source
477
70
                            uint32_t VerdefIndex) {
478
70
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
479
70
  // as the visibility, which will leave the visibility in the symbol table
480
70
  // unchanged.
481
70
  Symbol *S;
482
70
  bool WasInserted;
483
70
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
484
70
                                    /*CanOmitFromDynSym*/ true, &File);
485
70
  // Make sure we preempt DSO symbols with default visibility.
486
70
  if (Sym.getVisibility() == STV_DEFAULT)
487
70
    S->ExportDynamic = true;
488
70
489
70
  // An undefined symbol with non default visibility must be satisfied
490
70
  // in the same DSO.
491
70
  if (WasInserted ||
492
70
      
(38
(38
S->isUndefined()38
||
S->isLazy()4
) &&
S->Visibility == STV_DEFAULT34
)) {
493
66
    uint8_t Binding = S->Binding;
494
66
    replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
495
66
                                Sym.getType(), Sym.st_value, Sym.st_size,
496
66
                                Alignment, VerdefIndex);
497
66
    if (!WasInserted) {
498
34
      S->Binding = Binding;
499
34
      if (!S->isWeak() && 
!Config->GcSections31
)
500
31
        File.IsNeeded = true;
501
34
    }
502
66
  }
503
70
}
void lld::elf::SymbolTable::addShared<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >&, llvm::object::ELFType<(llvm::support::endianness)0, false>::Sym const&, unsigned int, unsigned int)
Line
Count
Source
477
29
                            uint32_t VerdefIndex) {
478
29
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
479
29
  // as the visibility, which will leave the visibility in the symbol table
480
29
  // unchanged.
481
29
  Symbol *S;
482
29
  bool WasInserted;
483
29
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
484
29
                                    /*CanOmitFromDynSym*/ true, &File);
485
29
  // Make sure we preempt DSO symbols with default visibility.
486
29
  if (Sym.getVisibility() == STV_DEFAULT)
487
29
    S->ExportDynamic = true;
488
29
489
29
  // An undefined symbol with non default visibility must be satisfied
490
29
  // in the same DSO.
491
29
  if (WasInserted ||
492
29
      
(8
(8
S->isUndefined()8
||
S->isLazy()0
) &&
S->Visibility == STV_DEFAULT8
)) {
493
29
    uint8_t Binding = S->Binding;
494
29
    replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
495
29
                                Sym.getType(), Sym.st_value, Sym.st_size,
496
29
                                Alignment, VerdefIndex);
497
29
    if (!WasInserted) {
498
8
      S->Binding = Binding;
499
8
      if (!S->isWeak() && !Config->GcSections)
500
8
        File.IsNeeded = true;
501
8
    }
502
29
  }
503
29
}
void lld::elf::SymbolTable::addShared<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >&, llvm::object::ELFType<(llvm::support::endianness)1, true>::Sym const&, unsigned int, unsigned int)
Line
Count
Source
477
239
                            uint32_t VerdefIndex) {
478
239
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
479
239
  // as the visibility, which will leave the visibility in the symbol table
480
239
  // unchanged.
481
239
  Symbol *S;
482
239
  bool WasInserted;
483
239
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
484
239
                                    /*CanOmitFromDynSym*/ true, &File);
485
239
  // Make sure we preempt DSO symbols with default visibility.
486
239
  if (Sym.getVisibility() == STV_DEFAULT)
487
234
    S->ExportDynamic = true;
488
239
489
239
  // An undefined symbol with non default visibility must be satisfied
490
239
  // in the same DSO.
491
239
  if (WasInserted ||
492
239
      
(128
(128
S->isUndefined()128
||
S->isLazy()13
) &&
S->Visibility == STV_DEFAULT115
)) {
493
224
    uint8_t Binding = S->Binding;
494
224
    replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
495
224
                                Sym.getType(), Sym.st_value, Sym.st_size,
496
224
                                Alignment, VerdefIndex);
497
224
    if (!WasInserted) {
498
113
      S->Binding = Binding;
499
113
      if (!S->isWeak() && 
!Config->GcSections110
)
500
104
        File.IsNeeded = true;
501
113
    }
502
224
  }
503
239
}
void lld::elf::SymbolTable::addShared<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef, lld::elf::SharedFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >&, llvm::object::ELFType<(llvm::support::endianness)0, true>::Sym const&, unsigned int, unsigned int)
Line
Count
Source
477
12
                            uint32_t VerdefIndex) {
478
12
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
479
12
  // as the visibility, which will leave the visibility in the symbol table
480
12
  // unchanged.
481
12
  Symbol *S;
482
12
  bool WasInserted;
483
12
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
484
12
                                    /*CanOmitFromDynSym*/ true, &File);
485
12
  // Make sure we preempt DSO symbols with default visibility.
486
12
  if (Sym.getVisibility() == STV_DEFAULT)
487
12
    S->ExportDynamic = true;
488
12
489
12
  // An undefined symbol with non default visibility must be satisfied
490
12
  // in the same DSO.
491
12
  if (WasInserted ||
492
12
      
(5
(5
S->isUndefined()5
||
S->isLazy()0
) &&
S->Visibility == STV_DEFAULT5
)) {
493
12
    uint8_t Binding = S->Binding;
494
12
    replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
495
12
                                Sym.getType(), Sym.st_value, Sym.st_size,
496
12
                                Alignment, VerdefIndex);
497
12
    if (!WasInserted) {
498
5
      S->Binding = Binding;
499
5
      if (!S->isWeak() && !Config->GcSections)
500
5
        File.IsNeeded = true;
501
5
    }
502
12
  }
503
12
}
504
505
Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,
506
                                uint8_t StOther, uint8_t Type,
507
98
                                bool CanOmitFromDynSym, BitcodeFile &F) {
508
98
  Symbol *S;
509
98
  bool WasInserted;
510
98
  std::tie(S, WasInserted) =
511
98
      insert(Name, Type, getVisibility(StOther), CanOmitFromDynSym, &F);
512
98
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
513
98
                                    /*IsAbs*/ false, /*Value*/ 0, Name);
514
98
  if (Cmp > 0)
515
97
    replaceSymbol<Defined>(S, &F, Name, Binding, StOther, Type, 0, 0, nullptr);
516
1
  else if (Cmp == 0)
517
1
    reportDuplicate(S, &F);
518
98
  return S;
519
98
}
520
521
148k
Symbol *SymbolTable::find(StringRef Name) {
522
148k
  auto It = SymMap.find(CachedHashStringRef(Name));
523
148k
  if (It == SymMap.end())
524
146k
    return nullptr;
525
1.26k
  if (It->second == -1)
526
0
    return nullptr;
527
1.26k
  return SymVector[It->second];
528
1.26k
}
529
530
template <class ELFT>
531
Symbol *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F,
532
69
                                    const object::Archive::Symbol Sym) {
533
69
  Symbol *S;
534
69
  bool WasInserted;
535
69
  std::tie(S, WasInserted) = insert(Name);
536
69
  if (WasInserted) {
537
27
    replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
538
27
    return S;
539
27
  }
540
42
  if (!S->isUndefined())
541
16
    return S;
542
26
543
26
  // An undefined weak will not fetch archive members. See comment on Lazy in
544
26
  // Symbols.h for the details.
545
26
  if (S->isWeak()) {
546
6
    replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
547
6
    S->Binding = STB_WEAK;
548
6
    return S;
549
6
  }
550
20
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
551
20
  if (!MBInfo.first.getBuffer().empty())
552
20
    addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
553
20
  return S;
554
20
}
lld::elf::Symbol* lld::elf::SymbolTable::addLazyArchive<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef, lld::elf::ArchiveFile&, llvm::object::Archive::Symbol)
Line
Count
Source
532
1
                                    const object::Archive::Symbol Sym) {
533
1
  Symbol *S;
534
1
  bool WasInserted;
535
1
  std::tie(S, WasInserted) = insert(Name);
536
1
  if (WasInserted) {
537
0
    replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
538
0
    return S;
539
0
  }
540
1
  if (!S->isUndefined())
541
0
    return S;
542
1
543
1
  // An undefined weak will not fetch archive members. See comment on Lazy in
544
1
  // Symbols.h for the details.
545
1
  if (S->isWeak()) {
546
1
    replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
547
1
    S->Binding = STB_WEAK;
548
1
    return S;
549
1
  }
550
0
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
551
0
  if (!MBInfo.first.getBuffer().empty())
552
0
    addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
553
0
  return S;
554
0
}
Unexecuted instantiation: lld::elf::Symbol* lld::elf::SymbolTable::addLazyArchive<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, lld::elf::ArchiveFile&, llvm::object::Archive::Symbol)
lld::elf::Symbol* lld::elf::SymbolTable::addLazyArchive<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, lld::elf::ArchiveFile&, llvm::object::Archive::Symbol)
Line
Count
Source
532
67
                                    const object::Archive::Symbol Sym) {
533
67
  Symbol *S;
534
67
  bool WasInserted;
535
67
  std::tie(S, WasInserted) = insert(Name);
536
67
  if (WasInserted) {
537
27
    replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
538
27
    return S;
539
27
  }
540
40
  if (!S->isUndefined())
541
16
    return S;
542
24
543
24
  // An undefined weak will not fetch archive members. See comment on Lazy in
544
24
  // Symbols.h for the details.
545
24
  if (S->isWeak()) {
546
4
    replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
547
4
    S->Binding = STB_WEAK;
548
4
    return S;
549
4
  }
550
20
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
551
20
  if (!MBInfo.first.getBuffer().empty())
552
20
    addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
553
20
  return S;
554
20
}
lld::elf::Symbol* lld::elf::SymbolTable::addLazyArchive<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef, lld::elf::ArchiveFile&, llvm::object::Archive::Symbol)
Line
Count
Source
532
1
                                    const object::Archive::Symbol Sym) {
533
1
  Symbol *S;
534
1
  bool WasInserted;
535
1
  std::tie(S, WasInserted) = insert(Name);
536
1
  if (WasInserted) {
537
0
    replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
538
0
    return S;
539
0
  }
540
1
  if (!S->isUndefined())
541
0
    return S;
542
1
543
1
  // An undefined weak will not fetch archive members. See comment on Lazy in
544
1
  // Symbols.h for the details.
545
1
  if (S->isWeak()) {
546
1
    replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
547
1
    S->Binding = STB_WEAK;
548
1
    return S;
549
1
  }
550
0
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
551
0
  if (!MBInfo.first.getBuffer().empty())
552
0
    addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
553
0
  return S;
554
0
}
555
556
template <class ELFT>
557
11
void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
558
11
  Symbol *S;
559
11
  bool WasInserted;
560
11
  std::tie(S, WasInserted) = insert(Name);
561
11
  if (WasInserted) {
562
5
    replaceSymbol<LazyObject>(S, Obj, Name, Symbol::UnknownType);
563
5
    return;
564
5
  }
565
6
  if (!S->isUndefined())
566
0
    return;
567
6
568
6
  // See comment for addLazyArchive above.
569
6
  if (S->isWeak())
570
0
    replaceSymbol<LazyObject>(S, Obj, Name, S->Type);
571
6
  else if (InputFile *F = Obj.fetch())
572
5
    addFile<ELFT>(F);
573
6
}
Unexecuted instantiation: void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef, lld::elf::LazyObjFile&)
Unexecuted instantiation: void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, lld::elf::LazyObjFile&)
void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, lld::elf::LazyObjFile&)
Line
Count
Source
557
11
void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
558
11
  Symbol *S;
559
11
  bool WasInserted;
560
11
  std::tie(S, WasInserted) = insert(Name);
561
11
  if (WasInserted) {
562
5
    replaceSymbol<LazyObject>(S, Obj, Name, Symbol::UnknownType);
563
5
    return;
564
5
  }
565
6
  if (!S->isUndefined())
566
0
    return;
567
6
568
6
  // See comment for addLazyArchive above.
569
6
  if (S->isWeak())
570
0
    replaceSymbol<LazyObject>(S, Obj, Name, S->Type);
571
6
  else if (InputFile *F = Obj.fetch())
572
5
    addFile<ELFT>(F);
573
6
}
Unexecuted instantiation: void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef, lld::elf::LazyObjFile&)
574
575
// If we already saw this symbol, force loading its file.
576
968
template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
577
968
  if (Symbol *B = find(Name)) {
578
525
    // Mark the symbol not to be eliminated by LTO
579
525
    // even if it is a bitcode symbol.
580
525
    B->IsUsedInRegularObj = true;
581
525
    if (auto *L = dyn_cast<Lazy>(B))
582
5
      if (InputFile *File = L->fetch())
583
5
        addFile<ELFT>(File);
584
525
  }
585
968
}
void lld::elf::SymbolTable::fetchIfLazy<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef)
Line
Count
Source
576
123
template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
577
123
  if (Symbol *B = find(Name)) {
578
70
    // Mark the symbol not to be eliminated by LTO
579
70
    // even if it is a bitcode symbol.
580
70
    B->IsUsedInRegularObj = true;
581
70
    if (auto *L = dyn_cast<Lazy>(B))
582
0
      if (InputFile *File = L->fetch())
583
0
        addFile<ELFT>(File);
584
70
  }
585
123
}
void lld::elf::SymbolTable::fetchIfLazy<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef)
Line
Count
Source
576
54
template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
577
54
  if (Symbol *B = find(Name)) {
578
30
    // Mark the symbol not to be eliminated by LTO
579
30
    // even if it is a bitcode symbol.
580
30
    B->IsUsedInRegularObj = true;
581
30
    if (auto *L = dyn_cast<Lazy>(B))
582
0
      if (InputFile *File = L->fetch())
583
0
        addFile<ELFT>(File);
584
30
  }
585
54
}
void lld::elf::SymbolTable::fetchIfLazy<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef)
Line
Count
Source
576
761
template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
577
761
  if (Symbol *B = find(Name)) {
578
408
    // Mark the symbol not to be eliminated by LTO
579
408
    // even if it is a bitcode symbol.
580
408
    B->IsUsedInRegularObj = true;
581
408
    if (auto *L = dyn_cast<Lazy>(B))
582
5
      if (InputFile *File = L->fetch())
583
5
        addFile<ELFT>(File);
584
408
  }
585
761
}
void lld::elf::SymbolTable::fetchIfLazy<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef)
Line
Count
Source
576
30
template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
577
30
  if (Symbol *B = find(Name)) {
578
17
    // Mark the symbol not to be eliminated by LTO
579
17
    // even if it is a bitcode symbol.
580
17
    B->IsUsedInRegularObj = true;
581
17
    if (auto *L = dyn_cast<Lazy>(B))
582
0
      if (InputFile *File = L->fetch())
583
0
        addFile<ELFT>(File);
584
17
  }
585
30
}
586
587
// This function takes care of the case in which shared libraries depend on
588
// the user program (not the other way, which is usual). Shared libraries
589
// may have undefined symbols, expecting that the user program provides
590
// the definitions for them. An example is BSD's __progname symbol.
591
// We need to put such symbols to the main program's .dynsym so that
592
// shared libraries can find them.
593
// Except this, we ignore undefined symbols in DSOs.
594
582
template <class ELFT> void SymbolTable::scanShlibUndefined() {
595
582
  for (InputFile *F : SharedFiles) {
596
119
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
597
8
      Symbol *Sym = find(U);
598
8
      if (!Sym || 
!Sym->isDefined()5
)
599
6
        continue;
600
2
      Sym->ExportDynamic = true;
601
2
    }
602
119
  }
603
582
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
594
74
template <class ELFT> void SymbolTable::scanShlibUndefined() {
595
74
  for (InputFile *F : SharedFiles) {
596
29
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
597
0
      Symbol *Sym = find(U);
598
0
      if (!Sym || !Sym->isDefined())
599
0
        continue;
600
0
      Sym->ExportDynamic = true;
601
0
    }
602
29
  }
603
74
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
594
30
template <class ELFT> void SymbolTable::scanShlibUndefined() {
595
30
  for (InputFile *F : SharedFiles) {
596
6
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
597
0
      Symbol *Sym = find(U);
598
0
      if (!Sym || !Sym->isDefined())
599
0
        continue;
600
0
      Sym->ExportDynamic = true;
601
0
    }
602
6
  }
603
30
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
594
463
template <class ELFT> void SymbolTable::scanShlibUndefined() {
595
463
  for (InputFile *F : SharedFiles) {
596
81
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
597
8
      Symbol *Sym = find(U);
598
8
      if (!Sym || 
!Sym->isDefined()5
)
599
6
        continue;
600
2
      Sym->ExportDynamic = true;
601
2
    }
602
81
  }
603
463
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
594
15
template <class ELFT> void SymbolTable::scanShlibUndefined() {
595
15
  for (InputFile *F : SharedFiles) {
596
3
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
597
0
      Symbol *Sym = find(U);
598
0
      if (!Sym || !Sym->isDefined())
599
0
        continue;
600
0
      Sym->ExportDynamic = true;
601
0
    }
602
3
  }
603
15
}
604
605
// Initialize DemangledSyms with a map from demangled symbols to symbol
606
// objects. Used to handle "extern C++" directive in version scripts.
607
//
608
// The map will contain all demangled symbols. That can be very large,
609
// and in LLD we generally want to avoid do anything for each symbol.
610
// Then, why are we doing this? Here's why.
611
//
612
// Users can use "extern C++ {}" directive to match against demangled
613
// C++ symbols. For example, you can write a pattern such as
614
// "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
615
// other than trying to match a pattern against all demangled symbols.
616
// So, if "extern C++" feature is used, we need to demangle all known
617
// symbols.
618
11
StringMap<std::vector<Symbol *>> &SymbolTable::getDemangledSyms() {
619
11
  if (!DemangledSyms) {
620
9
    DemangledSyms.emplace();
621
19
    for (Symbol *Sym : SymVector) {
622
19
      if (!Sym->isDefined())
623
0
        continue;
624
19
      if (Optional<std::string> S = demangleItanium(Sym->getName()))
625
19
        (*DemangledSyms)[*S].push_back(Sym);
626
0
      else
627
0
        (*DemangledSyms)[Sym->getName()].push_back(Sym);
628
19
    }
629
9
  }
630
11
  return *DemangledSyms;
631
11
}
632
633
43
std::vector<Symbol *> SymbolTable::findByVersion(SymbolVersion Ver) {
634
43
  if (Ver.IsExternCpp)
635
3
    return getDemangledSyms().lookup(Ver.Name);
636
40
  if (Symbol *B = find(Ver.Name))
637
34
    if (B->isDefined())
638
34
      return {B};
639
6
  return {};
640
6
}
641
642
15
std::vector<Symbol *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
643
15
  std::vector<Symbol *> Res;
644
15
  StringMatcher M(Ver.Name);
645
15
646
15
  if (Ver.IsExternCpp) {
647
8
    for (auto &P : getDemangledSyms())
648
18
      if (M.match(P.first()))
649
7
        Res.insert(Res.end(), P.second.begin(), P.second.end());
650
8
    return Res;
651
8
  }
652
7
653
7
  for (Symbol *Sym : SymVector)
654
23
    if (Sym->isDefined() && M.match(Sym->getName()))
655
18
      Res.push_back(Sym);
656
7
  return Res;
657
7
}
658
659
// If there's only one anonymous version definition in a version
660
// script file, the script does not actually define any symbol version,
661
// but just specifies symbols visibilities.
662
941
void SymbolTable::handleAnonymousVersion() {
663
941
  for (SymbolVersion &Ver : Config->VersionScriptGlobals)
664
7
    assignExactVersion(Ver, VER_NDX_GLOBAL, "global");
665
941
  for (SymbolVersion &Ver : Config->VersionScriptGlobals)
666
7
    assignWildcardVersion(Ver, VER_NDX_GLOBAL);
667
941
  for (SymbolVersion &Ver : Config->VersionScriptLocals)
668
3
    assignExactVersion(Ver, VER_NDX_LOCAL, "local");
669
941
  for (SymbolVersion &Ver : Config->VersionScriptLocals)
670
3
    assignWildcardVersion(Ver, VER_NDX_LOCAL);
671
941
}
672
673
// Handles -dynamic-list.
674
941
void SymbolTable::handleDynamicList() {
675
941
  for (SymbolVersion &Ver : Config->DynamicList) {
676
11
    std::vector<Symbol *> Syms;
677
11
    if (Ver.HasWildcard)
678
1
      Syms = findAllByVersion(Ver);
679
10
    else
680
10
      Syms = findByVersion(Ver);
681
11
682
11
    for (Symbol *B : Syms) {
683
11
      if (!Config->Shared)
684
11
        B->ExportDynamic = true;
685
0
      else if (B->includeInDynsym())
686
0
        B->IsPreemptible = true;
687
11
    }
688
11
  }
689
941
}
690
691
// Set symbol versions to symbols. This function handles patterns
692
// containing no wildcard characters.
693
void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
694
47
                                     StringRef VersionName) {
695
47
  if (Ver.HasWildcard)
696
14
    return;
697
33
698
33
  // Get a list of symbols which we need to assign the version to.
699
33
  std::vector<Symbol *> Syms = findByVersion(Ver);
700
33
  if (Syms.empty()) {
701
7
    if (Config->NoUndefinedVersion)
702
1
      error("version script assignment of '" + VersionName + "' to symbol '" +
703
1
            Ver.Name + "' failed: symbol not defined");
704
7
    return;
705
7
  }
706
26
707
26
  // Assign the version.
708
26
  for (Symbol *Sym : Syms) {
709
26
    // Skip symbols containing version info because symbol versions
710
26
    // specified by symbol names take precedence over version scripts.
711
26
    // See parseSymbolVersion().
712
26
    if (Sym->getName().contains('@'))
713
4
      continue;
714
22
715
22
    if (Sym->InVersionScript)
716
1
      warn("duplicate symbol '" + Ver.Name + "' in version script");
717
22
    Sym->VersionId = VersionId;
718
22
    Sym->InVersionScript = true;
719
22
  }
720
26
}
721
722
47
void SymbolTable::assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId) {
723
47
  if (!Ver.HasWildcard)
724
33
    return;
725
14
726
14
  // Exact matching takes precendence over fuzzy matching,
727
14
  // so we set a version to a symbol only if no version has been assigned
728
14
  // to the symbol. This behavior is compatible with GNU.
729
14
  for (Symbol *B : findAllByVersion(Ver))
730
23
    if (B->VersionId == Config->DefaultSymbolVersion)
731
19
      B->VersionId = VersionId;
732
14
}
733
734
// This function processes version scripts by updating VersionId
735
// member of symbols.
736
941
void SymbolTable::scanVersionScript() {
737
941
  // Handle edge cases first.
738
941
  handleAnonymousVersion();
739
941
  handleDynamicList();
740
941
741
941
  // Now we have version definitions, so we need to set version ids to symbols.
742
941
  // Each version definition has a glob pattern, and all symbols that match
743
941
  // with the pattern get that version.
744
941
745
941
  // First, we assign versions to exact matching symbols,
746
941
  // i.e. version definitions not containing any glob meta-characters.
747
941
  for (VersionDefinition &V : Config->VersionDefinitions)
748
40
    for (SymbolVersion &Ver : V.Globals)
749
37
      assignExactVersion(Ver, V.Id, V.Name);
750
941
751
941
  // Next, we assign versions to fuzzy matching symbols,
752
941
  // i.e. version definitions containing glob meta-characters.
753
941
  // Note that because the last match takes precedence over previous matches,
754
941
  // we iterate over the definitions in the reverse order.
755
941
  for (VersionDefinition &V : llvm::reverse(Config->VersionDefinitions))
756
40
    for (SymbolVersion &Ver : V.Globals)
757
37
      assignWildcardVersion(Ver, V.Id);
758
941
759
941
  // Symbol themselves might know their versions because symbols
760
941
  // can contain versions in the form of <name>@<version>.
761
941
  // Let them parse and update their names to exclude version suffix.
762
941
  for (Symbol *Sym : SymVector)
763
12.3k
    Sym->parseSymbolVersion();
764
941
}
765
766
template void SymbolTable::addFile<ELF32LE>(InputFile *);
767
template void SymbolTable::addFile<ELF32BE>(InputFile *);
768
template void SymbolTable::addFile<ELF64LE>(InputFile *);
769
template void SymbolTable::addFile<ELF64BE>(InputFile *);
770
771
template void SymbolTable::addSymbolWrap<ELF32LE>(StringRef);
772
template void SymbolTable::addSymbolWrap<ELF32BE>(StringRef);
773
template void SymbolTable::addSymbolWrap<ELF64LE>(StringRef);
774
template void SymbolTable::addSymbolWrap<ELF64BE>(StringRef);
775
776
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef);
777
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef);
778
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef);
779
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef);
780
781
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef, uint8_t, uint8_t,
782
                                                    uint8_t, bool, InputFile *);
783
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef, uint8_t, uint8_t,
784
                                                    uint8_t, bool, InputFile *);
785
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef, uint8_t, uint8_t,
786
                                                    uint8_t, bool, InputFile *);
787
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef, uint8_t, uint8_t,
788
                                                    uint8_t, bool, InputFile *);
789
790
template void SymbolTable::addCombinedLTOObject<ELF32LE>();
791
template void SymbolTable::addCombinedLTOObject<ELF32BE>();
792
template void SymbolTable::addCombinedLTOObject<ELF64LE>();
793
template void SymbolTable::addCombinedLTOObject<ELF64BE>();
794
795
template Symbol *
796
SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile &,
797
                                     const object::Archive::Symbol);
798
template Symbol *
799
SymbolTable::addLazyArchive<ELF32BE>(StringRef, ArchiveFile &,
800
                                     const object::Archive::Symbol);
801
template Symbol *
802
SymbolTable::addLazyArchive<ELF64LE>(StringRef, ArchiveFile &,
803
                                     const object::Archive::Symbol);
804
template Symbol *
805
SymbolTable::addLazyArchive<ELF64BE>(StringRef, ArchiveFile &,
806
                                     const object::Archive::Symbol);
807
808
template void SymbolTable::addLazyObject<ELF32LE>(StringRef, LazyObjFile &);
809
template void SymbolTable::addLazyObject<ELF32BE>(StringRef, LazyObjFile &);
810
template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
811
template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
812
813
template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> &,
814
                                              const typename ELF32LE::Sym &,
815
                                              uint32_t Alignment, uint32_t);
816
template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> &,
817
                                              const typename ELF32BE::Sym &,
818
                                              uint32_t Alignment, uint32_t);
819
template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> &,
820
                                              const typename ELF64LE::Sym &,
821
                                              uint32_t Alignment, uint32_t);
822
template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
823
                                              const typename ELF64BE::Sym &,
824
                                              uint32_t Alignment, uint32_t);
825
826
template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
827
template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
828
template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
829
template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
830
831
template void SymbolTable::scanShlibUndefined<ELF32LE>();
832
template void SymbolTable::scanShlibUndefined<ELF32BE>();
833
template void SymbolTable::scanShlibUndefined<ELF64LE>();
834
template void SymbolTable::scanShlibUndefined<ELF64BE>();