Update image oat checksum when patching
Change-Id: I766d2745bc817a5cb3a36d62bc733bab43a31fe0
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 007b8a6..b96db3e 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -707,7 +707,7 @@
uint32_t image_oat_checksum = image_header.GetOatChecksum();
if (oat_checksum != image_oat_checksum) {
LOG(ERROR) << "Failed to match oat file checksum " << std::hex << oat_checksum
- << " to expected oat checksum " << std::hex << oat_checksum
+ << " to expected oat checksum " << std::hex << image_oat_checksum
<< " in image";
return NULL;
}
diff --git a/src/image.h b/src/image.h
index 399b143..852367d 100644
--- a/src/image.h
+++ b/src/image.h
@@ -71,6 +71,10 @@
return oat_checksum_;
}
+ void SetOatChecksum(uint32_t oat_checksum) {
+ oat_checksum_ = oat_checksum;
+ }
+
byte* GetOatBegin() const {
return reinterpret_cast<byte*>(oat_begin_);
}
diff --git a/src/image_writer.cc b/src/image_writer.cc
index 56dfa5e..497ca22 100644
--- a/src/image_writer.cc
+++ b/src/image_writer.cc
@@ -676,6 +676,10 @@
AbstractMethod* target = GetTargetMethod(patch);
SetPatchLocation(patch, reinterpret_cast<uint32_t>(GetImageAddress(target)));
}
+
+ // Update the image header with the new checksum after patching
+ ImageHeader* image_header = reinterpret_cast<ImageHeader*>(image_->Begin());
+ image_header->SetOatChecksum(oat_file_->GetOatHeader().GetChecksum());
}
void ImageWriter::SetPatchLocation(const Compiler::PatchInformation* patch, uint32_t value) {
@@ -683,6 +687,7 @@
AbstractMethod* method = GetReferrerMethod(patch);
// Goodbye const, we are about to modify some code.
void* code = const_cast<void*>(class_linker->GetOatCodeFor(method));
+ OatHeader& oat_header = const_cast<OatHeader&>(oat_file_->GetOatHeader());
// TODO: make this Thumb2 specific
uint8_t* base = reinterpret_cast<uint8_t*>(reinterpret_cast<uint32_t>(code) & ~0x1);
uint32_t* patch_location = reinterpret_cast<uint32_t*>(base + patch->GetLiteralOffset());
@@ -696,6 +701,7 @@
<< "value=" << value;
#endif
*patch_location = value;
+ oat_header.UpdateChecksum(patch_location, sizeof(value));
}
} // namespace art