Coverage Report

Created: 2018-10-20 12:32

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