Write ELF image to Oat file.

(cherry picked from commit 1c84f1fd7570974bec8660cd17e0118be529afce)

Change-Id: I322579095009a09ab9ad8d2e7d7c309a5530718c
diff --git a/src/oat.cc b/src/oat.cc
index d8d01df..b3333c2 100644
--- a/src/oat.cc
+++ b/src/oat.cc
@@ -29,6 +29,7 @@
 
 OatHeader::OatHeader(InstructionSet instruction_set,
                      const std::vector<const DexFile*>* dex_files,
+                     uint32_t elf_image_count,
                      uint32_t image_file_location_checksum,
                      const std::string& image_file_location) {
   memcpy(magic_, kOatMagic, sizeof(kOatMagic));
@@ -42,6 +43,9 @@
   dex_file_count_ = dex_files->size();
   UpdateChecksum(&dex_file_count_, sizeof(dex_file_count_));
 
+  elf_image_count_ = elf_image_count;
+  UpdateChecksum(&elf_image_count_, sizeof(elf_image_count_));
+
   image_file_location_checksum_ = image_file_location_checksum;
   UpdateChecksum(&image_file_location_checksum_, sizeof(image_file_location_checksum_));
 
@@ -49,6 +53,7 @@
   UpdateChecksum(&image_file_location_size_, sizeof(image_file_location_size_));
   UpdateChecksum(image_file_location.data(), image_file_location_size_);
 
+  elf_image_table_offset_ = 0;
   executable_offset_ = 0;
 }
 
@@ -72,6 +77,16 @@
   return dex_file_count_;
 }
 
+uint32_t OatHeader::GetElfImageCount() const {
+  DCHECK(IsValid());
+  return elf_image_count_;
+}
+
+uint32_t OatHeader::GetElfImageTableOffset() const {
+  DCHECK(IsValid());
+  return elf_image_table_offset_;
+}
+
 uint32_t OatHeader::GetChecksum() const {
   CHECK(IsValid());
   return adler32_checksum_;
@@ -116,6 +131,12 @@
                      GetImageFileLocationSize());
 }
 
+void OatHeader::SetElfImageTableOffset(uint32_t elf_image_table_offset) {
+  DCHECK(IsValid());
+  elf_image_table_offset_ = elf_image_table_offset;
+  UpdateChecksum(&elf_image_table_offset_, sizeof(elf_image_table_offset_));
+}
+
 void OatHeader::SetExecutableOffset(uint32_t executable_offset) {
   DCHECK_ALIGNED(executable_offset, kPageSize);
   CHECK_GT(executable_offset, sizeof(OatHeader));