summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2024-04-02 16:36:05 +0000
committer Jiakai Zhang <jiakaiz@google.com> 2024-04-03 17:35:44 +0000
commit738911f0e21de7f9312d3af626459d3e336dd855 (patch)
tree9fbb223aca8b315a17c86d4febc54d99539a41b1
parenta4e0034c3acf5bf69b5e122dcfb77e3a61ff283c (diff)
Don't copy dex code for plain dex files.
The runtime doesn't expect the copied dex code for plain dex files, causing it to fail to load the odex/vdex files. Bug: 331124531 Change-Id: Ibfe4ac55f763ef4a601d0c471ea74632d959e433 Test: Presubmit Test: m test-art-host-gtest-art_dex2oat_tests
-rw-r--r--dex2oat/dex2oat_test.cc27
-rw-r--r--dex2oat/linker/oat_writer.cc2
-rw-r--r--libdexfile/dex/dex_file_loader.cc2
3 files changed, 28 insertions, 3 deletions
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 4a8a4f3c65..c4be5747cd 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1662,7 +1662,7 @@ TEST_F(Dex2oatTest, CompactDexGenerationFailure) {
ASSERT_TRUE(GenerateOdexForTest(temp_dex.GetFilename(),
oat_filename,
CompilerFilter::Filter::kVerify,
- {},
+ {"--copy-dex-files=always"},
/*expect_success=*/true,
/*use_fd=*/false,
/*use_zip_fd=*/false,
@@ -2091,6 +2091,31 @@ TEST_F(Dex2oatTest, DexFileFd) {
/*use_zip_fd=*/true));
}
+TEST_F(Dex2oatTest, DontCopyPlainDex) {
+ std::unique_ptr<const DexFile> dex(OpenTestDexFile("VerifierDepsMulti"));
+ std::string error_msg;
+ const std::string out_dir = GetScratchDir();
+ const std::string dex_location = dex->GetLocation();
+ const std::string odex_location = out_dir + "/base.oat";
+ const std::string vdex_location = out_dir + "/base.vdex";
+ ASSERT_TRUE(GenerateOdexForTest(dex_location,
+ odex_location,
+ CompilerFilter::Filter::kVerify,
+ {},
+ /*expect_success=*/true,
+ /*use_fd=*/false,
+ /*use_zip_fd=*/false,
+ [](const OatFile&) {}));
+
+ // Check that the vdex doesn't have dex code.
+ std::unique_ptr<VdexFile> vdex(VdexFile::Open(vdex_location,
+ /*writable=*/false,
+ /*low_4gb=*/false,
+ &error_msg));
+ ASSERT_TRUE(vdex != nullptr);
+ EXPECT_FALSE(vdex->HasDexSection()) << output_;
+}
+
TEST_F(Dex2oatTest, AppImageResolveStrings) {
using Hotness = ProfileCompilationInfo::MethodHotness;
// Create a profile with the startup method marked.
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index c6e861bf76..adbdda0e05 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -3201,7 +3201,7 @@ bool OatWriter::WriteDexFiles(File* file,
extract_dex_files_into_vdex_ = false;
for (OatDexFile& oat_dex_file : oat_dex_files_) {
const DexFileContainer* container = oat_dex_file.GetDexFile()->GetContainer().get();
- if (!(container->IsZip() && container->IsFileMap())) {
+ if (!container->IsFileMap()) {
extract_dex_files_into_vdex_ = true;
break;
}
diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
index daefa2f0dd..d524dfceb1 100644
--- a/libdexfile/dex/dex_file_loader.cc
+++ b/libdexfile/dex/dex_file_loader.cc
@@ -342,7 +342,7 @@ bool DexFileLoader::MapRootContainer(std::string* error_msg) {
DCHECK(!error_msg->empty());
return false;
}
- root_container_ = std::make_shared<MemMapContainer>(std::move(map));
+ root_container_ = std::make_shared<MemMapContainer>(std::move(map), /*is_file_map=*/true);
return true;
}