diff options
Diffstat (limited to 'dex2oat/dex2oat.cc')
-rw-r--r-- | dex2oat/dex2oat.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 6d861d4..d6501a1 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -45,6 +45,7 @@ #include "driver/compiler_driver.h" #include "driver/compiler_options.h" #include "elf_fixup.h" +#include "elf_patcher.h" #include "elf_stripper.h" #include "gc/space/image_space.h" #include "gc/space/space-inl.h" @@ -324,11 +325,28 @@ class Dex2Oat { return ReadImageClasses(image_classes_stream); } + bool PatchOatCode(const CompilerDriver* compiler_driver, File* oat_file, + const std::string& oat_location, std::string* error_msg) { + // We asked to include patch information but we are not making an image. We need to fix + // everything up manually. + std::unique_ptr<ElfFile> elf_file(ElfFile::Open(oat_file, PROT_READ|PROT_WRITE, + MAP_SHARED, error_msg)); + if (elf_file.get() == NULL) { + LOG(ERROR) << error_msg; + return false; + } + { + ReaderMutexLock mu(Thread::Current(), *Locks::mutator_lock_); + return ElfPatcher::Patch(compiler_driver, elf_file.get(), oat_location, error_msg); + } + } + const CompilerDriver* CreateOatFile(const std::string& boot_image_option, const std::string& android_root, bool is_host, const std::vector<const DexFile*>& dex_files, File* oat_file, + const std::string& oat_location, const std::string& bitcode_filename, bool image, std::unique_ptr<CompilerDriver::DescriptorSet>& image_classes, @@ -380,6 +398,7 @@ class Dex2Oat { std::string image_file_location; uint32_t image_file_location_oat_checksum = 0; uintptr_t image_file_location_oat_data_begin = 0; + int32_t image_patch_delta = 0; if (!driver->IsImage()) { TimingLogger::ScopedTiming t3("Loading image checksum", &timings); gc::space::ImageSpace* image_space = Runtime::Current()->GetHeap()->GetImageSpace(); @@ -387,6 +406,7 @@ class Dex2Oat { image_file_location_oat_data_begin = reinterpret_cast<uintptr_t>(image_space->GetImageHeader().GetOatDataBegin()); image_file_location = image_space->GetImageFilename(); + image_patch_delta = image_space->GetImageHeader().GetPatchDelta(); } if (!image_file_location.empty()) { @@ -395,6 +415,7 @@ class Dex2Oat { OatWriter oat_writer(dex_files, image_file_location_oat_checksum, image_file_location_oat_data_begin, + image_patch_delta, driver.get(), &timings, key_value_store); @@ -405,6 +426,16 @@ class Dex2Oat { return nullptr; } + if (!driver->IsImage() && driver->GetCompilerOptions().GetIncludePatchInformation()) { + t2.NewTiming("Patching ELF"); + std::string error_msg; + if (!PatchOatCode(driver.get(), oat_file, oat_location, &error_msg)) { + LOG(ERROR) << "Failed to fixup ELF file " << oat_file->GetPath(); + LOG(ERROR) << "Error was: " << error_msg; + return nullptr; + } + } + return driver.release(); } @@ -1361,6 +1392,7 @@ static int dex2oat(int argc, char** argv) { is_host, dex_files, oat_file.get(), + oat_location, bitcode_filename, image, image_classes, @@ -1370,7 +1402,6 @@ static int dex2oat(int argc, char** argv) { compiler_phases_timings, profile_file, key_value_store.get())); - if (compiler.get() == nullptr) { LOG(ERROR) << "Failed to create oat file: " << oat_location; return EXIT_FAILURE; @@ -1420,9 +1451,9 @@ static int dex2oat(int argc, char** argv) { // memory mapped so we could predict where its contents were based // on the file size. Now that it is an ELF file, we need to inspect // the ELF file to understand the in memory segment layout including - // where the oat header is located within. ImageWriter's - // PatchOatCodeAndMethods uses the PatchInformation from the - // Compiler to touch up absolute references in the oat file. + // where the oat header is located within. ElfPatcher's Patch method + // uses the PatchInformation from the Compiler to touch up absolute + // references in the oat file. // // 3. We fixup the ELF program headers so that dlopen will try to // load the .so at the desired location at runtime by offsetting the |