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;
|
|
|
|
class InputSegment;
|
2018-01-10 07:56:44 +08:00
|
|
|
class InputFunction;
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
class Symbol {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
DefinedFunctionKind,
|
|
|
|
DefinedGlobalKind,
|
|
|
|
|
|
|
|
LazyKind,
|
|
|
|
UndefinedFunctionKind,
|
|
|
|
UndefinedGlobalKind,
|
|
|
|
|
|
|
|
LastDefinedKind = DefinedGlobalKind,
|
|
|
|
InvalidKind,
|
|
|
|
};
|
|
|
|
|
2018-01-10 08:52:20 +08:00
|
|
|
Symbol(StringRef Name, uint32_t Flags)
|
|
|
|
: WrittenToSymtab(0), WrittenToNameSec(0), 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; }
|
|
|
|
|
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);
|
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-09 07:39:11 +08:00
|
|
|
uint32_t getTableIndex() const { return TableIndex.getValue(); }
|
|
|
|
|
2017-12-12 06:00:56 +08:00
|
|
|
// Returns true if a table index has been set for this symbol
|
|
|
|
bool hasTableIndex() const { return TableIndex.hasValue(); }
|
|
|
|
|
|
|
|
// 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,
|
2017-11-30 09:40:08 +08:00
|
|
|
const InputSegment *Segment = nullptr,
|
2018-01-10 08:52:20 +08:00
|
|
|
const InputFunction *Function = 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; }
|
|
|
|
|
|
|
|
// This bit is used by Writer::writeNameSection() to prevent
|
|
|
|
// symbols from being written to the symbol table more than once.
|
|
|
|
unsigned WrittenToSymtab : 1;
|
|
|
|
unsigned WrittenToNameSec : 1;
|
|
|
|
|
|
|
|
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;
|
|
|
|
const InputSegment *Segment = nullptr;
|
2018-01-10 07:56:44 +08:00
|
|
|
const InputFunction *Function = 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
|
|
|
};
|
|
|
|
|
|
|
|
} // 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
|