diff options
-rw-r--r-- | dex2oat/linker/image_test.h | 17 | ||||
-rw-r--r-- | dex2oat/linker/oat_writer.cc | 16 | ||||
-rw-r--r-- | dex2oat/linker/oat_writer_test.cc | 11 | ||||
-rw-r--r-- | runtime/vdex_file.h | 18 |
4 files changed, 44 insertions, 18 deletions
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h index cedbccf7cc..85145d3d64 100644 --- a/dex2oat/linker/image_test.h +++ b/dex2oat/linker/image_test.h @@ -293,14 +293,7 @@ inline void CompilationHelper::Compile(CompilerDriver* driver, 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 @@ inline void CompilationHelper::Compile(CompilerDriver* driver, 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; diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index 293078acee..b5c5d98c11 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -2742,10 +2742,6 @@ bool OatWriter::WriteQuickeningInfo(OutputStream* vdex_out) { size_t initial_offset = vdex_size_; size_t start_offset = RoundUp(initial_offset, 4u); - vdex_size_ = start_offset; - vdex_quickening_info_offset_ = vdex_size_; - size_quickening_info_alignment_ = start_offset - initial_offset; - off_t actual_offset = vdex_out->Seek(start_offset, kSeekSet); if (actual_offset != static_cast<off_t>(start_offset)) { PLOG(ERROR) << "Failed to seek to quickening info section. Actual: " << actual_offset @@ -2789,7 +2785,16 @@ bool OatWriter::WriteQuickeningInfo(OutputStream* vdex_out) { size_quickening_info_ = 0; } - vdex_size_ += size_quickening_info_; + if (size_quickening_info_ == 0) { + // Nothing was written. Leave `vdex_size_` untouched and unaligned. + vdex_quickening_info_offset_ = initial_offset; + size_quickening_info_alignment_ = 0; + } else { + vdex_size_ = start_offset + size_quickening_info_; + vdex_quickening_info_offset_ = start_offset; + size_quickening_info_alignment_ = start_offset - initial_offset; + } + return true; } @@ -3864,6 +3869,7 @@ bool OatWriter::WriteChecksumsAndVdexHeader(OutputStream* vdex_out) { DCHECK_NE(vdex_dex_files_offset_, 0u); DCHECK_NE(vdex_verifier_deps_offset_, 0u); + DCHECK_NE(vdex_quickening_info_offset_, 0u); size_t dex_section_size = vdex_verifier_deps_offset_ - vdex_dex_files_offset_; size_t verifier_deps_section_size = vdex_quickening_info_offset_ - vdex_verifier_deps_offset_; diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc index fec05cc393..e9958b129a 100644 --- a/dex2oat/linker/oat_writer_test.cc +++ b/dex2oat/linker/oat_writer_test.cc @@ -45,6 +45,7 @@ #include "oat_writer.h" #include "scoped_thread_state_change-inl.h" #include "utils/test_dex_file_builder.h" +#include "vdex_file.h" namespace art { namespace linker { @@ -225,6 +226,9 @@ class OatTest : public CommonCompilerTest { if (!oat_writer.WriteVerifierDeps(vdex_out.get(), nullptr)) { return false; } + if (!oat_writer.WriteQuickeningInfo(vdex_out.get())) { + return false; + } if (!oat_writer.WriteChecksumsAndVdexHeader(vdex_out.get())) { return false; } @@ -652,6 +656,13 @@ void OatTest::TestDexFileInput(bool verify, bool low_4gb, bool use_profile) { &opened_dex_file2->GetHeader(), dex_file2_data->GetHeader().file_size_)); ASSERT_EQ(dex_file2_data->GetLocation(), opened_dex_file2->GetLocation()); + + const VdexFile::Header &vdex_header = opened_oat_file->GetVdexFile()->GetHeader(); + ASSERT_EQ(vdex_header.GetQuickeningInfoSize(), 0u); + + int64_t actual_vdex_size = vdex_file.GetFile()->GetLength(); + ASSERT_GE(actual_vdex_size, 0); + ASSERT_EQ((uint64_t) actual_vdex_size, vdex_header.GetComputedFileSize()); } TEST_F(OatTest, DexFileInputCheckOutput) { diff --git a/runtime/vdex_file.h b/runtime/vdex_file.h index 3e0882693a..2d9fcab59c 100644 --- a/runtime/vdex_file.h +++ b/runtime/vdex_file.h @@ -68,6 +68,18 @@ class VdexFile { uint32_t GetQuickeningInfoSize() const { return quickening_info_size_; } uint32_t GetNumberOfDexFiles() const { return number_of_dex_files_; } + size_t GetComputedFileSize() const { + return sizeof(Header) + + GetSizeOfChecksumsSection() + + GetDexSize() + + GetVerifierDepsSize() + + GetQuickeningInfoSize(); + } + + size_t GetSizeOfChecksumsSection() const { + return sizeof(VdexChecksum) * GetNumberOfDexFiles(); + } + static constexpr uint8_t kVdexInvalidMagic[] = { 'w', 'd', 'e', 'x' }; private: @@ -172,17 +184,13 @@ class VdexFile { } const uint8_t* DexBegin() const { - return Begin() + sizeof(Header) + GetSizeOfChecksumsSection(); + return Begin() + sizeof(Header) + GetHeader().GetSizeOfChecksumsSection(); } const uint8_t* DexEnd() const { return DexBegin() + GetHeader().GetDexSize(); } - size_t GetSizeOfChecksumsSection() const { - return sizeof(VdexChecksum) * GetHeader().GetNumberOfDexFiles(); - } - uint32_t GetDexFileIndex(const DexFile& dex_file) const; std::unique_ptr<MemMap> mmap_; |