[gen_snapshot] Fixes for x86 Flutter code push.

 - Don't set lazily native linking on IA32 as it produces calls to NULL.
 - Add --snapshot_kind=app to produce a new isolate snapshot without code and without rewriting the VM isolate.

Change-Id: I641dff10d9e89d16b84340b60b1133332a48977b
Reviewed-on: https://dart-review.googlesource.com/c/89043
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc
index a944899..3cb0462 100644
--- a/runtime/bin/gen_snapshot.cc
+++ b/runtime/bin/gen_snapshot.cc
@@ -72,6 +72,7 @@
   kCore,
   kCoreJIT,
   kCoreJITAll,
+  kApp,
   kAppJIT,
   kAppAOTBlobs,
   kAppAOTAssembly,
@@ -99,6 +100,7 @@
     "core",
     "core-jit",
     "core-jit-all",
+    "app",
     "app-jit",
     "app-aot-blobs",
     "app-aot-assembly",
@@ -298,6 +300,7 @@
       }
       break;
     }
+    case kApp:
     case kAppJIT: {
       if ((load_vm_snapshot_data_filename == NULL) ||
           (isolate_snapshot_data_filename == NULL) ||
@@ -453,6 +456,7 @@
       case kAppAOTAssembly:
         WriteDependenciesWithTarget(assembly_filename);
         break;
+      case kApp:
       case kAppJIT:
         WriteDependenciesWithTarget(isolate_snapshot_data_filename);
         // WriteDependenciesWithTarget(isolate_snapshot_instructions_filename);
@@ -603,11 +607,15 @@
   WriteFile(vm_snapshot_data_filename, vm_snapshot_data_buffer,
             vm_snapshot_data_size);
   if (vm_snapshot_instructions_filename != NULL) {
+    // Create empty file for the convenience of build systems. Makes things
+    // polymorphic with generating core-jit snapshots.
     WriteFile(vm_snapshot_instructions_filename, NULL, 0);
   }
   WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer,
             isolate_snapshot_data_size);
   if (isolate_snapshot_instructions_filename != NULL) {
+    // Create empty file for the convenience of build systems. Makes things
+    // polymorphic with generating core-jit snapshots.
     WriteFile(isolate_snapshot_instructions_filename, NULL, 0);
   }
 }
@@ -675,6 +683,27 @@
             isolate_snapshot_instructions_size);
 }
 
+static void CreateAndWriteAppSnapshot() {
+  ASSERT(snapshot_kind == kApp);
+  ASSERT(isolate_snapshot_data_filename != NULL);
+
+  Dart_Handle result;
+  uint8_t* isolate_snapshot_data_buffer = NULL;
+  intptr_t isolate_snapshot_data_size = 0;
+
+  result = Dart_CreateSnapshot(NULL, NULL, &isolate_snapshot_data_buffer,
+                               &isolate_snapshot_data_size);
+  CHECK_RESULT(result);
+
+  WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer,
+            isolate_snapshot_data_size);
+  if (isolate_snapshot_instructions_filename != NULL) {
+    // Create empty file for the convenience of build systems. Makes things
+    // polymorphic with generating core-jit snapshots.
+    WriteFile(isolate_snapshot_instructions_filename, NULL, 0);
+  }
+}
+
 static void CreateAndWriteAppJITSnapshot() {
   ASSERT(snapshot_kind == kAppJIT);
   ASSERT(isolate_snapshot_data_filename != NULL);
@@ -907,6 +936,9 @@
       LoadCompilationTrace();
       CreateAndWriteCoreJITSnapshot();
       break;
+    case kApp:
+      CreateAndWriteAppSnapshot();
+      break;
     case kAppJIT:
       LoadBytecode();
       LoadCompilationTrace();
@@ -990,7 +1022,9 @@
   } else if ((snapshot_kind == kCoreJITAll) || (snapshot_kind == kCoreJIT) ||
              (snapshot_kind == kAppJIT)) {
     vm_options.AddArgument("--fields_may_be_reset");
+#if !defined(TARGET_ARCH_IA32)
     vm_options.AddArgument("--link_natives_lazily");
+#endif
 #if !defined(PRODUCT)
     vm_options.AddArgument("--collect_code=false");
 #endif