2017-11-18 02:14:09 +08:00
|
|
|
//===- Symbols.h ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_WASM_SYMBOLS_H
|
|
|
|
#define LLD_WASM_SYMBOLS_H
|
|
|
|
|
|
|
|
#include "lld/Common/LLVM.h"
|
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/Wasm.h"
|
|
|
|
|
|
|
|
using llvm::object::Archive;
|
2017-12-01 10:11:29 +08:00
|
|
|
using llvm::wasm::WasmSignature;
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
class InputFile;
|
2018-01-29 03:57:01 +08:00
|
|
|
class InputChunk;
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
class Symbol {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
DefinedFunctionKind,
|
|
|
|
DefinedGlobalKind,
|
|
|
|
|
|
|
|
LazyKind,
|
|
|
|
UndefinedFunctionKind,
|
|
|
|
UndefinedGlobalKind,
|
|
|
|
|
|
|
|
LastDefinedKind = DefinedGlobalKind,
|
|
|
|
InvalidKind,
|
|
|
|
};
|
|
|
|
|
2018-01-18 04:19:04 +08:00
|
|
|
Symbol(StringRef Name, uint32_t Flags) : Flags(Flags), Name(Name) {}
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
Kind getKind() const { return SymbolKind; }
|
|
|
|
|
|
|
|
bool isLazy() const { return SymbolKind == LazyKind; }
|
|
|
|
bool isDefined() const { return SymbolKind <= LastDefinedKind; }
|
|
|
|
bool isUndefined() const {
|
|
|
|
return SymbolKind == UndefinedGlobalKind ||
|
|
|
|
SymbolKind == UndefinedFunctionKind;
|
|
|
|
}
|
|
|
|
bool isFunction() const {
|
|
|
|
return SymbolKind == DefinedFunctionKind ||
|
|
|
|
SymbolKind == UndefinedFunctionKind;
|
|
|
|
}
|
|
|
|
bool isGlobal() const { return !isFunction(); }
|
2018-01-10 08:52:20 +08:00
|
|
|
bool isLocal() const;
|
2017-11-18 02:14:09 +08:00
|
|
|
bool isWeak() const;
|
2017-12-03 10:38:04 +08:00
|
|
|
bool isHidden() const;
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
// Returns the symbol name.
|
|
|
|
StringRef getName() const { return Name; }
|
|
|
|
|
|
|
|
// Returns the file from which this symbol was created.
|
|
|
|
InputFile *getFile() const { return File; }
|
2018-01-29 03:57:01 +08:00
|
|
|
InputChunk *getChunk() const { return Chunk; }
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2017-12-07 11:19:53 +08:00
|
|
|
bool hasFunctionType() const { return FunctionType != nullptr; }
|
2017-11-30 09:40:08 +08:00
|
|
|
const WasmSignature &getFunctionType() const;
|
2018-01-10 07:56:44 +08:00
|
|
|
void setFunctionType(const WasmSignature *Type);
|
2018-01-13 06:10:35 +08:00
|
|
|
void setHidden(bool IsHidden);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-01-10 07:56:44 +08:00
|
|
|
uint32_t getOutputIndex() const;
|
2018-01-09 07:39:11 +08:00
|
|
|
|
|
|
|
// Returns true if an output index has been set for this symbol
|
2018-01-10 07:56:44 +08:00
|
|
|
bool hasOutputIndex() const;
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
// Set the output index of the symbol (in the function or global index
|
|
|
|
// space of the output object.
|
|
|
|
void setOutputIndex(uint32_t Index);
|
|
|
|
|
2018-01-25 05:45:25 +08:00
|
|
|
uint32_t getTableIndex() const;
|
2018-01-09 07:39:11 +08:00
|
|
|
|
2017-12-12 06:00:56 +08:00
|
|
|
// Returns true if a table index has been set for this symbol
|
2018-01-25 05:45:25 +08:00
|
|
|
bool hasTableIndex() const;
|
2017-12-12 06:00:56 +08:00
|
|
|
|
|
|
|
// Set the table index of the symbol
|
|
|
|
void setTableIndex(uint32_t Index);
|
|
|
|
|
2018-01-09 07:39:11 +08:00
|
|
|
// Returns the virtual address of a defined global.
|
|
|
|
// Only works for globals, not functions.
|
|
|
|
uint32_t getVirtualAddress() const;
|
|
|
|
|
2017-12-06 03:05:45 +08:00
|
|
|
void setVirtualAddress(uint32_t VA);
|
|
|
|
|
2018-01-10 08:52:20 +08:00
|
|
|
void update(Kind K, InputFile *F = nullptr, uint32_t Flags = 0,
|
2018-01-29 03:57:02 +08:00
|
|
|
InputChunk *chunk = nullptr, uint32_t Address = UINT32_MAX);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
void setArchiveSymbol(const Archive::Symbol &Sym) { ArchiveSymbol = Sym; }
|
|
|
|
const Archive::Symbol &getArchiveSymbol() { return ArchiveSymbol; }
|
|
|
|
|
|
|
|
protected:
|
2018-01-10 08:52:20 +08:00
|
|
|
uint32_t Flags;
|
|
|
|
uint32_t VirtualAddress = 0;
|
2017-11-30 09:40:08 +08:00
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
StringRef Name;
|
|
|
|
Archive::Symbol ArchiveSymbol = {nullptr, 0, 0};
|
|
|
|
Kind SymbolKind = InvalidKind;
|
|
|
|
InputFile *File = nullptr;
|
2018-01-29 03:57:01 +08:00
|
|
|
InputChunk *Chunk = nullptr;
|
2017-11-18 02:14:09 +08:00
|
|
|
llvm::Optional<uint32_t> OutputIndex;
|
2017-12-12 06:00:56 +08:00
|
|
|
llvm::Optional<uint32_t> TableIndex;
|
2018-01-10 07:56:44 +08:00
|
|
|
const WasmSignature *FunctionType = nullptr;
|
2017-11-18 02:14:09 +08:00
|
|
|
};
|
|
|
|
|
2018-02-03 06:59:56 +08:00
|
|
|
// linker-generated symbols
|
|
|
|
struct WasmSym {
|
|
|
|
// __stack_pointer
|
2018-02-07 11:04:53 +08:00
|
|
|
// Global that holds the address of the top of the explicit value stack in
|
|
|
|
// linear memory.
|
2018-02-03 06:59:56 +08:00
|
|
|
static Symbol *StackPointer;
|
|
|
|
|
2018-02-07 11:04:53 +08:00
|
|
|
// __data_end
|
|
|
|
// Symbol marking the end of the data and bss.
|
|
|
|
static Symbol *DataEnd;
|
|
|
|
|
2018-02-03 06:59:56 +08:00
|
|
|
// __heap_base
|
2018-02-07 11:04:53 +08:00
|
|
|
// Symbol marking the end of the data, bss and explicit stack. Any linear
|
|
|
|
// memory following this address is not used by the linked code and can
|
|
|
|
// therefore be used as a backing store for brk()/malloc() implementations.
|
2018-02-03 06:59:56 +08:00
|
|
|
static Symbol *HeapBase;
|
|
|
|
|
|
|
|
// __wasm_call_ctors
|
|
|
|
// Function that directly calls all ctors in priority order.
|
|
|
|
static Symbol *CallCtors;
|
|
|
|
|
|
|
|
// __dso_handle
|
|
|
|
// Global used in calls to __cxa_atexit to determine current DLL
|
|
|
|
static Symbol *DsoHandle;
|
|
|
|
};
|
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
} // namespace wasm
|
|
|
|
|
|
|
|
// Returns a symbol name for an error message.
|
2017-12-06 00:50:46 +08:00
|
|
|
std::string toString(const wasm::Symbol &Sym);
|
|
|
|
std::string toString(wasm::Symbol::Kind Kind);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|