From 10c13565474de2786aad7c2e79757ea250747a15 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 25 Nov 2015 14:33:36 +0000 Subject: Refactor oat file writing to give Dex2Oat more control. This is the first step towards writing dex files to oat file and mapping them from there for the actual AOT compilation. Change-Id: Icb0d27487eaf6ba3a66c157e695f9bdc5bb9cf9a --- compiler/elf_builder.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'compiler/elf_builder.h') diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h index 6e8dfd60fb..c19bc3db5c 100644 --- a/compiler/elf_builder.h +++ b/compiler/elf_builder.h @@ -27,6 +27,7 @@ #include "elf_utils.h" #include "file_output_stream.h" #include "leb128.h" +#include "utils/array_ref.h" namespace art { @@ -100,7 +101,7 @@ class ElfBuilder FINAL { header_.sh_entsize = entsize; } - virtual ~Section() { + ~Section() OVERRIDE { if (started_) { CHECK(finished_); } @@ -187,6 +188,12 @@ class ElfBuilder FINAL { return owner_->Seek(offset, whence); } + // This function flushes the output and returns whether it succeeded. + // If there was a previous failure, this does nothing and returns false, i.e. failed. + bool Flush() OVERRIDE { + return owner_->Flush(); + } + Elf_Word GetSectionIndex() const { DCHECK(started_); DCHECK_NE(section_index_, 0u); @@ -312,7 +319,7 @@ class ElfBuilder FINAL { // Encode patch locations as LEB128 list of deltas between consecutive addresses. // (exposed publicly for tests) - static void EncodeOatPatches(const std::vector& locations, + static void EncodeOatPatches(const ArrayRef& locations, std::vector* buffer) { buffer->reserve(buffer->size() + locations.size() * 2); // guess 2 bytes per ULEB128. uintptr_t address = 0; // relative to start of section. @@ -323,9 +330,9 @@ class ElfBuilder FINAL { } } - void WritePatches(const char* name, const std::vector* patch_locations) { + void WritePatches(const char* name, const ArrayRef& patch_locations) { std::vector buffer; - EncodeOatPatches(*patch_locations, &buffer); + EncodeOatPatches(patch_locations, &buffer); std::unique_ptr
s(new Section(this, name, SHT_OAT_PATCH, 0, nullptr, 0, 1, 0)); s->Start(); s->WriteFully(buffer.data(), buffer.size()); @@ -385,6 +392,7 @@ class ElfBuilder FINAL { Seek(0, kSeekSet); WriteFully(&elf_header, sizeof(elf_header)); WriteFully(phdrs.data(), phdrs.size() * sizeof(phdrs[0])); + Flush(); } // The running program does not have access to section headers @@ -509,6 +517,13 @@ class ElfBuilder FINAL { return new_offset; } + bool Flush() { + if (output_good_) { + output_good_ = output_->Flush(); + } + return output_good_; + } + static Elf_Ehdr MakeElfHeader(InstructionSet isa) { Elf_Ehdr elf_header = Elf_Ehdr(); switch (isa) { -- cgit v1.2.3-59-g8ed1b