Coverage Report

Created: 2018-10-23 15:26

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/SymbolTable.h
Line
Count
Source
1
//===- SymbolTable.h --------------------------------------------*- C++ -*-===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLD_ELF_SYMBOL_TABLE_H
11
#define LLD_ELF_SYMBOL_TABLE_H
12
13
#include "InputFiles.h"
14
#include "LTO.h"
15
#include "lld/Common/Strings.h"
16
#include "llvm/ADT/CachedHashString.h"
17
#include "llvm/ADT/DenseMap.h"
18
19
namespace lld {
20
namespace elf {
21
class Defined;
22
class SectionBase;
23
24
// SymbolTable is a bucket of all known symbols, including defined,
25
// undefined, or lazy symbols (the last one is symbols in archive
26
// files whose archive members are not yet loaded).
27
//
28
// We put all symbols of all files to a SymbolTable, and the
29
// SymbolTable selects the "best" symbols if there are name
30
// conflicts. For example, obviously, a defined symbol is better than
31
// an undefined symbol. Or, if there's a conflict between a lazy and a
32
// undefined, it'll read an archive member to read a real definition
33
// to replace the lazy symbol. The logic is implemented in the
34
// add*() functions, which are called by input files as they are parsed. There
35
// is one add* function per symbol type.
36
class SymbolTable {
37
public:
38
  template <class ELFT> void addFile(InputFile *File);
39
  template <class ELFT> void addCombinedLTOObject();
40
  void wrap(Symbol *Sym, Symbol *Real, Symbol *Wrap);
41
42
7.33k
  ArrayRef<Symbol *> getSymbols() const { return SymVector; }
43
44
  template <class ELFT>
45
  Symbol *addUndefined(StringRef Name, uint8_t Binding, uint8_t StOther,
46
                       uint8_t Type, bool CanOmitFromDynSym, InputFile *File);
47
48
  Symbol *addDefined(StringRef Name, uint8_t StOther, uint8_t Type,
49
                     uint64_t Value, uint64_t Size, uint8_t Binding,
50
                     SectionBase *Section, InputFile *File);
51
52
  template <class ELFT>
53
  void addShared(StringRef Name, SharedFile<ELFT> &F,
54
                 const typename ELFT::Sym &Sym, uint32_t Alignment,
55
                 uint32_t VerdefIndex);
56
57
  template <class ELFT>
58
  void addLazyArchive(StringRef Name, ArchiveFile &F,
59
                      const llvm::object::Archive::Symbol S);
60
61
  template <class ELFT> void addLazyObject(StringRef Name, LazyObjFile &Obj);
62
63
  Symbol *addBitcode(StringRef Name, uint8_t Binding, uint8_t StOther,
64
                     uint8_t Type, bool CanOmitFromDynSym, BitcodeFile &File);
65
66
  Symbol *addCommon(StringRef Name, uint64_t Size, uint32_t Alignment,
67
                    uint8_t Binding, uint8_t StOther, uint8_t Type,
68
                    InputFile &File);
69
70
  std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Visibility,
71
                                   bool CanOmitFromDynSym, InputFile *File);
72
73
  template <class ELFT> void fetchLazy(Symbol *Sym);
74
75
  void scanVersionScript();
76
77
  Symbol *find(StringRef Name);
78
79
  void trace(StringRef Name);
80
81
  void handleDynamicList();
82
83
private:
84
  std::pair<Symbol *, bool> insertName(StringRef Name);
85
86
  std::vector<Symbol *> findByVersion(SymbolVersion Ver);
87
  std::vector<Symbol *> findAllByVersion(SymbolVersion Ver);
88
89
  llvm::StringMap<std::vector<Symbol *>> &getDemangledSyms();
90
  void handleAnonymousVersion();
91
  void assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
92
                          StringRef VersionName);
93
  void assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId);
94
95
  // The order the global symbols are in is not defined. We can use an arbitrary
96
  // order, but it has to be reproducible. That is true even when cross linking.
97
  // The default hashing of StringRef produces different results on 32 and 64
98
  // bit systems so we use a map to a vector. That is arbitrary, deterministic
99
  // but a bit inefficient.
100
  // FIXME: Experiment with passing in a custom hashing or sorting the symbols
101
  // once symbol resolution is finished.
102
  llvm::DenseMap<llvm::CachedHashStringRef, int> SymMap;
103
  std::vector<Symbol *> SymVector;
104
105
  // Comdat groups define "link once" sections. If two comdat groups have the
106
  // same name, only one of them is linked, and the other is ignored. This set
107
  // is used to uniquify them.
108
  llvm::DenseSet<llvm::CachedHashStringRef> ComdatGroups;
109
110
  // Set of .so files to not link the same shared object file more than once.
111
  llvm::DenseSet<StringRef> SoNames;
112
113
  // A map from demangled symbol names to their symbol objects.
114
  // This mapping is 1:N because two symbols with different versions
115
  // can have the same name. We use this map to handle "extern C++ {}"
116
  // directive in version scripts.
117
  llvm::Optional<llvm::StringMap<std::vector<Symbol *>>> DemangledSyms;
118
119
  // For LTO.
120
  std::unique_ptr<BitcodeCompiler> LTO;
121
};
122
123
extern SymbolTable *Symtab;
124
} // namespace elf
125
} // namespace lld
126
127
#endif