[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/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 8706698..284630e 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -119,6 +119,22 @@
         " in " + F.getName());
 }
 
+Symbol *SymbolTable::addDefinedFunction(StringRef Name,
+                                        const WasmSignature *Type,
+                                        uint32_t Flags) {
+  DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n");
+  Symbol *S;
+  bool WasInserted;
+  std::tie(S, WasInserted) = insert(Name);
+  if (WasInserted) {
+    S->update(Symbol::DefinedFunctionKind, nullptr, Flags);
+    S->setFunctionType(Type);
+  } else if (!S->isFunction()) {
+    error("symbol type mismatch: " + Name);
+  }
+  return S;
+}
+
 Symbol *SymbolTable::addDefinedGlobal(StringRef Name) {
   DEBUG(dbgs() << "addDefinedGlobal: " << Name << "\n");
   Symbol *S;