summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-10-04 16:14:16 +0200
committer VladimĂ­r Marko <vmarko@google.com> 2024-10-07 12:01:13 +0000
commitf758d6a7530324ca95a69d551ce48f9a0cc9014c (patch)
tree8391a29d8303ac032263b0c8b9af4e09d2e28922
parentd576392c76d75335d8284217f2153bdace62b355 (diff)
Fix `VerificationResults` use in `OatWriter`.
Since https://android-review.googlesource.com/2236075 the `OatWriter` has been using a null `VerificationResults` because `CreateOatWriters()` is called before initializing the `verification_results_` in `Dex2Oat`. As the `OatWriter` is using it only to select between two `ClassStatus` values that currently lead to the very same behavior in the `ClassLinker::VerifyClassUsingOatFile()` (but with different comments and therefore prone to diverging), this did not yet lead to any observable difference in behavior. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing. Change-Id: I3f0b67497358ac98b4980691f80044a5b0f0fc17
-rw-r--r--dex2oat/dex2oat.cc4
-rw-r--r--dex2oat/linker/image_test.h3
-rw-r--r--dex2oat/linker/oat_writer.cc5
-rw-r--r--dex2oat/linker/oat_writer.h4
-rw-r--r--dex2oat/linker/oat_writer_test.cc18
-rw-r--r--runtime/class_linker.cc2
6 files changed, 14 insertions, 22 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 06d3770abd..bcc51182b7 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2100,7 +2100,8 @@ class Dex2Oat final {
for (size_t i = 0, size = oat_files_.size(); i != size; ++i) {
std::unique_ptr<linker::OatWriter>& oat_writer = oat_writers_[i];
std::vector<const DexFile*>& dex_files = dex_files_per_oat_file_[i];
- oat_writer->Initialize(driver_.get(), image_writer_.get(), dex_files);
+ oat_writer->Initialize(
+ driver_.get(), verification_results_.get(), image_writer_.get(), dex_files);
}
if (!use_existing_vdex_) {
@@ -2648,7 +2649,6 @@ class Dex2Oat final {
bool do_oat_writer_layout = DoOatLayoutOptimizations();
oat_writers_.emplace_back(new linker::OatWriter(
*compiler_options_,
- verification_results_.get(),
timings_,
do_oat_writer_layout ? profile_compilation_info_.get() : nullptr));
}
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index 71e7f4de19..3706b685fa 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -245,7 +245,6 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode,
elf_writers.emplace_back(CreateElfWriterQuick(*compiler_options_, oat_file.GetFile()));
elf_writers.back()->Start();
oat_writers.emplace_back(new OatWriter(*compiler_options_,
- verification_results_.get(),
&timings,
/*profile_compilation_info*/nullptr));
}
@@ -300,7 +299,7 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode,
rodata[i],
(i == 0u) ? &key_value_store : nullptr);
ASSERT_TRUE(start_rodata_ok);
- oat_writer->Initialize(driver, writer.get(), cur_dex_files);
+ oat_writer->Initialize(driver, verification_results_.get(), writer.get(), cur_dex_files);
oat_writer->FinishVdexFile(out_helper.vdex_files[i].GetFile(), /*verifier_deps=*/ nullptr);
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 0ea446a0a2..4a3e2837bd 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -344,14 +344,13 @@ class OatWriter::OatDexFile {
<< "file_offset=" << file_offset << " offset_=" << offset_
OatWriter::OatWriter(const CompilerOptions& compiler_options,
- const VerificationResults* verification_results,
TimingLogger* timings,
ProfileCompilationInfo* info)
: write_state_(WriteState::kAddingDexFileSources),
timings_(timings),
compiler_driver_(nullptr),
compiler_options_(compiler_options),
- verification_results_(verification_results),
+ verification_results_(nullptr),
image_writer_(nullptr),
extract_dex_files_into_vdex_(true),
vdex_begin_(nullptr),
@@ -573,10 +572,12 @@ bool OatWriter::StartRoData(const std::vector<const DexFile*>& dex_files,
// Initialize the writer with the given parameters.
void OatWriter::Initialize(const CompilerDriver* compiler_driver,
+ const VerificationResults* verification_results,
ImageWriter* image_writer,
const std::vector<const DexFile*>& dex_files) {
CHECK(write_state_ == WriteState::kInitialize);
compiler_driver_ = compiler_driver;
+ verification_results_ = verification_results;
image_writer_ = image_writer;
dex_files_ = &dex_files;
write_state_ = WriteState::kPrepareLayout;
diff --git a/dex2oat/linker/oat_writer.h b/dex2oat/linker/oat_writer.h
index f2b239252c..129a791982 100644
--- a/dex2oat/linker/oat_writer.h
+++ b/dex2oat/linker/oat_writer.h
@@ -115,7 +115,6 @@ enum class CopyOption {
class OatWriter {
public:
OatWriter(const CompilerOptions& compiler_options,
- const VerificationResults* verification_results,
TimingLogger* timings,
ProfileCompilationInfo* info);
@@ -171,6 +170,7 @@ class OatWriter {
SafeMap<std::string, std::string>* key_value_store);
// Initialize the writer with the given parameters.
void Initialize(const CompilerDriver* compiler_driver,
+ const VerificationResults* verification_results,
ImageWriter* image_writer,
const std::vector<const DexFile*>& dex_files);
bool FinishVdexFile(File* vdex_file, verifier::VerifierDeps* verifier_deps);
@@ -376,7 +376,7 @@ class OatWriter {
const CompilerDriver* compiler_driver_;
const CompilerOptions& compiler_options_;
- const VerificationResults* const verification_results_;
+ const VerificationResults* verification_results_;
ImageWriter* image_writer_;
// Whether the dex files being compiled are going to be extracted to the vdex.
bool extract_dex_files_into_vdex_;
diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc
index 8486bff0d3..a905294360 100644
--- a/dex2oat/linker/oat_writer_test.cc
+++ b/dex2oat/linker/oat_writer_test.cc
@@ -106,10 +106,7 @@ class OatTest : public CommonCompilerDriverTest {
bool verify) {
TimingLogger timings("WriteElf", false, false);
ClearBootImageOption();
- OatWriter oat_writer(*compiler_options_,
- verification_results_.get(),
- &timings,
- /*profile_compilation_info*/nullptr);
+ OatWriter oat_writer(*compiler_options_, &timings, /*profile_compilation_info*/nullptr);
for (const DexFile* dex_file : dex_files) {
if (!oat_writer.AddRawDexFileSource(dex_file->GetContainer(),
dex_file->Begin(),
@@ -131,10 +128,7 @@ class OatTest : public CommonCompilerDriverTest {
ProfileCompilationInfo* profile_compilation_info) {
TimingLogger timings("WriteElf", false, false);
ClearBootImageOption();
- OatWriter oat_writer(*compiler_options_,
- verification_results_.get(),
- &timings,
- profile_compilation_info);
+ OatWriter oat_writer(*compiler_options_, &timings, profile_compilation_info);
for (const char* dex_filename : dex_filenames) {
if (!oat_writer.AddDexFileSource(dex_filename, dex_filename)) {
return false;
@@ -153,10 +147,7 @@ class OatTest : public CommonCompilerDriverTest {
ProfileCompilationInfo* profile_compilation_info = nullptr) {
TimingLogger timings("WriteElf", false, false);
ClearBootImageOption();
- OatWriter oat_writer(*compiler_options_,
- verification_results_.get(),
- &timings,
- profile_compilation_info);
+ OatWriter oat_writer(*compiler_options_, &timings, profile_compilation_info);
if (!oat_writer.AddDexFileSource(std::move(dex_file_fd), location)) {
return false;
}
@@ -200,7 +191,8 @@ class OatTest : public CommonCompilerDriverTest {
if (!oat_writer.StartRoData(dex_files, oat_rodata, &key_value_store)) {
return false;
}
- oat_writer.Initialize(compiler_driver_.get(), /*image_writer=*/ nullptr, dex_files);
+ oat_writer.Initialize(
+ compiler_driver_.get(), verification_results_.get(), /*image_writer=*/ nullptr, dex_files);
if (!oat_writer.FinishVdexFile(vdex_file, /*verifier_deps=*/ nullptr)) {
return false;
}
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index cad968dfc2..b23a543b5d 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5165,7 +5165,7 @@ bool ClassLinker::VerifyClassUsingOatFile(Thread* self,
return true;
}
if (oat_file_class_status >= ClassStatus::kVerifiedNeedsAccessChecks) {
- // We return that the clas has already been verified, and the caller should
+ // We return that the class has already been verified, and the caller should
// check the class status to ensure we run with access checks.
return true;
}