summaryrefslogtreecommitdiff
path: root/dex2oat/linker/oat_writer.h
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2025-03-07 17:13:16 +0000
committer Jiakai Zhang <jiakaiz@google.com> 2025-03-11 06:45:45 -0700
commit4370b86853f0fdf16f0e957365c6b600e5b32fe2 (patch)
treea9e3bc73df56cf8f9270b56688ede9d0ac06417e /dex2oat/linker/oat_writer.h
parenta6a75dba00303a88642a1c57ad2ed390797adf47 (diff)
Ensure oat checksum determinism across hosts and devices.
For Cloud Compilation, we need to enable hosts to generate a boot image that has exactly the same checksum as generated on device. In other words, we need to make the oat checksum deterministic across hosts and devices. To achieve that, when writing the oat header, the non-deterministic fields are padded to their length limits and excluded from the oat checksum computation. Bug: 372868052 Test: m test-art-host-gtest Test: Generate a boot image on host. See the checksum being identical to the one on device. Change-Id: I9f73a28b349b673c25909b61a0c7ae8cf883c014
Diffstat (limited to 'dex2oat/linker/oat_writer.h')
-rw-r--r--dex2oat/linker/oat_writer.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/dex2oat/linker/oat_writer.h b/dex2oat/linker/oat_writer.h
index 5a775fa517..4f50b1a39c 100644
--- a/dex2oat/linker/oat_writer.h
+++ b/dex2oat/linker/oat_writer.h
@@ -70,6 +70,29 @@ enum class CopyOption {
kOnlyIfCompressed
};
+class OatKeyValueStore {
+ public:
+ // Puts a key value pair whose key is in `OatHeader::kNonDeterministicFieldsAndLengths`.
+ bool PutNonDeterministic(const std::string& k,
+ const std::string& v,
+ bool allow_truncation = false);
+
+ // Puts a key value pair whose key is in `OatHeader::kDeterministicFields`.
+ void Put(const std::string& k, const std::string& v);
+
+ // Puts a key value pair whose key is in `OatHeader::kDeterministicFields`.
+ void Put(const std::string& k, bool v);
+
+ // Makes sure calls with `const char*` falls into the overload for `std::string`, not the one for
+ // `bool`.
+ void Put(const std::string& k, const char* v) { Put(k, std::string(v)); }
+
+ private:
+ SafeMap<std::string, std::string> map_;
+
+ friend class OatWriter;
+};
+
// OatHeader variable length with count of D OatDexFiles
//
// TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile.
@@ -167,7 +190,7 @@ class OatWriter {
// Start writing .rodata, including supporting data structures for dex files.
bool StartRoData(const std::vector<const DexFile*>& dex_files,
OutputStream* oat_rodata,
- SafeMap<std::string, std::string>* key_value_store);
+ OatKeyValueStore* key_value_store);
// Initialize the writer with the given parameters.
void Initialize(const CompilerDriver* compiler_driver,
const VerificationResults* verification_results,
@@ -291,7 +314,7 @@ class OatWriter {
void WriteVerifierDeps(verifier::VerifierDeps* verifier_deps,
/*out*/std::vector<uint8_t>* buffer);
- size_t InitOatHeader(uint32_t num_dex_files, SafeMap<std::string, std::string>* key_value_store);
+ size_t InitOatHeader(uint32_t num_dex_files, OatKeyValueStore* key_value_store);
size_t InitClassOffsets(size_t offset);
size_t InitOatClasses(size_t offset);
size_t InitOatMaps(size_t offset);