From f8980875ef8fb0ce86be4ed2c0af7070f5ae9cfd Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Fri, 22 May 2015 17:04:47 +0100 Subject: Split .oat_patches to multiple sections. .oat_patches section currently contains encoded patch locations for several other sections. Split it to several sections - one for each of the destination sections. For example, .text.oat_patches section contains patch locations for the .text section. This ensures that if we strip some the sections using standard tools, we strip the corresponding .oat_patches section as well. It also makes the overall design simpler. I should have done it this way in the first place. Since ApplyOatPatches has been simplified and uses unaligned memory access, this also fixes bug 21403573. Bug:20556771 Bug:21403573 Change-Id: Iae7c423911507b524eec500e8d61744046fcd3ba --- compiler/elf_builder.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'compiler/elf_builder.h') diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h index 8a63a4882f..730d780f6b 100644 --- a/compiler/elf_builder.h +++ b/compiler/elf_builder.h @@ -168,6 +168,10 @@ class ElfBuilder FINAL { patched_(false), patch_(patch), patch_base_section_(patch_base_section) { } + RawSection(const std::string& name, Elf_Word type) + : RawSection(name, type, 0, nullptr, 0, 1, 0, nullptr, nullptr) { + } + Elf_Word GetSize() const OVERRIDE { return buffer_.size(); } @@ -779,10 +783,12 @@ class ElfBuilder FINAL { template static bool WriteArray(File* elf_file, const T* data, size_t count) { - DCHECK(data != nullptr); - if (!elf_file->WriteFully(data, count * sizeof(T))) { - PLOG(ERROR) << "Failed to write to file " << elf_file->GetPath(); - return false; + if (count != 0) { + DCHECK(data != nullptr); + if (!elf_file->WriteFully(data, count * sizeof(T))) { + PLOG(ERROR) << "Failed to write to file " << elf_file->GetPath(); + return false; + } } return true; } -- cgit v1.2.3-59-g8ed1b