Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/COFF/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_COFF_SYMBOL_TABLE_H
11
#define LLD_COFF_SYMBOL_TABLE_H
12
13
#include "InputFiles.h"
14
#include "LTO.h"
15
#include "llvm/ADT/CachedHashString.h"
16
#include "llvm/ADT/DenseMap.h"
17
#include "llvm/ADT/DenseMapInfo.h"
18
#include "llvm/Support/raw_ostream.h"
19
20
namespace llvm {
21
struct LTOCodeGenerator;
22
}
23
24
namespace lld {
25
namespace coff {
26
27
class Chunk;
28
class CommonChunk;
29
class Defined;
30
class DefinedAbsolute;
31
class DefinedRelative;
32
class Lazy;
33
class SectionChunk;
34
class SymbolBody;
35
struct Symbol;
36
37
// SymbolTable is a bucket of all known symbols, including defined,
38
// undefined, or lazy symbols (the last one is symbols in archive
39
// files whose archive members are not yet loaded).
40
//
41
// We put all symbols of all files to a SymbolTable, and the
42
// SymbolTable selects the "best" symbols if there are name
43
// conflicts. For example, obviously, a defined symbol is better than
44
// an undefined symbol. Or, if there's a conflict between a lazy and a
45
// undefined, it'll read an archive member to read a real definition
46
// to replace the lazy symbol. The logic is implemented in the
47
// add*() functions, which are called by input files as they are parsed.
48
// There is one add* function per symbol type.
49
class SymbolTable {
50
public:
51
  void addFile(InputFile *File);
52
53
  // Try to resolve any undefined symbols and update the symbol table
54
  // accordingly, then print an error message for any remaining undefined
55
  // symbols.
56
  void reportRemainingUndefines();
57
58
  // Returns a list of chunks of selected symbols.
59
  std::vector<Chunk *> getChunks();
60
61
  // Returns a symbol for a given name. Returns a nullptr if not found.
62
  Symbol *find(StringRef Name);
63
  Symbol *findUnderscore(StringRef Name);
64
65
  // Occasionally we have to resolve an undefined symbol to its
66
  // mangled symbol. This function tries to find a mangled name
67
  // for U from the symbol table, and if found, set the symbol as
68
  // a weak alias for U.
69
  void mangleMaybe(SymbolBody *B);
70
  StringRef findMangle(StringRef Name);
71
72
  // Build a set of COFF objects representing the combined contents of
73
  // BitcodeFiles and add them to the symbol table. Called after all files are
74
  // added and before the writer writes results to a file.
75
  void addCombinedLTOObjects();
76
  std::vector<StringRef> compileBitcodeFiles();
77
78
  // Creates an Undefined symbol for a given name.
79
  SymbolBody *addUndefined(StringRef Name);
80
81
  Symbol *addSynthetic(StringRef N, Chunk *C);
82
  Symbol *addAbsolute(StringRef N, uint64_t VA);
83
84
  Symbol *addUndefined(StringRef Name, InputFile *F, bool IsWeakAlias);
85
  void addLazy(ArchiveFile *F, const Archive::Symbol Sym);
86
  Symbol *addAbsolute(StringRef N, COFFSymbolRef S);
87
  Symbol *addRegular(InputFile *F, StringRef N, bool IsCOMDAT,
88
                     const llvm::object::coff_symbol_generic *S = nullptr,
89
                     SectionChunk *C = nullptr);
90
  Symbol *addCommon(InputFile *F, StringRef N, uint64_t Size,
91
                    const llvm::object::coff_symbol_generic *S = nullptr,
92
                    CommonChunk *C = nullptr);
93
  DefinedImportData *addImportData(StringRef N, ImportFile *F);
94
  DefinedImportThunk *addImportThunk(StringRef Name, DefinedImportData *S,
95
                                     uint16_t Machine);
96
97
  void reportDuplicate(Symbol *Existing, InputFile *NewFile);
98
99
  // A list of chunks which to be added to .rdata.
100
  std::vector<Chunk *> LocalImportChunks;
101
102
  // Iterates symbols in non-determinstic hash table order.
103
40
  template <typename T> void forEachSymbol(T Callback) {
104
40
    for (auto &Pair : Symtab)
105
464
      Callback(Pair.second);
106
40
  }
107
108
private:
109
  std::pair<Symbol *, bool> insert(StringRef Name);
110
  StringRef findByPrefix(StringRef Prefix);
111
112
  llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> Symtab;
113
  std::unique_ptr<BitcodeCompiler> LTO;
114
};
115
116
extern SymbolTable *Symtab;
117
118
} // namespace coff
119
} // namespace lld
120
121
#endif