Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/SymbolTable.h
Line
Count
Source
1
//===- SymbolTable.h --------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLD_WASM_SYMBOL_TABLE_H
10
#define LLD_WASM_SYMBOL_TABLE_H
11
12
#include "InputFiles.h"
13
#include "LTO.h"
14
#include "Symbols.h"
15
#include "lld/Common/LLVM.h"
16
#include "llvm/ADT/CachedHashString.h"
17
#include "llvm/ADT/DenseSet.h"
18
19
namespace lld {
20
namespace wasm {
21
22
class InputSegment;
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.
35
// There is one add* function per symbol type.
36
class SymbolTable {
37
public:
38
  void addFile(InputFile *File);
39
  void addCombinedLTOObject();
40
41
  std::vector<ObjFile *> ObjectFiles;
42
  std::vector<SharedFile *> SharedFiles;
43
  std::vector<BitcodeFile *> BitcodeFiles;
44
  std::vector<InputFunction *> SyntheticFunctions;
45
  std::vector<InputGlobal *> SyntheticGlobals;
46
47
  void reportRemainingUndefines();
48
49
597
  ArrayRef<Symbol *> getSymbols() const { return SymVector; }
50
51
  Symbol *find(StringRef Name);
52
53
  void replace(StringRef Name, Symbol* Sym);
54
55
  void trace(StringRef Name);
56
57
  Symbol *addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
58
                             InputFunction *Function);
59
  Symbol *addDefinedData(StringRef Name, uint32_t Flags, InputFile *File,
60
                         InputSegment *Segment, uint32_t Address,
61
                         uint32_t Size);
62
  Symbol *addDefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
63
                           InputGlobal *G);
64
  Symbol *addDefinedEvent(StringRef Name, uint32_t Flags, InputFile *File,
65
                          InputEvent *E);
66
67
  Symbol *addUndefinedFunction(StringRef Name, StringRef ImportName,
68
                               StringRef ImportModule, uint32_t Flags,
69
                               InputFile *File, const WasmSignature *Signature);
70
  Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File);
71
  Symbol *addUndefinedGlobal(StringRef Name, StringRef ImportName,
72
                             StringRef ImportModule,  uint32_t Flags,
73
                             InputFile *File, const WasmGlobalType *Type);
74
75
  void addLazy(ArchiveFile *F, const llvm::object::Archive::Symbol *Sym);
76
77
  bool addComdat(StringRef Name);
78
79
  DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags);
80
  DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags,
81
                                    InputGlobal *Global);
82
  DefinedFunction *addSyntheticFunction(StringRef Name, uint32_t Flags,
83
                                        InputFunction *Function);
84
85
  void handleSymbolVariants();
86
  void handleWeakUndefines();
87
88
private:
89
  std::pair<Symbol *, bool> insert(StringRef Name, const InputFile *File);
90
  std::pair<Symbol *, bool> insertName(StringRef Name);
91
92
  bool getFunctionVariant(Symbol* Sym, const WasmSignature *Sig,
93
                          const InputFile *File, Symbol **Out);
94
  InputFunction *replaceWithUnreachable(Symbol *Sym, const WasmSignature &Sig,
95
                                        StringRef DebugName);
96
97
  // Maps symbol names to index into the SymVector.  -1 means that symbols
98
  // is to not yet in the vector but it should have tracing enabled if it is
99
  // ever added.
100
  llvm::DenseMap<llvm::CachedHashStringRef, int> SymMap;
101
  std::vector<Symbol *> SymVector;
102
103
  // For certain symbols types, e.g. function symbols, we allow for muliple
104
  // variants of the same symbol with different signatures.
105
  llvm::DenseMap<llvm::CachedHashStringRef, std::vector<Symbol *>> SymVariants;
106
107
  // Comdat groups define "link once" sections. If two comdat groups have the
108
  // same name, only one of them is linked, and the other is ignored. This set
109
  // is used to uniquify them.
110
  llvm::DenseSet<llvm::CachedHashStringRef> ComdatGroups;
111
112
  // For LTO.
113
  std::unique_ptr<BitcodeCompiler> LTO;
114
};
115
116
extern SymbolTable *Symtab;
117
118
} // namespace wasm
119
} // namespace lld
120
121
#endif