Fix dex location of boot oat files during preopt
Dex location should reflect the path on target when preopting
on host. This previously did not hold and this patch fixes the
issue. Other paths remain the same as before. A DCHECK is added
to class linker to guarantee that -Xboot-classpath-locations is
not ignored.
Simultaneously it refactors the logic for resolving a relative
path to make it clearer which path is used for opening files
(dex file name) and which reflects the location on target (dex
location), as these differ when preopting.
The patch also adds a missing dex2oat dependency for oat_file_test.
Test: test-art-gtest-{host,target}-oat_file_test
Test: compiles, no DCHECK crashes
Change-Id: I0629c7ee505b5fd50649800bb3e08efc1ee44102
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 6fdac3f..658fec3 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1077,6 +1077,14 @@
error_msg)) {
return false;
}
+ // Assert that if absolute boot classpath locations were provided, they were
+ // assigned to the loaded dex files.
+ if (kIsDebugBuild && IsAbsoluteLocation(boot_class_path_locations[i])) {
+ for (const auto& dex_file : dex_files) {
+ DCHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation()),
+ boot_class_path_locations[i]);
+ }
+ }
// Append opened dex files at the end.
boot_dex_files_.insert(boot_dex_files_.end(),
std::make_move_iterator(dex_files.begin()),
@@ -2027,10 +2035,8 @@
for (int32_t i = 0; i < dex_caches->GetLength(); i++) {
ObjPtr<mirror::DexCache> dex_cache = dex_caches->Get(i);
- std::string dex_file_location(dex_cache->GetLocation()->ToModifiedUtf8());
- // TODO: Only store qualified paths.
- // If non qualified, qualify it.
- dex_file_location = OatFile::ResolveRelativeEncodedDexLocation(dex_location, dex_file_location);
+ std::string dex_file_location = dex_cache->GetLocation()->ToModifiedUtf8();
+ DCHECK_EQ(dex_location, DexFileLoader::GetBaseLocation(dex_file_location));
std::unique_ptr<const DexFile> dex_file = OpenOatDexFile(oat_file,
dex_file_location.c_str(),
error_msg);