Fix VDEX header when no quickening info

When there is no quickening info to be written, the OatWriter logic
wrongly assumes that padding was written to align the file size to
32 bits. The file is therefore shorter than the size calculated from
header data. This patch fixes that.

Additionally, it enforces that OatWriter::WriteQuickeningInfo is
always called, which was not the case with some of our tests. This
requirement was already mentioned in OatWriter comments but not
adhered to.

Test: m test-art-host-gtest
Bug: 70267762
Change-Id: If25600761677efba173d7cac02931e71c6260f9d
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index cedbccf..85145d3 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -293,14 +293,7 @@
       bool image_space_ok = writer->PrepareImageAddressSpace();
       ASSERT_TRUE(image_space_ok);
 
-      for (size_t i = 0, size = vdex_files.size(); i != size; ++i) {
-        std::unique_ptr<BufferedOutputStream> vdex_out =
-            std::make_unique<BufferedOutputStream>(
-                std::make_unique<FileOutputStream>(vdex_files[i].GetFile()));
-        oat_writers[i]->WriteVerifierDeps(vdex_out.get(), nullptr);
-        oat_writers[i]->WriteChecksumsAndVdexHeader(vdex_out.get());
-      }
-
+      DCHECK_EQ(vdex_files.size(), oat_files.size());
       for (size_t i = 0, size = oat_files.size(); i != size; ++i) {
         MultiOatRelativePatcher patcher(driver->GetInstructionSet(),
                                         driver->GetInstructionSetFeatures());
@@ -308,6 +301,14 @@
         ElfWriter* const elf_writer = elf_writers[i].get();
         std::vector<const DexFile*> cur_dex_files(1u, class_path[i]);
         oat_writer->Initialize(driver, writer.get(), cur_dex_files);
+
+        std::unique_ptr<BufferedOutputStream> vdex_out =
+            std::make_unique<BufferedOutputStream>(
+                std::make_unique<FileOutputStream>(vdex_files[i].GetFile()));
+        oat_writer->WriteVerifierDeps(vdex_out.get(), nullptr);
+        oat_writer->WriteQuickeningInfo(vdex_out.get());
+        oat_writer->WriteChecksumsAndVdexHeader(vdex_out.get());
+
         oat_writer->PrepareLayout(&patcher);
         size_t rodata_size = oat_writer->GetOatHeader().GetExecutableOffset();
         size_t text_size = oat_writer->GetOatSize() - rodata_size;