[WebAssembly] Add option to emit passive segments

Summary:
Adds `--passive-segments` and `--active-segments` flags to control
what kind of segments are emitted. For now the default is always
to emit active segments so this is not a breaking change, but in
the future the default will be changed to passive segments when
shared memory is requested and active segments otherwise. When
passive segments are emitted, corresponding memory.init and
data.drop instructions are emitted in a `__wasm_init_memory`
function that is automatically called at the beginning of
`__wasm_call_ctors`.

Reviewers: sbc100, aheejin, dschuff

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

Tags: #llvm

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

llvm-svn: 365088
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index b3dce23..0826492 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -50,6 +50,10 @@
     // 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->Pic)
+        Enqueue(WasmSym::ApplyRelocs);
       for (const ObjFile *Obj : Symtab->ObjectFiles) {
         const WasmLinkingData &L = Obj->getWasmObj()->linkingData();
         for (const WasmInitFunc &F : L.InitFunctions) {
@@ -79,10 +83,8 @@
     }
   }
 
-  if (Config->Pic) {
+  if (Config->Pic)
     Enqueue(WasmSym::CallCtors);
-    Enqueue(WasmSym::ApplyRelocs);
-  }
 
   // Follow relocations to mark all reachable chunks.
   while (!Q.empty()) {