aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
diff options
context:
space:
mode:
authorAndy Wingo <wingo@igalia.com>2020-12-08 13:55:19 +0100
committerAndy Wingo <wingo@igalia.com>2021-01-05 11:09:24 +0100
commit9ad83fd6dc46330dcdea8af36c435061a31ac0c5 (patch)
tree9d03183a780e58bc165f20b9a822b24c91225f40 /llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
parent53a341a61d1fc2d0c455738a6a4d5f5d54a4e1d3 (diff)
downloadllvm-9ad83fd6dc46330dcdea8af36c435061a31ac0c5.zip
llvm-9ad83fd6dc46330dcdea8af36c435061a31ac0c5.tar.gz
llvm-9ad83fd6dc46330dcdea8af36c435061a31ac0c5.tar.bz2
[WebAssembly] call_indirect causes indirect function table import
For wasm-ld table linking work to proceed, object files should indicate if they use an indirect function table. In the future this will be done by the usual symbols and relocations mechanism, but until that support lands in the linker, the presence of an `__indirect_function_table` in the object file's import section shows that the object file needs an indirect function table. Prior to https://reviews.llvm.org/D91637, this condition was met by all object files residualizing an `__indirect_function_table` import. Since https://reviews.llvm.org/D91637, the intention has been that only those object files needing an indirect function table would have the `__indirect_function_table` import. However, we missed the case of object files which use the table via `call_indirect` but which themselves do not declare any indirect functions. This changeset makes it so that when we lower a call to `call_indirect`, that we ensure that a `__indirect_function_table` symbol is present and that it will be propagated to the linker. A followup patch will revise this mechanism to make an explicit link between `call_indirect` and its associated indirect function table; see https://reviews.llvm.org/D90948. Differential Revision: https://reviews.llvm.org/D92840
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 949564e..903a8e2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -20,12 +20,14 @@
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyTargetMachine.h"
+#include "WebAssemblyUtilities.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/CodeGen/FastISel.h"
#include "llvm/CodeGen/FunctionLoweringInfo.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
@@ -878,6 +880,15 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
// Add placeholders for the type index and immediate flags
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();
}
for (unsigned ArgReg : Args)