Coverage Report

Created: 2018-01-17 17:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/SymbolTable.h
Line
Count
Source (jump to first uncovered line)
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 "Symbols.h"
15
16
#include "llvm/ADT/CachedHashString.h"
17
#include "llvm/ADT/DenseMap.h"
18
#include "llvm/Support/raw_ostream.h"
19
20
using llvm::wasm::WasmSignature;
21
22
namespace lld {
23
namespace wasm {
24
25
class InputSegment;
26
27
// SymbolTable is a bucket of all known symbols, including defined,
28
// undefined, or lazy symbols (the last one is symbols in archive
29
// files whose archive members are not yet loaded).
30
//
31
// We put all symbols of all files to a SymbolTable, and the
32
// SymbolTable selects the "best" symbols if there are name
33
// conflicts. For example, obviously, a defined symbol is better than
34
// an undefined symbol. Or, if there's a conflict between a lazy and a
35
// undefined, it'll read an archive member to read a real definition
36
// to replace the lazy symbol. The logic is implemented in the
37
// add*() functions, which are called by input files as they are parsed.
38
// There is one add* function per symbol type.
39
class SymbolTable {
40
public:
41
  void addFile(InputFile *File);
42
43
  std::vector<ObjFile *> ObjectFiles;
44
45
  void reportDuplicate(Symbol *Existing, InputFile *NewFile);
46
  void reportRemainingUndefines();
47
48
0
  ArrayRef<Symbol *> getSymbols() const { return SymVector; }
49
  Symbol *find(StringRef Name);
50
  ObjFile *findComdat(StringRef Name) const;
51
52
  Symbol *addDefined(StringRef Name, Symbol::Kind Kind, uint32_t Flags,
53
                     InputFile *F, const InputSegment *Segment = nullptr,
54
                     InputFunction *Function = nullptr, uint32_t Address = 0);
55
  Symbol *addUndefined(StringRef Name, Symbol::Kind Kind, uint32_t Flags,
56
                       InputFile *F, const WasmSignature *Signature = nullptr);
57
  Symbol *addUndefinedFunction(StringRef Name, const WasmSignature *Type);
58
  Symbol *addDefinedGlobal(StringRef Name);
59
  Symbol *addDefinedFunction(StringRef Name, const WasmSignature *Type,
60
                             uint32_t Flags);
61
  void addLazy(ArchiveFile *F, const Archive::Symbol *Sym);
62
  bool addComdat(StringRef Name, ObjFile *);
63
64
private:
65
  std::pair<Symbol *, bool> insert(StringRef Name);
66
67
  llvm::DenseMap<llvm::CachedHashStringRef, ObjFile *> ComdatMap;
68
  llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
69
  std::vector<Symbol *> SymVector;
70
};
71
72
extern SymbolTable *Symtab;
73
74
} // namespace wasm
75
} // namespace lld
76
77
#endif