Coverage Report

Created: 2018-06-18 20:01

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/InputFiles.h
Line
Count
Source (jump to first uncovered line)
1
//===- InputFiles.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_INPUT_FILES_H
11
#define LLD_WASM_INPUT_FILES_H
12
13
#include "Symbols.h"
14
#include "lld/Common/LLVM.h"
15
#include "llvm/ADT/DenseMap.h"
16
#include "llvm/ADT/DenseSet.h"
17
#include "llvm/LTO/LTO.h"
18
#include "llvm/Object/Archive.h"
19
#include "llvm/Object/Wasm.h"
20
#include "llvm/Support/MemoryBuffer.h"
21
#include <vector>
22
23
using llvm::object::Archive;
24
using llvm::object::WasmObjectFile;
25
using llvm::object::WasmSection;
26
using llvm::object::WasmSymbol;
27
using llvm::wasm::WasmGlobal;
28
using llvm::wasm::WasmImport;
29
using llvm::wasm::WasmRelocation;
30
using llvm::wasm::WasmSignature;
31
32
namespace llvm {
33
namespace lto {
34
class InputFile;
35
}
36
} // namespace llvm
37
38
namespace lld {
39
namespace wasm {
40
41
class InputChunk;
42
class InputFunction;
43
class InputSegment;
44
class InputGlobal;
45
class InputSection;
46
47
class InputFile {
48
public:
49
  enum Kind {
50
    ObjectKind,
51
    ArchiveKind,
52
    BitcodeKind,
53
  };
54
55
0
  virtual ~InputFile() {}
56
57
  // Returns the filename.
58
0
  StringRef getName() const { return MB.getBufferIdentifier(); }
59
60
  // Reads a file (the constructor doesn't do that).
61
  virtual void parse() = 0;
62
63
0
  Kind kind() const { return FileKind; }
64
65
  // An archive file name if this file is created from an archive.
66
  StringRef ParentName;
67
68
0
  ArrayRef<Symbol *> getSymbols() const { return Symbols; }
69
70
protected:
71
0
  InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
72
  MemoryBufferRef MB;
73
74
  // List of all symbols referenced or defined by this file.
75
  std::vector<Symbol *> Symbols;
76
77
private:
78
  const Kind FileKind;
79
};
80
81
// .a file (ar archive)
82
class ArchiveFile : public InputFile {
83
public:
84
0
  explicit ArchiveFile(MemoryBufferRef M) : InputFile(ArchiveKind, M) {}
85
0
  static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
86
87
  void addMember(const Archive::Symbol *Sym);
88
89
  void parse() override;
90
91
private:
92
  std::unique_ptr<Archive> File;
93
  llvm::DenseSet<uint64_t> Seen;
94
};
95
96
// .o file (wasm object file)
97
class ObjFile : public InputFile {
98
public:
99
0
  explicit ObjFile(MemoryBufferRef M) : InputFile(ObjectKind, M) {}
100
0
  static bool classof(const InputFile *F) { return F->kind() == ObjectKind; }
101
102
  void parse() override;
103
104
  // Returns the underlying wasm file.
105
0
  const WasmObjectFile *getWasmObj() const { return WasmObj.get(); }
106
107
  void dumpInfo() const;
108
109
  uint32_t calcNewIndex(const WasmRelocation &Reloc) const;
110
  uint32_t calcNewValue(const WasmRelocation &Reloc) const;
111
  uint32_t calcNewAddend(const WasmRelocation &Reloc) const;
112
  uint32_t calcExpectedValue(const WasmRelocation &Reloc) const;
113
114
  const WasmSection *CodeSection = nullptr;
115
  const WasmSection *DataSection = nullptr;
116
117
  // Maps input type indices to output type indices
118
  std::vector<uint32_t> TypeMap;
119
  std::vector<bool> TypeIsUsed;
120
  // Maps function indices to table indices
121
  std::vector<uint32_t> TableEntries;
122
  std::vector<bool> UsedComdats;
123
  std::vector<InputSegment *> Segments;
124
  std::vector<InputFunction *> Functions;
125
  std::vector<InputGlobal *> Globals;
126
  std::vector<InputSection *> CustomSections;
127
  llvm::DenseMap<uint32_t, InputSection *> CustomSectionsByIndex;
128
129
0
  Symbol *getSymbol(uint32_t Index) const { return Symbols[Index]; }
130
  FunctionSymbol *getFunctionSymbol(uint32_t Index) const;
131
  DataSymbol *getDataSymbol(uint32_t Index) const;
132
  GlobalSymbol *getGlobalSymbol(uint32_t Index) const;
133
  SectionSymbol *getSectionSymbol(uint32_t Index) const;
134
135
private:
136
  Symbol *createDefined(const WasmSymbol &Sym);
137
  Symbol *createUndefined(const WasmSymbol &Sym);
138
139
  bool isExcludedByComdat(InputChunk *Chunk) const;
140
141
  std::unique_ptr<WasmObjectFile> WasmObj;
142
};
143
144
class BitcodeFile : public InputFile {
145
public:
146
0
  explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
147
0
  static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
148
149
  void parse() override;
150
  std::unique_ptr<llvm::lto::InputFile> Obj;
151
};
152
153
// Opens a given file.
154
llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
155
156
} // namespace wasm
157
158
std::string toString(const wasm::InputFile *File);
159
160
} // namespace lld
161
162
#endif