Add image dependency to oat files

Change-Id: I945356f71357f1aa0092f4fe6c57eccfb029b4a6
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index 1f02a44..f75aeb7 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -199,6 +199,7 @@
   }
 
   bool CreateOatFile(const std::string& boot_image_option,
+                     const std::string& host_prefix,
                      const std::vector<const DexFile*>& dex_files,
                      File* oat_file,
 #if defined(ART_USE_LLVM_COMPILER)
@@ -233,7 +234,24 @@
 
     compiler.CompileAll(class_loader->get(), dex_files);
 
-    if (!OatWriter::Create(oat_file, class_loader->get(), dex_files, compiler)) {
+    std::string image_file_location;
+    uint32_t image_file_location_checksum = 0;
+    Heap* heap = Runtime::Current()->GetHeap();
+    if (heap->GetSpaces().size() > 1) {
+      ImageSpace* image_space = heap->GetImageSpace();
+      image_file_location_checksum = image_space->GetImageHeader().GetOatChecksum();
+      image_file_location = image_space->GetImageFilename();
+      if (!host_prefix.empty() && StartsWith(image_file_location, host_prefix.c_str())) {
+        image_file_location = image_file_location.substr(host_prefix.size());
+      }
+    }
+
+    if (!OatWriter::Create(oat_file,
+                           class_loader->get(),
+                           dex_files,
+                           image_file_location_checksum,
+                           image_file_location,
+                           compiler)) {
       LOG(ERROR) << "Failed to create oat file " << oat_file->name();
       return false;
     }
@@ -687,6 +705,7 @@
   }
 
   if (!dex2oat->CreateOatFile(boot_image_option,
+                              host_prefix,
                               dex_files,
                               oat_file.get(),
 #if defined(ART_USE_LLVM_COMPILER)