summaryrefslogtreecommitdiffstats
path: root/lld/wasm/MarkLive.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/wasm/MarkLive.cpp')
-rw-r--r--lld/wasm/MarkLive.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index 22211c11edf..9b72697277c 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -73,8 +73,25 @@ void lld::wasm::markLive() {
InputChunk *C = Q.pop_back_val();
for (const WasmRelocation Reloc : C->getRelocations()) {
- if (Reloc.Type != R_WEBASSEMBLY_TYPE_INDEX_LEB)
- Enqueue(C->File->getSymbol(Reloc.Index));
+ if (Reloc.Type == R_WEBASSEMBLY_TYPE_INDEX_LEB)
+ continue;
+ Symbol *Sym = C->File->getSymbol(Reloc.Index);
+
+ // If the function has been assigned the special index zero in the table,
+ // the relocation doesn't pull in the function body, since the function
+ // won't actually go in the table (the runtime will trap attempts to call
+ // that index, since we don't use it). A function with a table index of
+ // zero is only reachable via "call", not via "call_indirect". The stub
+ // functions used for weak-undefined symbols have this behaviour (compare
+ // equal to null pointer, only reachable via direct call).
+ if (Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_SLEB ||
+ Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_I32) {
+ FunctionSymbol *FuncSym = cast<FunctionSymbol>(Sym);
+ if (FuncSym->hasTableIndex() && FuncSym->getTableIndex() == 0)
+ continue;
+ }
+
+ Enqueue(Sym);
}
}
OpenPOWER on IntegriCloud