[WebAssembly] Create synthetic __wasm_call_ctors function
This change create a new synthetic function in the final
output binary which calls the static constructors in sequence.
See: https://github.com/WebAssembly/tool-conventions/issues/25
Differential Revision: https://reviews.llvm.org/D41893
llvm-svn: 322388
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 0059e56..0173cdc 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -291,15 +291,16 @@
error("undefined symbols specified for relocatable output file");
if (!Config->Relocatable) {
- if (!Config->Entry.empty()) {
- static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
+ static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
+ if (!Config->Entry.empty())
addSyntheticUndefinedFunction(Config->Entry, &Signature);
- }
// Handle the `--undefined <sym>` options.
for (StringRef S : args::getStrings(Args, OPT_undefined))
addSyntheticUndefinedFunction(S, nullptr);
+ Config->CtorSymbol = Symtab->addDefinedFunction(
+ "__wasm_call_ctors", &Signature, WASM_SYMBOL_VISIBILITY_HIDDEN);
Config->StackPointerSymbol = Symtab->addDefinedGlobal("__stack_pointer");
}