diff options
author | Andy Wingo <wingo@igalia.com> | 2021-02-12 11:22:13 +0100 |
---|---|---|
committer | Andy Wingo <wingo@igalia.com> | 2021-02-22 10:13:36 +0100 |
commit | 861dbe1a021e6439af837b72b219fb9c449a57ae (patch) | |
tree | 6afa4286c0f944c3078e6b245ffec22bf2d4e35d /llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp | |
parent | f10137399a3c9239a6acd1d3df12a40766b64759 (diff) | |
download | llvm-861dbe1a021e6439af837b72b219fb9c449a57ae.zip llvm-861dbe1a021e6439af837b72b219fb9c449a57ae.tar.gz llvm-861dbe1a021e6439af837b72b219fb9c449a57ae.tar.bz2 |
[WebAssembly] call_indirect issues table number relocs
If the reference-types feature is enabled, call_indirect will explicitly
reference its corresponding function table via `TABLE_NUMBER`
relocations against a table symbol.
Also, as before, address-taken functions can also cause the function
table to be created, only with reference-types they additionally cause a
symbol table entry to be emitted.
We abuse the used-in-reloc flag on symbols to indicate which tables
should end up in the symbol table. We do this because unfortunately
older wasm-ld will carp if it see a table symbol.
Differential Revision: https://reviews.llvm.org/D90948
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp index 509f2be..d60c162 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp @@ -869,19 +869,20 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) { if (IsDirect) { MIB.addGlobalAddress(Func); } else { - // Add placeholders for the type index and immediate flags + // Placehoder for the type index. MIB.addImm(0); - MIB.addImm(0); - - // Ensure that the object file has a __indirect_function_table import, as we - // call_indirect against it. - MCSymbolWasm *Sym = WebAssembly::getOrCreateFunctionTableSymbol( - MF->getMMI().getContext(), "__indirect_function_table"); - // Until call_indirect emits TABLE_NUMBER relocs against this symbol, mark - // it as NO_STRIP so as to ensure that the indirect function table makes it - // to linked output. - Sym->setNoStrip(); - + // The table into which this call_indirect indexes. + MCSymbolWasm *Table = WebAssembly::getOrCreateFunctionTableSymbol( + MF->getMMI().getContext(), Subtarget); + if (Subtarget->hasReferenceTypes()) { + MIB.addSym(Table); + } else { + // Otherwise for the MVP there is at most one table whose number is 0, but + // we can't write a table symbol or issue relocations. Instead we just + // ensure the table is live. + Table->setNoStrip(); + MIB.addImm(0); + } // See if we must truncate the function pointer. // CALL_INDIRECT takes an i32, but in wasm64 we represent function pointers // as 64-bit for uniformity with other pointer types. |