summaryrefslogtreecommitdiffstats
path: root/lld/wasm/MarkLive.cpp
diff options
context:
space:
mode:
authorNicholas Wilson <nicholas@nicholaswilson.me.uk>2018-03-09 17:06:38 +0000
committerNicholas Wilson <nicholas@nicholaswilson.me.uk>2018-03-09 17:06:38 +0000
commit2e55ee77e2b9f0d13d4a85852059d258a697cc5c (patch)
treec2c9a682be796a44cb9062b61cdc17fc77403718 /lld/wasm/MarkLive.cpp
parent95d9ccb2a0542d79ecf40f14784be20f96b494b1 (diff)
downloadbcm5719-llvm-2e55ee77e2b9f0d13d4a85852059d258a697cc5c.tar.gz
bcm5719-llvm-2e55ee77e2b9f0d13d4a85852059d258a697cc5c.zip
[WebAssembly] Handle weak undefined functions with a synthetic stub
This error case is described in Linking.md. The operand for call requires generation of a synthetic stub. Differential Revision: https://reviews.llvm.org/D44028 llvm-svn: 327151
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