Coverage Report

Created: 2017-09-19 22:28

/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.29k
template <class ELFT> static bool isCompatible(InputFile *F) {
38
2.29k
  if (
!isa<ELFFileBase<ELFT>>(F) && 2.29k
!isa<BitcodeFile>(F)249
)
39
93
    return true;
40
2.19k
41
2.19k
  
if (2.19k
F->EKind == Config->EKind && 2.19k
F->EMachine == Config->EMachine2.18k
) {
42
2.18k
    if (Config->EMachine != EM_MIPS)
43
1.98k
      return true;
44
200
    
if (200
isMipsN32Abi(F) == Config->MipsN32Abi200
)
45
198
      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.29k
  return false;
53
2.29k
}
SymbolTable.cpp:bool isCompatible<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::InputFile*)
Line
Count
Source
37
274
template <class ELFT> static bool isCompatible(InputFile *F) {
38
274
  if (
!isa<ELFFileBase<ELFT>>(F) && 274
!isa<BitcodeFile>(F)3
)
39
2
    return true;
40
272
41
272
  
if (272
F->EKind == Config->EKind && 272
F->EMachine == Config->EMachine265
) {
42
265
    if (Config->EMachine != EM_MIPS)
43
248
      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
274
  return false;
53
274
}
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.81k
template <class ELFT> static bool isCompatible(InputFile *F) {
38
1.81k
  if (
!isa<ELFFileBase<ELFT>>(F) && 1.81k
!isa<BitcodeFile>(F)246
)
39
91
    return true;
40
1.72k
41
1.72k
  
if (1.72k
F->EKind == Config->EKind && 1.72k
F->EMachine == Config->EMachine1.71k
) {
42
1.71k
    if (Config->EMachine != EM_MIPS)
43
1.71k
      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.81k
  return false;
53
1.81k
}
SymbolTable.cpp:bool isCompatible<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::InputFile*)
Line
Count
Source
37
144
template <class ELFT> static bool isCompatible(InputFile *F) {
38
144
  if (
!isa<ELFFileBase<ELFT>>(F) && 144
!isa<BitcodeFile>(F)0
)
39
0
    return true;
40
144
41
144
  
if (144
F->EKind == Config->EKind && 144
F->EMachine == Config->EMachine144
) {
42
144
    if (Config->EMachine != EM_MIPS)
43
2
      return true;
44
142
    
if (142
isMipsN32Abi(F) == Config->MipsN32Abi142
)
45
140
      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
144
  return false;
53
144
}
54
55
// Add symbols in File to the symbol table.
56
2.29k
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
57
2.29k
  if (
!Config->FirstElf && 2.29k
isa<ELFFileBase<ELFT>>(File)1.70k
)
58
1.52k
    Config->FirstElf = File;
59
2.29k
60
2.29k
  if (!isCompatible<ELFT>(File))
61
15
    return;
62
2.27k
63
2.27k
  // Binary file
64
2.27k
  
if (auto *2.27k
F2.27k
= dyn_cast<BinaryFile>(File)) {
65
5
    BinaryFiles.push_back(F);
66
5
    F->parse<ELFT>();
67
5
    return;
68
5
  }
69
2.27k
70
2.27k
  // .a file
71
2.27k
  
if (auto *2.27k
F2.27k
= dyn_cast<ArchiveFile>(File)) {
72
69
    F->parse<ELFT>();
73
69
    return;
74
69
  }
75
2.20k
76
2.20k
  // Lazy object file
77
2.20k
  
if (auto *2.20k
F2.20k
= dyn_cast<LazyObjFile>(File)) {
78
19
    F->parse<ELFT>();
79
19
    return;
80
19
  }
81
2.18k
82
2.18k
  
if (2.18k
Config->Trace2.18k
)
83
6
    message(toString(File));
84
2.18k
85
2.18k
  // .so file
86
2.18k
  if (auto *
F2.18k
= 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.96k
96
1.96k
  // LLVM bitcode file
97
1.96k
  
if (auto *1.96k
F1.96k
= dyn_cast<BitcodeFile>(File)) {
98
155
    BitcodeFiles.push_back(F);
99
155
    F->parse<ELFT>(ComdatGroups);
100
155
    return;
101
155
  }
102
1.80k
103
1.80k
  // Regular object file
104
1.80k
  ObjectFiles.push_back(File);
105
1.80k
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
106
1.80k
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::InputFile*)
Line
Count
Source
56
274
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
57
274
  if (
!Config->FirstElf && 274
isa<ELFFileBase<ELFT>>(File)200
)
58
198
    Config->FirstElf = File;
59
274
60
274
  if (!isCompatible<ELFT>(File))
61
7
    return;
62
267
63
267
  // Binary file
64
267
  
if (auto *267
F267
= dyn_cast<BinaryFile>(File)) {
65
0
    BinaryFiles.push_back(F);
66
0
    F->parse<ELFT>();
67
0
    return;
68
0
  }
69
267
70
267
  // .a file
71
267
  
if (auto *267
F267
= dyn_cast<ArchiveFile>(File)) {
72
2
    F->parse<ELFT>();
73
2
    return;
74
2
  }
75
265
76
265
  // Lazy object file
77
265
  
if (auto *265
F265
= dyn_cast<LazyObjFile>(File)) {
78
0
    F->parse<ELFT>();
79
0
    return;
80
0
  }
81
265
82
265
  
if (265
Config->Trace265
)
83
0
    message(toString(File));
84
265
85
265
  // .so file
86
265
  if (auto *
F265
= 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
222
96
222
  // LLVM bitcode file
97
222
  
if (auto *222
F222
= dyn_cast<BitcodeFile>(File)) {
98
0
    BitcodeFiles.push_back(F);
99
0
    F->parse<ELFT>(ComdatGroups);
100
0
    return;
101
0
  }
102
222
103
222
  // Regular object file
104
222
  ObjectFiles.push_back(File);
105
222
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
106
222
}
void lld::elf::SymbolTable::addFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >(lld::elf::InputFile*)
Line
Count
Source
56
1.81k
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
57
1.81k
  if (
!Config->FirstElf && 1.81k
isa<ELFFileBase<ELFT>>(File)1.35k
)
58
1.18k
    Config->FirstElf = File;
59
1.81k
60
1.81k
  if (!isCompatible<ELFT>(File))
61
3
    return;
62
1.80k
63
1.80k
  // Binary file
64
1.80k
  
if (auto *1.80k
F1.80k
= dyn_cast<BinaryFile>(File)) {
65
5
    BinaryFiles.push_back(F);
66
5
    F->parse<ELFT>();
67
5
    return;
68
5
  }
69
1.80k
70
1.80k
  // .a file
71
1.80k
  
if (auto *1.80k
F1.80k
= dyn_cast<ArchiveFile>(File)) {
72
67
    F->parse<ELFT>();
73
67
    return;
74
67
  }
75
1.73k
76
1.73k
  // Lazy object file
77
1.73k
  
if (auto *1.73k
F1.73k
= dyn_cast<LazyObjFile>(File)) {
78
19
    F->parse<ELFT>();
79
19
    return;
80
19
  }
81
1.71k
82
1.71k
  
if (1.71k
Config->Trace1.71k
)
83
6
    message(toString(File));
84
1.71k
85
1.71k
  // .so file
86
1.71k
  if (auto *
F1.71k
= 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.56k
96
1.56k
  // LLVM bitcode file
97
1.56k
  
if (auto *1.56k
F1.56k
= dyn_cast<BitcodeFile>(File)) {
98
155
    BitcodeFiles.push_back(F);
99
155
    F->parse<ELFT>(ComdatGroups);
100
155
    return;
101
155
  }
102
1.41k
103
1.41k
  // Regular object file
104
1.41k
  ObjectFiles.push_back(File);
105
1.41k
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
106
1.41k
}
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
144
template <class ELFT> void SymbolTable::addFile(InputFile *File) {
57
144
  if (
!Config->FirstElf && 144
isa<ELFFileBase<ELFT>>(File)96
)
58
96
    Config->FirstElf = File;
59
144
60
144
  if (!isCompatible<ELFT>(File))
61
2
    return;
62
142
63
142
  // Binary file
64
142
  
if (auto *142
F142
= dyn_cast<BinaryFile>(File)) {
65
0
    BinaryFiles.push_back(F);
66
0
    F->parse<ELFT>();
67
0
    return;
68
0
  }
69
142
70
142
  // .a file
71
142
  
if (auto *142
F142
= dyn_cast<ArchiveFile>(File)) {
72
0
    F->parse<ELFT>();
73
0
    return;
74
0
  }
75
142
76
142
  // Lazy object file
77
142
  
if (auto *142
F142
= dyn_cast<LazyObjFile>(File)) {
78
0
    F->parse<ELFT>();
79
0
    return;
80
0
  }
81
142
82
142
  
if (142
Config->Trace142
)
83
0
    message(toString(File));
84
142
85
142
  // .so file
86
142
  if (auto *
F142
= 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
125
96
125
  // LLVM bitcode file
97
125
  
if (auto *125
F125
= dyn_cast<BitcodeFile>(File)) {
98
0
    BitcodeFiles.push_back(F);
99
0
    F->parse<ELFT>(ComdatGroups);
100
0
    return;
101
0
  }
102
125
103
125
  // Regular object file
104
125
  ObjectFiles.push_back(File);
105
125
  cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
106
125
}
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.59k
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
116
1.59k
  if (BitcodeFiles.empty())
117
1.48k
    return;
118
110
119
110
  // Compile bitcode files and replace bitcode symbols.
120
110
  LTO.reset(new BitcodeCompiler);
121
110
  for (BitcodeFile *F : BitcodeFiles)
122
153
    LTO->add(*F);
123
110
124
125
  for (InputFile *File : LTO->compile()) {
125
125
    DenseSet<CachedHashStringRef> DummyGroups;
126
125
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
127
125
    ObjectFiles.push_back(File);
128
125
  }
129
1.59k
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
115
191
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
116
191
  if (BitcodeFiles.empty())
117
191
    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
191
}
void lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
115
94
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
116
94
  if (BitcodeFiles.empty())
117
94
    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
94
}
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.26k
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
116
1.26k
  if (BitcodeFiles.empty())
117
1.15k
    return;
118
110
119
110
  // Compile bitcode files and replace bitcode symbols.
120
110
  LTO.reset(new BitcodeCompiler);
121
110
  for (BitcodeFile *F : BitcodeFiles)
122
153
    LTO->add(*F);
123
110
124
125
  for (InputFile *File : LTO->compile()) {
125
125
    DenseSet<CachedHashStringRef> DummyGroups;
126
125
    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
127
125
    ObjectFiles.push_back(File);
128
125
  }
129
1.26k
}
130
131
template <class ELFT>
132
DefinedRegular *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
133
139
                                         uint8_t Binding) {
134
139
  Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
135
139
                                 nullptr, nullptr);
136
139
  return cast<DefinedRegular>(Sym->body());
137
139
}
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
}
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
91
                                         uint8_t Binding) {
134
91
  Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
135
91
                                 nullptr, nullptr);
136
91
  return cast<DefinedRegular>(Sym->body());
137
91
}
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
}
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
725
DefinedRegular *SymbolTable::addIgnored(StringRef Name, uint8_t Visibility) {
143
725
  SymbolBody *S = find(Name);
144
725
  if (
!S || 725
S->isInCurrentDSO()9
)
145
721
    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
}
lld::elf::DefinedRegular* lld::elf::SymbolTable::addIgnored<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, unsigned char)
Line
Count
Source
142
595
DefinedRegular *SymbolTable::addIgnored(StringRef Name, uint8_t Visibility) {
143
595
  SymbolBody *S = find(Name);
144
595
  if (
!S || 595
S->isInCurrentDSO()5
)
145
591
    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, 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, 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
}
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
168
7
  Config->RenamedSymbols[Real] = {Sym, Real->Binding};
169
7
  Config->RenamedSymbols[Sym] = {Wrap, Sym->Binding};
170
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
168
7
  Config->RenamedSymbols[Real] = {Sym, Real->Binding};
169
7
  Config->RenamedSymbols[Sym] = {Wrap, Sym->Binding};
170
7
}
171
172
// Creates alias for symbol. Used to implement --defsym=ALIAS=SYM.
173
template <class ELFT>
174
6
void SymbolTable::addSymbolAlias(StringRef Alias, StringRef Name) {
175
6
  SymbolBody *B = find(Name);
176
6
  if (
!B6
) {
177
2
    error("-defsym: undefined symbol: " + Name);
178
2
    return;
179
2
  }
180
4
  Symbol *Sym = B->symbol();
181
4
  Symbol *AliasSym = addUndefined<ELFT>(Alias);
182
4
183
4
  // Tell LTO not to eliminate this symbol
184
4
  Sym->IsUsedInRegularObj = true;
185
4
  Config->RenamedSymbols[AliasSym] = {Sym, AliasSym->Binding};
186
4
}
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolAlias<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::StringRef, llvm::StringRef)
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolAlias<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, llvm::StringRef)
void lld::elf::SymbolTable::addSymbolAlias<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, llvm::StringRef)
Line
Count
Source
174
6
void SymbolTable::addSymbolAlias(StringRef Alias, StringRef Name) {
175
6
  SymbolBody *B = find(Name);
176
6
  if (
!B6
) {
177
2
    error("-defsym: undefined symbol: " + Name);
178
2
    return;
179
2
  }
180
4
  Symbol *Sym = B->symbol();
181
4
  Symbol *AliasSym = addUndefined<ELFT>(Alias);
182
4
183
4
  // Tell LTO not to eliminate this symbol
184
4
  Sym->IsUsedInRegularObj = true;
185
4
  Config->RenamedSymbols[AliasSym] = {Sym, AliasSym->Binding};
186
4
}
Unexecuted instantiation: void lld::elf::SymbolTable::addSymbolAlias<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::StringRef, llvm::StringRef)
187
188
// Apply symbol renames created by -wrap and -defsym. The renames are created
189
// before LTO in addSymbolWrap() and addSymbolAlias() to have a chance to inform
190
// LTO (if LTO is running) not to include these symbols in IPO. Now that the
191
// symbols are finalized, we can perform the replacement.
192
1.58k
void SymbolTable::applySymbolRenames() {
193
18
  for (auto &KV : Config->RenamedSymbols) {
194
18
    Symbol *Dst = KV.first;
195
18
    Symbol *Src = KV.second.Target;
196
18
    Dst->body()->copy(Src->body());
197
18
    Dst->File = Src->File;
198
18
    Dst->Binding = KV.second.OriginalBinding;
199
18
  }
200
1.58k
}
201
202
6.60k
static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
203
6.60k
  if (VA == STV_DEFAULT)
204
6.55k
    return VB;
205
47
  
if (47
VB == STV_DEFAULT47
)
206
27
    return VA;
207
20
  return std::min(VA, VB);
208
20
}
209
210
// Find an existing symbol or create and insert a new one.
211
6.76k
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
212
6.76k
  // <name>@@<version> means the symbol is the default version. In that
213
6.76k
  // case <name>@@<version> will be used to resolve references to <name>.
214
6.76k
  size_t Pos = Name.find("@@");
215
6.76k
  if (Pos != StringRef::npos)
216
8
    Name = Name.take_front(Pos);
217
6.76k
218
6.76k
  auto P = Symtab.insert(
219
6.76k
      {CachedHashStringRef(Name), SymIndex((int)SymVector.size(), false)});
220
6.76k
  SymIndex &V = P.first->second;
221
6.76k
  bool IsNew = P.second;
222
6.76k
223
6.76k
  if (
V.Idx == -16.76k
) {
224
28
    IsNew = true;
225
28
    V = SymIndex((int)SymVector.size(), true);
226
28
  }
227
6.76k
228
6.76k
  Symbol *Sym;
229
6.76k
  if (
IsNew6.76k
) {
230
4.68k
    Sym = make<Symbol>();
231
4.68k
    Sym->InVersionScript = false;
232
4.68k
    Sym->Binding = STB_WEAK;
233
4.68k
    Sym->Visibility = STV_DEFAULT;
234
4.68k
    Sym->IsUsedInRegularObj = false;
235
4.68k
    Sym->ExportDynamic = false;
236
4.68k
    Sym->Traced = V.Traced;
237
4.68k
    Sym->VersionId = Config->DefaultSymbolVersion;
238
4.68k
    SymVector.push_back(Sym);
239
6.76k
  } else {
240
2.08k
    Sym = SymVector[V.Idx];
241
2.08k
  }
242
6.76k
  return {Sym, IsNew};
243
6.76k
}
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.60k
                                              InputFile *File) {
251
4.41k
  bool IsUsedInRegularObj = !File || File->kind() == InputFile::ObjKind;
252
6.60k
  Symbol *S;
253
6.60k
  bool WasInserted;
254
6.60k
  std::tie(S, WasInserted) = insert(Name);
255
6.60k
256
6.60k
  // Merge in the new symbol's visibility.
257
6.60k
  S->Visibility = getMinVisibility(S->Visibility, Visibility);
258
6.60k
259
6.60k
  if (
!CanOmitFromDynSym && 6.60k
(Config->Shared || 6.03k
Config->ExportDynamic3.89k
))
260
2.30k
    S->ExportDynamic = true;
261
6.60k
262
6.60k
  if (IsUsedInRegularObj)
263
5.77k
    S->IsUsedInRegularObj = true;
264
6.60k
265
6.60k
  if (
!WasInserted && 6.60k
S->body()->Type != SymbolBody::UnknownType2.00k
&&
266
6.60k
      
((Type == STT_TLS) != S->body()->isTls())1.95k
) {
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.60k
272
6.60k
  return {S, WasInserted};
273
6.60k
}
274
275
974
template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
276
974
  return addUndefined<ELFT>(Name, /*IsLocal=*/false, STB_GLOBAL, STV_DEFAULT,
277
974
                            /*Type*/ 0,
278
974
                            /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
279
974
}
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)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
}
lld::elf::Symbol* lld::elf::SymbolTable::addUndefined<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef)
Line
Count
Source
275
769
template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
276
769
  return addUndefined<ELFT>(Name, /*IsLocal=*/false, STB_GLOBAL, STV_DEFAULT,
277
769
                            /*Type*/ 0,
278
769
                            /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
279
769
}
280
281
5.86k
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.94k
                                  bool CanOmitFromDynSym, InputFile *File) {
287
1.94k
  Symbol *S;
288
1.94k
  bool WasInserted;
289
1.94k
  uint8_t Visibility = getVisibility(StOther);
290
1.94k
  std::tie(S, WasInserted) =
291
1.94k
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
292
1.94k
  // An undefined symbol with non default visibility must be satisfied
293
1.94k
  // in the same DSO.
294
1.94k
  if (WasInserted ||
295
1.94k
      
(isa<SharedSymbol>(S->body()) && 1.10k
Visibility != STV_DEFAULT21
)) {
296
839
    S->Binding = Binding;
297
839
    replaceBody<Undefined>(S, File, Name, IsLocal, StOther, Type);
298
839
    return S;
299
839
  }
300
1.10k
  
if (1.10k
Binding != STB_WEAK1.10k
) {
301
1.09k
    SymbolBody *B = S->body();
302
1.09k
    if (!B->isInCurrentDSO())
303
81
      S->Binding = Binding;
304
1.09k
    if (auto *SS = dyn_cast<SharedSymbol>(B))
305
20
      SS->getFile<ELFT>()->IsUsed = true;
306
1.09k
  }
307
1.10k
  if (auto *
L1.10k
= 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.94k
  return S;
316
1.94k
}
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.50k
                                  bool CanOmitFromDynSym, InputFile *File) {
287
1.50k
  Symbol *S;
288
1.50k
  bool WasInserted;
289
1.50k
  uint8_t Visibility = getVisibility(StOther);
290
1.50k
  std::tie(S, WasInserted) =
291
1.50k
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
292
1.50k
  // An undefined symbol with non default visibility must be satisfied
293
1.50k
  // in the same DSO.
294
1.50k
  if (WasInserted ||
295
1.50k
      
(isa<SharedSymbol>(S->body()) && 859
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
858
  
if (858
Binding != STB_WEAK858
) {
301
847
    SymbolBody *B = S->body();
302
847
    if (!B->isInCurrentDSO())
303
66
      S->Binding = Binding;
304
847
    if (auto *SS = dyn_cast<SharedSymbol>(B))
305
9
      SS->getFile<ELFT>()->IsUsed = true;
306
847
  }
307
858
  if (auto *
L858
= 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.50k
  return S;
316
1.50k
}
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
136
                                  bool CanOmitFromDynSym, InputFile *File) {
287
136
  Symbol *S;
288
136
  bool WasInserted;
289
136
  uint8_t Visibility = getVisibility(StOther);
290
136
  std::tie(S, WasInserted) =
291
136
      insert(Name, Type, Visibility, CanOmitFromDynSym, File);
292
136
  // An undefined symbol with non default visibility must be satisfied
293
136
  // in the same DSO.
294
136
  if (WasInserted ||
295
136
      
(isa<SharedSymbol>(S->body()) && 67
Visibility != STV_DEFAULT0
)) {
296
69
    S->Binding = Binding;
297
69
    replaceBody<Undefined>(S, File, Name, IsLocal, StOther, Type);
298
69
    return S;
299
69
  }
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
136
  return S;
316
136
}
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.92k
                          StringRef Name) {
339
3.92k
  if (WasInserted)
340
3.33k
    return 1;
341
594
  SymbolBody *Body = S->body();
342
594
  if (!Body->isInCurrentDSO())
343
521
    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.80k
                                   StringRef Name) {
361
3.80k
  if (int 
Cmp3.80k
= compareDefined(S, WasInserted, Binding, Name)) {
362
3.78k
    if (Cmp > 0)
363
3.77k
      S->Binding = Binding;
364
3.78k
    return Cmp;
365
3.78k
  }
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
}
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)
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
}
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.61k
                                SectionBase *Section, InputFile *File) {
459
3.61k
  Symbol *S;
460
3.61k
  bool WasInserted;
461
3.61k
  std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
462
3.61k
                                    /*CanOmitFromDynSym*/ false, File);
463
3.61k
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
464
3.61k
                                    Value, Name);
465
3.61k
  if (Cmp > 0)
466
3.58k
    replaceBody<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther, Type,
467
3.58k
                                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.61k
  return S;
472
3.61k
}
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, 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.54k
                                SectionBase *Section, InputFile *File) {
459
2.54k
  Symbol *S;
460
2.54k
  bool WasInserted;
461
2.54k
  std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
462
2.54k
                                    /*CanOmitFromDynSym*/ false, File);
463
2.54k
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
464
2.54k
                                    Value, Name);
465
2.54k
  if (Cmp > 0)
466
2.51k
    replaceBody<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther, Type,
467
2.51k
                                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.54k
  return S;
472
2.54k
}
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
529
                                SectionBase *Section, InputFile *File) {
459
529
  Symbol *S;
460
529
  bool WasInserted;
461
529
  std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
462
529
                                    /*CanOmitFromDynSym*/ false, File);
463
529
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
464
529
                                    Value, Name);
465
529
  if (Cmp > 0)
466
529
    replaceBody<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther, Type,
467
529
                                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
529
  return S;
472
529
}
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
388
                                SectionBase *Section, InputFile *File) {
459
388
  Symbol *S;
460
388
  bool WasInserted;
461
388
  std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
462
388
                                    /*CanOmitFromDynSym*/ false, File);
463
388
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
464
388
                                    Value, Name);
465
388
  if (Cmp > 0)
466
388
    replaceBody<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther, Type,
467
388
                                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
388
  return S;
472
388
}
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)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
}
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
}
500
501
Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,
502
                                uint8_t StOther, uint8_t Type,
503
196
                                bool CanOmitFromDynSym, BitcodeFile *F) {
504
196
  Symbol *S;
505
196
  bool WasInserted;
506
196
  std::tie(S, WasInserted) =
507
196
      insert(Name, Type, getVisibility(StOther), CanOmitFromDynSym, F);
508
196
  int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
509
196
                                    /*IsAbs*/ false, /*Value*/ 0, Name);
510
196
  if (Cmp > 0)
511
191
    replaceBody<DefinedRegular>(S, F, Name, /*IsLocal=*/false, StOther, Type, 0,
512
191
                                0, nullptr);
513
5
  else 
if (5
Cmp == 05
)
514
1
    reportDuplicate(S->body(), F);
515
196
  return S;
516
196
}
517
518
421k
SymbolBody *SymbolTable::find(StringRef Name) {
519
421k
  auto It = Symtab.find(CachedHashStringRef(Name));
520
421k
  if (It == Symtab.end())
521
419k
    return nullptr;
522
2.18k
  SymIndex V = It->second;
523
2.18k
  if (V.Idx == -1)
524
0
    return nullptr;
525
2.18k
  return SymVector[V.Idx]->body();
526
2.18k
}
527
528
template <class ELFT>
529
Symbol *SymbolTable::addLazyArchive(ArchiveFile *F,
530
137
                                    const object::Archive::Symbol Sym) {
531
137
  Symbol *S;
532
137
  bool WasInserted;
533
137
  StringRef Name = Sym.getName();
534
137
  std::tie(S, WasInserted) = insert(Name);
535
137
  if (
WasInserted137
) {
536
69
    replaceBody<LazyArchive>(S, F, Sym, SymbolBody::UnknownType);
537
69
    return S;
538
69
  }
539
68
  
if (68
!S->body()->isUndefined()68
)
540
23
    return S;
541
45
542
45
  // Weak undefined symbols should not fetch members from archives. If we were
543
45
  // to keep old symbol we would not know that an archive member was available
544
45
  // if a strong undefined symbol shows up afterwards in the link. If a strong
545
45
  // undefined symbol never shows up, this lazy symbol will get to the end of
546
45
  // the link and must be treated as the weak undefined one. We already marked
547
45
  // this symbol as used when we added it to the symbol table, but we also need
548
45
  // to preserve its type. FIXME: Move the Type field to Symbol.
549
45
  
if (45
S->isWeak()45
) {
550
10
    replaceBody<LazyArchive>(S, F, Sym, S->body()->Type);
551
10
    return S;
552
10
  }
553
35
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
554
35
  if (!MBInfo.first.getBuffer().empty())
555
35
    addFile<ELFT>(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
556
137
  return S;
557
137
}
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
530
3
                                    const object::Archive::Symbol Sym) {
531
3
  Symbol *S;
532
3
  bool WasInserted;
533
3
  StringRef Name = Sym.getName();
534
3
  std::tie(S, WasInserted) = insert(Name);
535
3
  if (
WasInserted3
) {
536
3
    replaceBody<LazyArchive>(S, F, Sym, SymbolBody::UnknownType);
537
3
    return S;
538
3
  }
539
0
  
if (0
!S->body()->isUndefined()0
)
540
0
    return S;
541
0
542
0
  // Weak undefined symbols should not fetch members from archives. If we were
543
0
  // to keep old symbol we would not know that an archive member was available
544
0
  // if a strong undefined symbol shows up afterwards in the link. If a strong
545
0
  // undefined symbol never shows up, this lazy symbol will get to the end of
546
0
  // the link and must be treated as the weak undefined one. We already marked
547
0
  // this symbol as used when we added it to the symbol table, but we also need
548
0
  // to preserve its type. FIXME: Move the Type field to Symbol.
549
0
  
if (0
S->isWeak()0
) {
550
0
    replaceBody<LazyArchive>(S, F, Sym, S->body()->Type);
551
0
    return S;
552
0
  }
553
0
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
554
0
  if (!MBInfo.first.getBuffer().empty())
555
0
    addFile<ELFT>(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
556
3
  return S;
557
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
530
134
                                    const object::Archive::Symbol Sym) {
531
134
  Symbol *S;
532
134
  bool WasInserted;
533
134
  StringRef Name = Sym.getName();
534
134
  std::tie(S, WasInserted) = insert(Name);
535
134
  if (
WasInserted134
) {
536
66
    replaceBody<LazyArchive>(S, F, Sym, SymbolBody::UnknownType);
537
66
    return S;
538
66
  }
539
68
  
if (68
!S->body()->isUndefined()68
)
540
23
    return S;
541
45
542
45
  // Weak undefined symbols should not fetch members from archives. If we were
543
45
  // to keep old symbol we would not know that an archive member was available
544
45
  // if a strong undefined symbol shows up afterwards in the link. If a strong
545
45
  // undefined symbol never shows up, this lazy symbol will get to the end of
546
45
  // the link and must be treated as the weak undefined one. We already marked
547
45
  // this symbol as used when we added it to the symbol table, but we also need
548
45
  // to preserve its type. FIXME: Move the Type field to Symbol.
549
45
  
if (45
S->isWeak()45
) {
550
10
    replaceBody<LazyArchive>(S, F, Sym, S->body()->Type);
551
10
    return S;
552
10
  }
553
35
  std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
554
35
  if (!MBInfo.first.getBuffer().empty())
555
35
    addFile<ELFT>(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
556
134
  return S;
557
134
}
Unexecuted instantiation: lld::elf::Symbol* lld::elf::SymbolTable::addLazyArchive<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::ArchiveFile*, llvm::object::Archive::Symbol)
558
559
template <class ELFT>
560
25
void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
561
25
  Symbol *S;
562
25
  bool WasInserted;
563
25
  std::tie(S, WasInserted) = insert(Name);
564
25
  if (
WasInserted25
) {
565
14
    replaceBody<LazyObject>(S, &Obj, Name, SymbolBody::UnknownType);
566
14
    return;
567
14
  }
568
11
  
if (11
!S->body()->isUndefined()11
)
569
3
    return;
570
8
571
8
  // See comment for addLazyArchive above.
572
8
  
if (8
S->isWeak()8
)
573
0
    replaceBody<LazyObject>(S, &Obj, Name, S->body()->Type);
574
8
  else 
if (InputFile *8
F8
= Obj.fetch())
575
7
    addFile<ELFT>(F);
576
25
}
void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::StringRef, lld::elf::LazyObjFile&)
Line
Count
Source
560
25
void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
561
25
  Symbol *S;
562
25
  bool WasInserted;
563
25
  std::tie(S, WasInserted) = insert(Name);
564
25
  if (
WasInserted25
) {
565
14
    replaceBody<LazyObject>(S, &Obj, Name, SymbolBody::UnknownType);
566
14
    return;
567
14
  }
568
11
  
if (11
!S->body()->isUndefined()11
)
569
3
    return;
570
8
571
8
  // See comment for addLazyArchive above.
572
8
  
if (8
S->isWeak()8
)
573
0
    replaceBody<LazyObject>(S, &Obj, Name, S->body()->Type);
574
8
  else 
if (InputFile *8
F8
= Obj.fetch())
575
7
    addFile<ELFT>(F);
576
25
}
Unexecuted instantiation: void lld::elf::SymbolTable::addLazyObject<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::StringRef, lld::elf::LazyObjFile&)
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, true> >(llvm::StringRef, lld::elf::LazyObjFile&)
577
578
// Process undefined (-u) flags by loading lazy symbols named by those flags.
579
1.59k
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
580
1.59k
  for (StringRef S : Config->Undefined)
581
18
    
if (auto *18
L18
= dyn_cast_or_null<Lazy>(find(S)))
582
12
      
if (InputFile *12
File12
= L->fetch())
583
12
        addFile<ELFT>(File);
584
1.59k
}
void lld::elf::SymbolTable::scanUndefinedFlags<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
579
44
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
580
44
  for (StringRef S : Config->Undefined)
581
0
    
if (auto *0
L0
= dyn_cast_or_null<Lazy>(find(S)))
582
0
      
if (InputFile *0
File0
= L->fetch())
583
0
        addFile<ELFT>(File);
584
44
}
void lld::elf::SymbolTable::scanUndefinedFlags<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
579
191
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
580
191
  for (StringRef S : Config->Undefined)
581
0
    
if (auto *0
L0
= dyn_cast_or_null<Lazy>(find(S)))
582
0
      
if (InputFile *0
File0
= L->fetch())
583
0
        addFile<ELFT>(File);
584
191
}
void lld::elf::SymbolTable::scanUndefinedFlags<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
579
1.26k
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
580
1.26k
  for (StringRef S : Config->Undefined)
581
18
    
if (auto *18
L18
= dyn_cast_or_null<Lazy>(find(S)))
582
12
      
if (InputFile *12
File12
= L->fetch())
583
12
        addFile<ELFT>(File);
584
1.26k
}
void lld::elf::SymbolTable::scanUndefinedFlags<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
579
94
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
580
94
  for (StringRef S : Config->Undefined)
581
0
    
if (auto *0
L0
= dyn_cast_or_null<Lazy>(find(S)))
582
0
      
if (InputFile *0
File0
= L->fetch())
583
0
        addFile<ELFT>(File);
584
94
}
585
586
// This function takes care of the case in which shared libraries depend on
587
// the user program (not the other way, which is usual). Shared libraries
588
// may have undefined symbols, expecting that the user program provides
589
// the definitions for them. An example is BSD's __progname symbol.
590
// We need to put such symbols to the main program's .dynsym so that
591
// shared libraries can find them.
592
// Except this, we ignore undefined symbols in DSOs.
593
1.59k
template <class ELFT> void SymbolTable::scanShlibUndefined() {
594
213
  for (InputFile *F : SharedFiles) {
595
30
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
596
30
      SymbolBody *Sym = find(U);
597
30
      if (
!Sym || 30
!Sym->isDefined()15
)
598
15
        continue;
599
15
      Sym->symbol()->ExportDynamic = true;
600
15
601
15
      // If -dynamic-list is given, the default version is set to
602
15
      // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
603
15
      // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
604
15
      // specified by -dynamic-list.
605
15
      Sym->symbol()->VersionId = VER_NDX_GLOBAL;
606
15
    }
607
213
  }
608
1.59k
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
593
191
template <class ELFT> void SymbolTable::scanShlibUndefined() {
594
38
  for (InputFile *F : SharedFiles) {
595
0
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
596
0
      SymbolBody *Sym = find(U);
597
0
      if (
!Sym || 0
!Sym->isDefined()0
)
598
0
        continue;
599
0
      Sym->symbol()->ExportDynamic = true;
600
0
601
0
      // If -dynamic-list is given, the default version is set to
602
0
      // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
603
0
      // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
604
0
      // specified by -dynamic-list.
605
0
      Sym->symbol()->VersionId = VER_NDX_GLOBAL;
606
0
    }
607
38
  }
608
191
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
593
1.26k
template <class ELFT> void SymbolTable::scanShlibUndefined() {
594
151
  for (InputFile *F : SharedFiles) {
595
30
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
596
30
      SymbolBody *Sym = find(U);
597
30
      if (
!Sym || 30
!Sym->isDefined()15
)
598
15
        continue;
599
15
      Sym->symbol()->ExportDynamic = true;
600
15
601
15
      // If -dynamic-list is given, the default version is set to
602
15
      // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
603
15
      // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
604
15
      // specified by -dynamic-list.
605
15
      Sym->symbol()->VersionId = VER_NDX_GLOBAL;
606
15
    }
607
151
  }
608
1.26k
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
593
44
template <class ELFT> void SymbolTable::scanShlibUndefined() {
594
7
  for (InputFile *F : SharedFiles) {
595
0
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
596
0
      SymbolBody *Sym = find(U);
597
0
      if (
!Sym || 0
!Sym->isDefined()0
)
598
0
        continue;
599
0
      Sym->symbol()->ExportDynamic = true;
600
0
601
0
      // If -dynamic-list is given, the default version is set to
602
0
      // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
603
0
      // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
604
0
      // specified by -dynamic-list.
605
0
      Sym->symbol()->VersionId = VER_NDX_GLOBAL;
606
0
    }
607
7
  }
608
44
}
void lld::elf::SymbolTable::scanShlibUndefined<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
593
94
template <class ELFT> void SymbolTable::scanShlibUndefined() {
594
17
  for (InputFile *F : SharedFiles) {
595
0
    for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
596
0
      SymbolBody *Sym = find(U);
597
0
      if (
!Sym || 0
!Sym->isDefined()0
)
598
0
        continue;
599
0
      Sym->symbol()->ExportDynamic = true;
600
0
601
0
      // If -dynamic-list is given, the default version is set to
602
0
      // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
603
0
      // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
604
0
      // specified by -dynamic-list.
605
0
      Sym->symbol()->VersionId = VER_NDX_GLOBAL;
606
0
    }
607
17
  }
608
94
}
609
610
// Initialize DemangledSyms with a map from demangled symbols to symbol
611
// objects. Used to handle "extern C++" directive in version scripts.
612
//
613
// The map will contain all demangled symbols. That can be very large,
614
// and in LLD we generally want to avoid do anything for each symbol.
615
// Then, why are we doing this? Here's why.
616
//
617
// Users can use "extern C++ {}" directive to match against demangled
618
// C++ symbols. For example, you can write a pattern such as
619
// "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
620
// other than trying to match a pattern against all demangled symbols.
621
// So, if "extern C++" feature is used, we need to demangle all known
622
// symbols.
623
26
StringMap<std::vector<SymbolBody *>> &SymbolTable::getDemangledSyms() {
624
26
  if (
!DemangledSyms26
) {
625
19
    DemangledSyms.emplace();
626
43
    for (Symbol *Sym : SymVector) {
627
43
      SymbolBody *B = Sym->body();
628
43
      if (B->isUndefined())
629
0
        continue;
630
43
      
if (Optional<std::string> 43
S43
= demangle(B->getName()))
631
43
        (*DemangledSyms)[*S].push_back(B);
632
43
      else
633
0
        (*DemangledSyms)[B->getName()].push_back(B);
634
43
    }
635
19
  }
636
26
  return *DemangledSyms;
637
26
}
638
639
59
std::vector<SymbolBody *> SymbolTable::findByVersion(SymbolVersion Ver) {
640
59
  if (Ver.IsExternCpp)
641
8
    return getDemangledSyms().lookup(Ver.Name);
642
51
  
if (SymbolBody *51
B51
= find(Ver.Name))
643
46
    
if (46
!B->isUndefined()46
)
644
44
      return {B};
645
7
  return {};
646
7
}
647
648
43
std::vector<SymbolBody *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
649
43
  std::vector<SymbolBody *> Res;
650
43
  StringMatcher M(Ver.Name);
651
43
652
43
  if (
Ver.IsExternCpp43
) {
653
18
    for (auto &P : getDemangledSyms())
654
42
      
if (42
M.match(P.first())42
)
655
19
        Res.insert(Res.end(), P.second.begin(), P.second.end());
656
18
    return Res;
657
18
  }
658
25
659
25
  
for (Symbol *Sym : SymVector) 25
{
660
118
    SymbolBody *B = Sym->body();
661
118
    if (
!B->isUndefined() && 118
M.match(B->getName())116
)
662
35
      Res.push_back(B);
663
118
  }
664
43
  return Res;
665
43
}
666
667
// If there's only one anonymous version definition in a version
668
// script file, the script does not actually define any symbol version,
669
// but just specifies symbols visibilities.
670
1.59k
void SymbolTable::handleAnonymousVersion() {
671
1.59k
  for (SymbolVersion &Ver : Config->VersionScriptGlobals)
672
26
    assignExactVersion(Ver, VER_NDX_GLOBAL, "global");
673
1.59k
  for (SymbolVersion &Ver : Config->VersionScriptGlobals)
674
26
    assignWildcardVersion(Ver, VER_NDX_GLOBAL);
675
1.59k
  for (SymbolVersion &Ver : Config->VersionScriptLocals)
676
8
    assignExactVersion(Ver, VER_NDX_LOCAL, "local");
677
1.59k
  for (SymbolVersion &Ver : Config->VersionScriptLocals)
678
8
    assignWildcardVersion(Ver, VER_NDX_LOCAL);
679
1.59k
}
680
681
// Handles -dynamic-list.
682
1.59k
void SymbolTable::handleDynamicList() {
683
17
  for (SymbolVersion &Ver : Config->DynamicList) {
684
17
    std::vector<SymbolBody *> Syms;
685
17
    if (Ver.HasWildcard)
686
0
      Syms = findByVersion(Ver);
687
17
    else
688
17
      Syms = findAllByVersion(Ver);
689
17
690
14
    for (SymbolBody *B : Syms) {
691
14
      if (!Config->Shared)
692
12
        B->symbol()->VersionId = VER_NDX_GLOBAL;
693
2
      else 
if (2
B->symbol()->includeInDynsym()2
)
694
1
        B->IsPreemptible = true;
695
14
    }
696
17
  }
697
1.59k
}
698
699
// Set symbol versions to symbols. This function handles patterns
700
// containing no wildcard characters.
701
void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
702
85
                                     StringRef VersionName) {
703
85
  if (Ver.HasWildcard)
704
26
    return;
705
59
706
59
  // Get a list of symbols which we need to assign the version to.
707
59
  std::vector<SymbolBody *> Syms = findByVersion(Ver);
708
59
  if (
Syms.empty()59
) {
709
10
    if (Config->NoUndefinedVersion)
710
3
      error("version script assignment of '" + VersionName + "' to symbol '" +
711
3
            Ver.Name + "' failed: symbol not defined");
712
10
    return;
713
10
  }
714
49
715
49
  // Assign the version.
716
49
  
for (SymbolBody *B : Syms) 49
{
717
50
    // Skip symbols containing version info because symbol versions
718
50
    // specified by symbol names take precedence over version scripts.
719
50
    // See parseSymbolVersion().
720
50
    if (B->getName().contains('@'))
721
4
      continue;
722
46
723
46
    Symbol *Sym = B->symbol();
724
46
    if (Sym->InVersionScript)
725
1
      warn("duplicate symbol '" + Ver.Name + "' in version script");
726
50
    Sym->VersionId = VersionId;
727
50
    Sym->InVersionScript = true;
728
50
  }
729
85
}
730
731
85
void SymbolTable::assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId) {
732
85
  if (!Ver.HasWildcard)
733
59
    return;
734
26
735
26
  // Exact matching takes precendence over fuzzy matching,
736
26
  // so we set a version to a symbol only if no version has been assigned
737
26
  // to the symbol. This behavior is compatible with GNU.
738
26
  for (SymbolBody *B : findAllByVersion(Ver))
739
40
    
if (40
B->symbol()->VersionId == Config->DefaultSymbolVersion40
)
740
36
      B->symbol()->VersionId = VersionId;
741
85
}
742
743
// This function processes version scripts by updating VersionId
744
// member of symbols.
745
1.59k
void SymbolTable::scanVersionScript() {
746
1.59k
  // Handle edge cases first.
747
1.59k
  handleAnonymousVersion();
748
1.59k
  handleDynamicList();
749
1.59k
750
1.59k
  // Now we have version definitions, so we need to set version ids to symbols.
751
1.59k
  // Each version definition has a glob pattern, and all symbols that match
752
1.59k
  // with the pattern get that version.
753
1.59k
754
1.59k
  // First, we assign versions to exact matching symbols,
755
1.59k
  // i.e. version definitions not containing any glob meta-characters.
756
1.59k
  for (VersionDefinition &V : Config->VersionDefinitions)
757
59
    for (SymbolVersion &Ver : V.Globals)
758
51
      assignExactVersion(Ver, V.Id, V.Name);
759
1.59k
760
1.59k
  // Next, we assign versions to fuzzy matching symbols,
761
1.59k
  // i.e. version definitions containing glob meta-characters.
762
1.59k
  // Note that because the last match takes precedence over previous matches,
763
1.59k
  // we iterate over the definitions in the reverse order.
764
1.59k
  for (VersionDefinition &V : llvm::reverse(Config->VersionDefinitions))
765
59
    for (SymbolVersion &Ver : V.Globals)
766
51
      assignWildcardVersion(Ver, V.Id);
767
1.59k
768
1.59k
  // Symbol themselves might know their versions because symbols
769
1.59k
  // can contain versions in the form of <name>@<version>.
770
1.59k
  // Let them parse and update their names to exclude version suffix.
771
1.59k
  for (Symbol *Sym : SymVector)
772
3.58k
    Sym->body()->parseSymbolVersion();
773
1.59k
}
774
775
template void SymbolTable::addSymbolWrap<ELF32LE>(StringRef);
776
template void SymbolTable::addSymbolWrap<ELF32BE>(StringRef);
777
template void SymbolTable::addSymbolWrap<ELF64LE>(StringRef);
778
template void SymbolTable::addSymbolWrap<ELF64BE>(StringRef);
779
780
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef);
781
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef);
782
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef);
783
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef);
784
785
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef, bool, uint8_t,
786
                                                    uint8_t, uint8_t, bool,
787
                                                    InputFile *);
788
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef, bool, uint8_t,
789
                                                    uint8_t, uint8_t, bool,
790
                                                    InputFile *);
791
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef, bool, uint8_t,
792
                                                    uint8_t, uint8_t, bool,
793
                                                    InputFile *);
794
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef, bool, uint8_t,
795
                                                    uint8_t, uint8_t, bool,
796
                                                    InputFile *);
797
798
template void SymbolTable::addSymbolAlias<ELF32LE>(StringRef, StringRef);
799
template void SymbolTable::addSymbolAlias<ELF32BE>(StringRef, StringRef);
800
template void SymbolTable::addSymbolAlias<ELF64LE>(StringRef, StringRef);
801
template void SymbolTable::addSymbolAlias<ELF64BE>(StringRef, StringRef);
802
803
template void SymbolTable::addCombinedLTOObject<ELF32LE>();
804
template void SymbolTable::addCombinedLTOObject<ELF32BE>();
805
template void SymbolTable::addCombinedLTOObject<ELF64LE>();
806
template void SymbolTable::addCombinedLTOObject<ELF64BE>();
807
808
template Symbol *SymbolTable::addRegular<ELF32LE>(StringRef, uint8_t, uint8_t,
809
                                                  uint64_t, uint64_t, uint8_t,
810
                                                  SectionBase *, InputFile *);
811
template Symbol *SymbolTable::addRegular<ELF32BE>(StringRef, uint8_t, uint8_t,
812
                                                  uint64_t, uint64_t, uint8_t,
813
                                                  SectionBase *, InputFile *);
814
template Symbol *SymbolTable::addRegular<ELF64LE>(StringRef, uint8_t, uint8_t,
815
                                                  uint64_t, uint64_t, uint8_t,
816
                                                  SectionBase *, InputFile *);
817
template Symbol *SymbolTable::addRegular<ELF64BE>(StringRef, uint8_t, uint8_t,
818
                                                  uint64_t, uint64_t, uint8_t,
819
                                                  SectionBase *, InputFile *);
820
821
template DefinedRegular *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
822
                                                           uint8_t);
823
template DefinedRegular *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
824
                                                           uint8_t);
825
template DefinedRegular *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
826
                                                           uint8_t);
827
template DefinedRegular *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
828
                                                           uint8_t);
829
830
template DefinedRegular *SymbolTable::addIgnored<ELF32LE>(StringRef, uint8_t);
831
template DefinedRegular *SymbolTable::addIgnored<ELF32BE>(StringRef, uint8_t);
832
template DefinedRegular *SymbolTable::addIgnored<ELF64LE>(StringRef, uint8_t);
833
template DefinedRegular *SymbolTable::addIgnored<ELF64BE>(StringRef, uint8_t);
834
835
template Symbol *
836
SymbolTable::addLazyArchive<ELF32LE>(ArchiveFile *,
837
                                     const object::Archive::Symbol);
838
template Symbol *
839
SymbolTable::addLazyArchive<ELF32BE>(ArchiveFile *,
840
                                     const object::Archive::Symbol);
841
template Symbol *
842
SymbolTable::addLazyArchive<ELF64LE>(ArchiveFile *,
843
                                     const object::Archive::Symbol);
844
template Symbol *
845
SymbolTable::addLazyArchive<ELF64BE>(ArchiveFile *,
846
                                     const object::Archive::Symbol);
847
848
template void SymbolTable::addLazyObject<ELF32LE>(StringRef, LazyObjFile &);
849
template void SymbolTable::addLazyObject<ELF32BE>(StringRef, LazyObjFile &);
850
template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
851
template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
852
853
template void SymbolTable::addShared<ELF32LE>(SharedFile<ELF32LE> *, StringRef,
854
                                              const typename ELF32LE::Sym &,
855
                                              const typename ELF32LE::Verdef *);
856
template void SymbolTable::addShared<ELF32BE>(SharedFile<ELF32BE> *, StringRef,
857
                                              const typename ELF32BE::Sym &,
858
                                              const typename ELF32BE::Verdef *);
859
template void SymbolTable::addShared<ELF64LE>(SharedFile<ELF64LE> *, StringRef,
860
                                              const typename ELF64LE::Sym &,
861
                                              const typename ELF64LE::Verdef *);
862
template void SymbolTable::addShared<ELF64BE>(SharedFile<ELF64BE> *, StringRef,
863
                                              const typename ELF64BE::Sym &,
864
                                              const typename ELF64BE::Verdef *);
865
866
template void SymbolTable::scanUndefinedFlags<ELF32LE>();
867
template void SymbolTable::scanUndefinedFlags<ELF32BE>();
868
template void SymbolTable::scanUndefinedFlags<ELF64LE>();
869
template void SymbolTable::scanUndefinedFlags<ELF64BE>();
870
871
template void SymbolTable::scanShlibUndefined<ELF32LE>();
872
template void SymbolTable::scanShlibUndefined<ELF32BE>();
873
template void SymbolTable::scanShlibUndefined<ELF64LE>();
874
template void SymbolTable::scanShlibUndefined<ELF64BE>();