summaryrefslogtreecommitdiff
path: root/wasm/InputFiles.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:08:33 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:08:33 +0000
commit20d35e67e67f106f617c939725101223211659f0 (patch)
tree64eb963cbf5ba58765e0a6b64a440965d66a7a4d /wasm/InputFiles.h
parentae1a339de31cf4065777531959a11e55a2e5fa00 (diff)
Notes
Diffstat (limited to 'wasm/InputFiles.h')
-rw-r--r--wasm/InputFiles.h95
1 files changed, 54 insertions, 41 deletions
diff --git a/wasm/InputFiles.h b/wasm/InputFiles.h
index 158cc53cafb1..ec77446e6308 100644
--- a/wasm/InputFiles.h
+++ b/wasm/InputFiles.h
@@ -10,34 +10,46 @@
#ifndef LLD_WASM_INPUT_FILES_H
#define LLD_WASM_INPUT_FILES_H
+#include "Symbols.h"
#include "lld/Common/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Support/MemoryBuffer.h"
-
-#include "WriterUtils.h"
-
#include <vector>
using llvm::object::Archive;
using llvm::object::WasmObjectFile;
using llvm::object::WasmSection;
using llvm::object::WasmSymbol;
+using llvm::wasm::WasmGlobal;
using llvm::wasm::WasmImport;
+using llvm::wasm::WasmRelocation;
+using llvm::wasm::WasmSignature;
+
+namespace llvm {
+namespace lto {
+class InputFile;
+}
+} // namespace llvm
namespace lld {
namespace wasm {
-class Symbol;
+class InputChunk;
+class InputFunction;
class InputSegment;
+class InputGlobal;
+class InputSection;
class InputFile {
public:
enum Kind {
ObjectKind,
ArchiveKind,
+ BitcodeKind,
};
virtual ~InputFile() {}
@@ -51,12 +63,17 @@ public:
Kind kind() const { return FileKind; }
// An archive file name if this file is created from an archive.
- StringRef ParentName;
+ StringRef ArchiveName;
+
+ ArrayRef<Symbol *> getSymbols() const { return Symbols; }
protected:
InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
MemoryBufferRef MB;
+ // List of all symbols referenced or defined by this file.
+ std::vector<Symbol *> Symbols;
+
private:
const Kind FileKind;
};
@@ -89,58 +106,54 @@ public:
void dumpInfo() const;
- uint32_t relocateTypeIndex(uint32_t Original) const;
- uint32_t relocateFunctionIndex(uint32_t Original) const;
- uint32_t relocateGlobalIndex(uint32_t Original) const;
- uint32_t relocateTableIndex(uint32_t Original) const;
- uint32_t getRelocatedAddress(uint32_t Index) const;
-
- // Returns true if the given function index is an imported function,
- // as opposed to the locally defined function.
- bool isImportedFunction(uint32_t Index) const;
-
- size_t NumFunctionImports() const { return FunctionImports; }
- size_t NumGlobalImports() const { return GlobalImports; }
+ uint32_t calcNewIndex(const WasmRelocation &Reloc) const;
+ uint32_t calcNewValue(const WasmRelocation &Reloc) const;
+ uint32_t calcNewAddend(const WasmRelocation &Reloc) const;
+ uint32_t calcExpectedValue(const WasmRelocation &Reloc) const;
- int32_t FunctionIndexOffset = 0;
const WasmSection *CodeSection = nullptr;
- std::vector<OutputRelocation> CodeRelocations;
- int32_t CodeOffset = 0;
const WasmSection *DataSection = nullptr;
+ // Maps input type indices to output type indices
std::vector<uint32_t> TypeMap;
+ std::vector<bool> TypeIsUsed;
+ // Maps function indices to table indices
+ std::vector<uint32_t> TableEntries;
+ std::vector<bool> UsedComdats;
std::vector<InputSegment *> Segments;
+ std::vector<InputFunction *> Functions;
+ std::vector<InputGlobal *> Globals;
+ std::vector<InputSection *> CustomSections;
+ llvm::DenseMap<uint32_t, InputSection *> CustomSectionsByIndex;
- ArrayRef<Symbol *> getSymbols() { return Symbols; }
- ArrayRef<Symbol *> getTableSymbols() { return TableSymbols; }
+ Symbol *getSymbol(uint32_t Index) const { return Symbols[Index]; }
+ FunctionSymbol *getFunctionSymbol(uint32_t Index) const;
+ DataSymbol *getDataSymbol(uint32_t Index) const;
+ GlobalSymbol *getGlobalSymbol(uint32_t Index) const;
+ SectionSymbol *getSectionSymbol(uint32_t Index) const;
private:
- Symbol *createDefined(const WasmSymbol &Sym,
- const InputSegment *Segment = nullptr);
+ Symbol *createDefined(const WasmSymbol &Sym);
Symbol *createUndefined(const WasmSymbol &Sym);
- void initializeSymbols();
- InputSegment *getSegment(const WasmSymbol &WasmSym);
- Symbol *getFunctionSymbol(uint32_t FunctionIndex) const;
- Symbol *getTableSymbol(uint32_t TableIndex) const;
- Symbol *getGlobalSymbol(uint32_t GlobalIndex) const;
- // List of all symbols referenced or defined by this file.
- std::vector<Symbol *> Symbols;
-
- // List of all function symbols indexed by the function index space
- std::vector<Symbol *> FunctionSymbols;
+ bool isExcludedByComdat(InputChunk *Chunk) const;
- // List of all global symbols indexed by the global index space
- std::vector<Symbol *> GlobalSymbols;
+ std::unique_ptr<WasmObjectFile> WasmObj;
+};
- // List of all indirect symbols indexed by table index space.
- std::vector<Symbol *> TableSymbols;
+class BitcodeFile : public InputFile {
+public:
+ explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
+ static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
- uint32_t GlobalImports = 0;
- uint32_t FunctionImports = 0;
- std::unique_ptr<WasmObjectFile> WasmObj;
+ void parse() override;
+ std::unique_ptr<llvm::lto::InputFile> Obj;
};
+// Will report a fatal() error if the input buffer is not a valid bitcode
+// or was object file.
+InputFile *createObjectFile(MemoryBufferRef MB);
+
// Opens a given file.
llvm::Optional<MemoryBufferRef> readFile(StringRef Path);