Coverage Report

Created: 2019-01-18 03:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/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_WASM_SYMBOL_TABLE_H
11
#define LLD_WASM_SYMBOL_TABLE_H
12
13
#include "InputFiles.h"
14
#include "LTO.h"
15
#include "Symbols.h"
16
#include "lld/Common/LLVM.h"
17
#include "llvm/ADT/CachedHashString.h"
18
#include "llvm/ADT/DenseSet.h"
19
20
namespace lld {
21
namespace wasm {
22
23
class InputSegment;
24
25
// SymbolTable is a bucket of all known symbols, including defined,
26
// undefined, or lazy symbols (the last one is symbols in archive
27
// files whose archive members are not yet loaded).
28
//
29
// We put all symbols of all files to a SymbolTable, and the
30
// SymbolTable selects the "best" symbols if there are name
31
// conflicts. For example, obviously, a defined symbol is better than
32
// an undefined symbol. Or, if there's a conflict between a lazy and a
33
// undefined, it'll read an archive member to read a real definition
34
// to replace the lazy symbol. The logic is implemented in the
35
// add*() functions, which are called by input files as they are parsed.
36
// There is one add* function per symbol type.
37
class SymbolTable {
38
public:
39
  void addFile(InputFile *File);
40
  void addCombinedLTOObject();
41
42
  std::vector<ObjFile *> ObjectFiles;
43
  std::vector<BitcodeFile *> BitcodeFiles;
44
  std::vector<InputFunction *> SyntheticFunctions;
45
  std::vector<InputGlobal *> SyntheticGlobals;
46
47
  void reportRemainingUndefines();
48
49
369
  ArrayRef<Symbol *> getSymbols() const { return SymVector; }
50
  Symbol *find(StringRef Name);
51
52
  Symbol *addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
53
                             InputFunction *Function);
54
  Symbol *addDefinedData(StringRef Name, uint32_t Flags, InputFile *File,
55
                         InputSegment *Segment, uint32_t Address,
56
                         uint32_t Size);
57
  Symbol *addDefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
58
                           InputGlobal *G);
59
  Symbol *addDefinedEvent(StringRef Name, uint32_t Flags, InputFile *File,
60
                          InputEvent *E);
61
62
  Symbol *addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
63
                               const WasmSignature *Signature);
64
  Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File);
65
  Symbol *addUndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
66
                             const WasmGlobalType *Type);
67
68
  void addLazy(ArchiveFile *F, const llvm::object::Archive::Symbol *Sym);
69
70
  bool addComdat(StringRef Name);
71
72
  DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags);
73
  DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags,
74
                                    InputGlobal *Global);
75
  DefinedFunction *addSyntheticFunction(StringRef Name, uint32_t Flags,
76
                                        InputFunction *Function);
77
78
private:
79
  std::pair<Symbol *, bool> insert(StringRef Name, InputFile *File);
80
81
  llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
82
  std::vector<Symbol *> SymVector;
83
84
  llvm::DenseSet<llvm::CachedHashStringRef> Comdats;
85
86
  // For LTO.
87
  std::unique_ptr<BitcodeCompiler> LTO;
88
};
89
90
extern SymbolTable *Symtab;
91
92
} // namespace wasm
93
} // namespace lld
94
95
#endif