From cb6a5916cce4f18c7183fa8731446a084fb28fe5 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Thu, 19 Jan 2017 10:53:59 +0000 Subject: Revert^3 "Remove unused code for patching oat files." This reverts commit e7ec8b25dd6ac1b8ad8a68f808048bd6a61138f0. Because tests are failing. Bug: 33192586 Change-Id: I3e575c6c037873195c2177241153e3646d58e8a6 --- patchoat/patchoat.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'patchoat/patchoat.h') diff --git a/patchoat/patchoat.h b/patchoat/patchoat.h index e15a6bc695..a51963127a 100644 --- a/patchoat/patchoat.h +++ b/patchoat/patchoat.h @@ -44,7 +44,17 @@ class Class; class PatchOat { public: - static bool Patch(const std::string& image_location, + // Patch only the oat file + static bool Patch(File* oat_in, off_t delta, File* oat_out, TimingLogger* timings, + bool output_oat_opened_from_fd, // Was this using --oatput-oat-fd ? + bool new_oat_out); // Output oat was a new file created by us? + + // Patch only the image (art file) + static bool Patch(const std::string& art_location, off_t delta, File* art_out, InstructionSet isa, + TimingLogger* timings); + + // Patch both the image and the oat file + static bool Patch(const std::string& art_location, off_t delta, const std::string& output_directory, InstructionSet isa, @@ -54,11 +64,18 @@ class PatchOat { PatchOat(PatchOat&&) = default; private: - // All pointers are only borrowed. - PatchOat(InstructionSet isa, MemMap* image, + // Takes ownership only of the ElfFile. All other pointers are only borrowed. + PatchOat(ElfFile* oat_file, off_t delta, TimingLogger* timings) + : oat_file_(oat_file), image_(nullptr), bitmap_(nullptr), heap_(nullptr), delta_(delta), + isa_(kNone), space_map_(nullptr), timings_(timings) {} + PatchOat(InstructionSet isa, MemMap* image, gc::accounting::ContinuousSpaceBitmap* bitmap, + MemMap* heap, off_t delta, TimingLogger* timings) + : image_(image), bitmap_(bitmap), heap_(heap), + delta_(delta), isa_(isa), space_map_(nullptr), timings_(timings) {} + PatchOat(InstructionSet isa, ElfFile* oat_file, MemMap* image, gc::accounting::ContinuousSpaceBitmap* bitmap, MemMap* heap, off_t delta, std::map>* map, TimingLogger* timings) - : image_(image), bitmap_(bitmap), heap_(heap), + : oat_file_(oat_file), image_(image), bitmap_(bitmap), heap_(heap), delta_(delta), isa_(isa), space_map_(map), timings_(timings) {} // Was the .art image at image_path made with --compile-pic ? @@ -77,7 +94,9 @@ class PatchOat { // Attempt to replace the file with a symlink // Returns false if it fails static bool ReplaceOatFileWithSymlink(const std::string& input_oat_filename, - const std::string& output_oat_filename); + const std::string& output_oat_filename, + bool output_oat_opened_from_fd, + bool new_oat_out); // Output oat was newly created? static void BitmapCallback(mirror::Object* obj, void* arg) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -89,6 +108,13 @@ class PatchOat { void FixupMethod(ArtMethod* object, ArtMethod* copy) REQUIRES_SHARED(Locks::mutator_lock_); + // Patches oat in place, modifying the oat_file given to the constructor. + bool PatchElf(); + template + bool PatchElf(ElfFileImpl* oat_file); + template + bool PatchOatHeader(ElfFileImpl* oat_file); + bool PatchImage(bool primary_image) REQUIRES_SHARED(Locks::mutator_lock_); void PatchArtFields(const ImageHeader* image_header) REQUIRES_SHARED(Locks::mutator_lock_); void PatchArtMethods(const ImageHeader* image_header) REQUIRES_SHARED(Locks::mutator_lock_); @@ -102,6 +128,7 @@ class PatchOat { void PatchDexFileArrays(mirror::ObjectArray* img_roots) REQUIRES_SHARED(Locks::mutator_lock_); + bool WriteElf(File* out); bool WriteImage(File* out); template @@ -148,6 +175,19 @@ class PatchOat { return reinterpret_cast(ret); } + template + T RelocatedAddressOfIntPointer(T obj) const { + if (obj == 0) { + return obj; + } + T ret = obj + delta_; + // Trim off high bits in case negative relocation with 64 bit patchoat. + if (Is32BitISA()) { + ret = static_cast(static_cast(ret)); + } + return ret; + } + bool Is32BitISA() const { return InstructionSetPointerSize(isa_) == PointerSize::k32; } @@ -173,6 +213,8 @@ class PatchOat { mirror::Object* const copy_; }; + // The elf file we are patching. + std::unique_ptr oat_file_; // A mmap of the image we are patching. This is modified. const MemMap* const image_; // The bitmap over the image within the heap we are patching. This is not modified. -- cgit v1.2.3-59-g8ed1b