[WebAssembly] Initialize memory in start function

Summary:
 - `__wasm_init_memory` is now the WebAssembly start function instead
   of being called from `__wasm_call_ctors` or called directly by the
   runtime.
 - Adds a new synthetic data symbol `__wasm_init_memory_flag` that is
   atomically incremented from zero to one by the thread responsible
   for initializing memory.
 - All threads now unconditionally perform data.drop on all passive
   segments.
 - Removes --passive-segments and --active-segments flags and controls
   segment type based on --shared-memory instead. The deleted flags
   were only present to ameliorate the upgrade path in Emscripten.

Reviewers: sbc100, aheejin

Subscribers: dschuff, jgravelle-google, sunfish, jfb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65783

llvm-svn: 370965
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index 7656689..98267d1 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -50,8 +50,6 @@
     // function.  However, this function does not contain relocations so we
     // have to manually mark the ctors as live if callCtors itself is live.
     if (sym == WasmSym::callCtors) {
-      if (config->passiveSegments)
-        enqueue(WasmSym::initMemory);
       if (config->isPic)
         enqueue(WasmSym::applyRelocs);
       for (const ObjFile *obj : symtab->objectFiles) {
@@ -86,6 +84,9 @@
   if (config->isPic)
     enqueue(WasmSym::callCtors);
 
+  if (config->sharedMemory && !config->shared)
+    enqueue(WasmSym::initMemory);
+
   // Follow relocations to mark all reachable chunks.
   while (!q.empty()) {
     InputChunk *c = q.pop_back_val();