Coverage Report

Created: 2017-10-03 07:32

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