summaryrefslogtreecommitdiff
path: root/wasm/Symbols.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wasm/Symbols.cpp')
-rw-r--r--wasm/Symbols.cpp52
1 files changed, 48 insertions, 4 deletions
diff --git a/wasm/Symbols.cpp b/wasm/Symbols.cpp
index a11081cbcf779..4bef9761ec250 100644
--- a/wasm/Symbols.cpp
+++ b/wasm/Symbols.cpp
@@ -10,6 +10,7 @@
#include "Symbols.h"
#include "Config.h"
#include "InputChunks.h"
+#include "InputEvent.h"
#include "InputFiles.h"
#include "InputGlobal.h"
#include "OutputSegment.h"
@@ -27,7 +28,9 @@ DefinedFunction *WasmSym::CallCtors;
DefinedData *WasmSym::DsoHandle;
DefinedData *WasmSym::DataEnd;
DefinedData *WasmSym::HeapBase;
-DefinedGlobal *WasmSym::StackPointer;
+GlobalSymbol *WasmSym::StackPointer;
+UndefinedGlobal *WasmSym::TableBase;
+UndefinedGlobal *WasmSym::MemoryBase;
WasmSymbolType Symbol::getWasmType() const {
if (isa<FunctionSymbol>(this))
@@ -36,6 +39,8 @@ WasmSymbolType Symbol::getWasmType() const {
return WASM_SYMBOL_TYPE_DATA;
if (isa<GlobalSymbol>(this))
return WASM_SYMBOL_TYPE_GLOBAL;
+ if (isa<EventSymbol>(this))
+ return WASM_SYMBOL_TYPE_EVENT;
if (isa<SectionSymbol>(this))
return WASM_SYMBOL_TYPE_SECTION;
llvm_unreachable("invalid symbol kind");
@@ -52,6 +57,8 @@ InputChunk *Symbol::getChunk() const {
bool Symbol::isLive() const {
if (auto *G = dyn_cast<DefinedGlobal>(this))
return G->Global->Live;
+ if (auto *E = dyn_cast<DefinedEvent>(this))
+ return E->Event->Live;
if (InputChunk *C = getChunk())
return C->Live;
return Referenced;
@@ -60,6 +67,8 @@ bool Symbol::isLive() const {
void Symbol::markLive() {
if (auto *G = dyn_cast<DefinedGlobal>(this))
G->Global->Live = true;
+ if (auto *E = dyn_cast<DefinedEvent>(this))
+ E->Event->Live = true;
if (InputChunk *C = getChunk())
C->Live = true;
Referenced = true;
@@ -105,7 +114,10 @@ bool Symbol::isExported() const {
if (ForceExport || Config->ExportAll)
return true;
- return !isHidden();
+ if (Config->ExportDynamic && !isHidden())
+ return true;
+
+ return false;
}
uint32_t FunctionSymbol::getFunctionIndex() const {
@@ -207,6 +219,32 @@ DefinedGlobal::DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
Global ? &Global->getType() : nullptr),
Global(Global) {}
+uint32_t EventSymbol::getEventIndex() const {
+ if (auto *F = dyn_cast<DefinedEvent>(this))
+ return F->Event->getEventIndex();
+ assert(EventIndex != INVALID_INDEX);
+ return EventIndex;
+}
+
+void EventSymbol::setEventIndex(uint32_t Index) {
+ LLVM_DEBUG(dbgs() << "setEventIndex " << Name << " -> " << Index << "\n");
+ assert(EventIndex == INVALID_INDEX);
+ EventIndex = Index;
+}
+
+bool EventSymbol::hasEventIndex() const {
+ if (auto *F = dyn_cast<DefinedEvent>(this))
+ return F->Event->hasEventIndex();
+ return EventIndex != INVALID_INDEX;
+}
+
+DefinedEvent::DefinedEvent(StringRef Name, uint32_t Flags, InputFile *File,
+ InputEvent *Event)
+ : EventSymbol(Name, DefinedEventKind, Flags, File,
+ Event ? &Event->getType() : nullptr,
+ Event ? &Event->Signature : nullptr),
+ Event(Event) {}
+
uint32_t SectionSymbol::getOutputSectionIndex() const {
LLVM_DEBUG(dbgs() << "getOutputSectionIndex: " << getName() << "\n");
assert(OutputSectionIndex != INVALID_INDEX);
@@ -223,10 +261,14 @@ void SectionSymbol::setOutputSectionIndex(uint32_t Index) {
void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
std::string lld::toString(const wasm::Symbol &Sym) {
+ return lld::maybeDemangleSymbol(Sym.getName());
+}
+
+std::string lld::maybeDemangleSymbol(StringRef Name) {
if (Config->Demangle)
- if (Optional<std::string> S = demangleItanium(Sym.getName()))
+ if (Optional<std::string> S = demangleItanium(Name))
return *S;
- return Sym.getName();
+ return Name;
}
std::string lld::toString(wasm::Symbol::Kind Kind) {
@@ -237,6 +279,8 @@ std::string lld::toString(wasm::Symbol::Kind Kind) {
return "DefinedData";
case wasm::Symbol::DefinedGlobalKind:
return "DefinedGlobal";
+ case wasm::Symbol::DefinedEventKind:
+ return "DefinedEvent";
case wasm::Symbol::UndefinedFunctionKind:
return "UndefinedFunction";
case wasm::Symbol::UndefinedDataKind: