diff options
author | 2025-03-11 14:39:13 +0000 | |
---|---|---|
committer | 2025-03-11 11:10:41 -0700 | |
commit | 11a5d95861c061ca65ecbf28597e2176a5448c8b (patch) | |
tree | 62bfec0b42538cc36c78ed806e6f0d70532311eb | |
parent | ca2362c05e2fc05f9211e39ecb74857195b27780 (diff) |
Fix --oat-location for mainline boot image extension.
dex2oat uses the basename of the oat location to determine the soname of
the oat file in the ELF header.
- If the output is specified by "--oat-file", dex2oat takes the oat
location from "--oat-file" and uses it as is.
- If the output is specified by "--oat-fd", dex2oat takes the oat
location from "--oat-location", and for boot image extensions, dex2oat
expends the oat location with the name of the first input dex file.
For the mainline boot image extension specifically, before this change,
odrefresh passes
"--oat-location=/data/misc/.../boot-framework-adservices.oat", so
dex2oat expends it to
"boot-framework-adservices-framework-adservices.oat".
This is unexpected, and it causes a discrepancy between odrefresh and
Cloud Compilation. Cloud Compilation is typically performed on host,
with the output specified by "--oat-file", so the soname of the mainline
boot image extension is "boot-framework-adservices.oat". This
discrepancy causes all the offsets in the oat file to differ.
After this change, odrefresh passes
"--oat-location=/data/misc/.../boot.oat", so the soname after expansion
is "boot-framework-adservices.oat", which is correct.
Bug: 372868052
Test: Generate a mainline boot image extension on host. See the checksum
being identical to the one on device.
Change-Id: I9bfd165a9505e889c3da7d4bc408f9a4f2e52714
-rw-r--r-- | odrefresh/odrefresh.cc | 10 | ||||
-rw-r--r-- | odrefresh/odrefresh_test.cc | 30 |
2 files changed, 30 insertions, 10 deletions
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc index fc782bc697..92912b7bfa 100644 --- a/odrefresh/odrefresh.cc +++ b/odrefresh/odrefresh.cc @@ -1762,7 +1762,6 @@ WARN_UNUSED CompilationResult OnDeviceRefresh::RunDex2oat( } } - args.Add("--oat-location=%s", artifacts.OatPath()); std::pair<std::string, const char*> location_kind_pairs[] = { std::make_pair(artifacts.ImagePath(), artifacts.ImageKind()), std::make_pair(artifacts.OatPath(), "oat"), @@ -1910,9 +1909,16 @@ OnDeviceRefresh::RunDex2oatForBootClasspath(const std::string& staging_dir, preloaded_classes_file, strerror(errno))); } + args.Add("--oat-location=%s", OdrArtifacts::ForBootImage(output_path).OatPath()); } else { // Mainline extension. args.Add("--compiler-filter=%s", kMainlineCompilerFilter); + // For boot image extensions, dex2oat takes the oat location of the primary boot image and + // expends it with the name of the first input dex file. + args.Add("--oat-location=%s", + OdrArtifacts::ForBootImage( + GetPrimaryBootImagePath(/*on_system=*/false, /*minimal=*/false, isa)) + .OatPath()); } const OdrSystemProperties& system_properties = config_.GetSystemProperties(); @@ -2080,6 +2086,8 @@ WARN_UNUSED CompilationResult OnDeviceRefresh::RunDex2oatForSystemServer( args.Add("--class-loader-context-fds=%s", Join(fds, ':')); } + args.Add("--oat-location=%s", OdrArtifacts::ForSystemServer(output_path).OatPath()); + const OdrSystemProperties& system_properties = config_.GetSystemProperties(); args.AddRuntimeIfNonEmpty("-Xms%s", system_properties.GetOrEmpty("dalvik.vm.dex2oat-Xms")) .AddRuntimeIfNonEmpty("-Xmx%s", system_properties.GetOrEmpty("dalvik.vm.dex2oat-Xmx")); diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc index b19a4225b4..7f4e990ffe 100644 --- a/odrefresh/odrefresh_test.cc +++ b/odrefresh/odrefresh_test.cc @@ -48,12 +48,14 @@ namespace art { namespace odrefresh { +using ::android::base::Basename; using ::android::base::Split; using ::android::modules::sdklevel::IsAtLeastU; using ::testing::_; using ::testing::AllOf; using ::testing::Contains; using ::testing::ElementsAre; +using ::testing::EndsWith; using ::testing::Not; using ::testing::ResultOf; using ::testing::Return; @@ -336,7 +338,7 @@ TEST_F(OdRefreshTest, BootImageMainlineExtension) { FdOf(framework_jar_), FdOf(conscrypt_jar_), FdOf(framework_wifi_jar_)))), - Contains(Flag("--oat-location=", dalvik_cache_dir_ + "/x86_64/boot-conscrypt.oat")), + Contains(Flag("--oat-location=", dalvik_cache_dir_ + "/x86_64/boot.oat")), Not(Contains(Flag("--base=", _))), Contains(Flag("--boot-image=", _)), Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_)))))) @@ -435,11 +437,15 @@ TEST_F(OdRefreshTest, BootClasspathJarsFallback) { } TEST_F(OdRefreshTest, AllSystemServerJars) { - EXPECT_CALL(*mock_exec_utils_, - DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", location_provider_jar_)), - Contains("--class-loader-context=PCL[]"), - Not(Contains(Flag("--class-loader-context-fds=", _))), - Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_)))))) + EXPECT_CALL( + *mock_exec_utils_, + DoExecAndReturnCode(AllOf( + Contains(Flag("--dex-file=", location_provider_jar_)), + Contains("--class-loader-context=PCL[]"), + Not(Contains(Flag("--class-loader-context-fds=", _))), + Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))), + Contains(Flag("--oat-location=", + EndsWith("@" + Basename(location_provider_jar_) + "@classes.odex")))))) .WillOnce(Return(0)); EXPECT_CALL( *mock_exec_utils_, @@ -447,7 +453,9 @@ TEST_F(OdRefreshTest, AllSystemServerJars) { Contains(Flag("--dex-file=", services_jar_)), Contains(Flag("--class-loader-context=", ART_FORMAT("PCL[{}]", location_provider_jar_))), Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))), - Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_)))))) + Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))), + Contains( + Flag("--oat-location=", EndsWith("@" + Basename(services_jar_) + "@classes.odex")))))) .WillOnce(Return(0)); EXPECT_CALL( *mock_exec_utils_, @@ -457,7 +465,9 @@ TEST_F(OdRefreshTest, AllSystemServerJars) { ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))), Contains(ListFlag("--class-loader-context-fds=", ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))), - Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_)))))) + Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))), + Contains(Flag("--oat-location=", + EndsWith("@" + Basename(services_foo_jar_) + "@classes.odex")))))) .WillOnce(Return(0)); EXPECT_CALL( *mock_exec_utils_, @@ -467,7 +477,9 @@ TEST_F(OdRefreshTest, AllSystemServerJars) { ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))), Contains(ListFlag("--class-loader-context-fds=", ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))), - Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_)))))) + Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))), + Contains(Flag("--oat-location=", + EndsWith("@" + Basename(services_bar_jar_) + "@classes.odex")))))) .WillOnce(Return(0)); EXPECT_EQ( |