diff options
author | paulgazz@chromium.org <paulgazz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 22:07:53 +0000 |
---|---|---|
committer | paulgazz@chromium.org <paulgazz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 22:07:53 +0000 |
commit | a8e80416be9ccd606ce54f7f192b91133bb23b98 (patch) | |
tree | 0972d2fe6b393a5e07e7a1267be5b616643b7eec /courgette/encoded_program.cc | |
parent | ba79a799579a5417511d472071e3f8fc5e2b67a5 (diff) | |
download | chromium_src-a8e80416be9ccd606ce54f7f192b91133bb23b98.zip chromium_src-a8e80416be9ccd606ce54f7f192b91133bb23b98.tar.gz chromium_src-a8e80416be9ccd606ce54f7f192b91133bb23b98.tar.bz2 |
Fixed Courgette to correctly regenerate the ELF relocation table for
ARM binaries.
Note for reviewers:
Don: general courgette correctness
Ben: style, correctness
BUG=258648
Review URL: https://chromiumcodereview.appspot.com/19022007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212449 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/encoded_program.cc')
-rw-r--r-- | courgette/encoded_program.cc | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc index 26cbf4b..b7c9b55 100644 --- a/courgette/encoded_program.cc +++ b/courgette/encoded_program.cc @@ -15,6 +15,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "courgette/courgette.h" +#include "courgette/disassembler_elf_32_arm.h" #include "courgette/streams.h" #include "courgette/types_elf.h" @@ -250,6 +251,10 @@ CheckBool EncodedProgram::AddElfMakeRelocs() { return ops_.push_back(MAKE_ELF_RELOCATION_TABLE); } +CheckBool EncodedProgram::AddElfARMMakeRelocs() { + return ops_.push_back(MAKE_ELF_ARM_RELOCATION_TABLE); +} + void EncodedProgram::DebuggingSummary() { VLOG(1) << "EncodedProgram Summary" << "\n image base " << image_base_ @@ -405,7 +410,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) { RVA current_rva = 0; bool pending_pe_relocation_table = false; - bool pending_elf_relocation_table = false; + Elf32_Word pending_elf_relocation_table_type = 0; SinkStream bytes_following_relocation_table; SinkStream* output = final_buffer; @@ -505,15 +510,28 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) { // emitting an ORIGIN after the MAKE_BASE_RELOCATION_TABLE. } + case MAKE_ELF_ARM_RELOCATION_TABLE: { + // We can see the base relocation anywhere, but we only have the + // information to generate it at the very end. So we divert the bytes + // we are generating to a temporary stream. + if (pending_elf_relocation_table_type) // Can't have two relocation + // tables. + return false; + + pending_elf_relocation_table_type = R_ARM_RELATIVE; + output = &bytes_following_relocation_table; + break; + } + case MAKE_ELF_RELOCATION_TABLE: { // We can see the base relocation anywhere, but we only have the // information to generate it at the very end. So we divert the bytes // we are generating to a temporary stream. - if (pending_elf_relocation_table) // Can't have two relocation - // tables. + if (pending_elf_relocation_table_type) // Can't have two relocation + // tables. return false; - pending_elf_relocation_table = true; + pending_elf_relocation_table_type = R_386_RELATIVE; output = &bytes_following_relocation_table; break; } @@ -526,8 +544,9 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) { return false; } - if (pending_elf_relocation_table) { - if (!GenerateElfRelocations(final_buffer) || + if (pending_elf_relocation_table_type) { + if (!GenerateElfRelocations(pending_elf_relocation_table_type, + final_buffer) || !final_buffer->Append(&bytes_following_relocation_table)) return false; } @@ -602,13 +621,13 @@ CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer) { return ok; } -CheckBool EncodedProgram::GenerateElfRelocations(SinkStream* buffer) { +CheckBool EncodedProgram::GenerateElfRelocations(Elf32_Word r_info, + SinkStream* buffer) { std::sort(abs32_relocs_.begin(), abs32_relocs_.end()); Elf32_Rel relocation_block; - // We only handle this specific type of relocation, so far. - relocation_block.r_info = R_386_RELATIVE; + relocation_block.r_info = r_info; bool ok = true; for (size_t i = 0; ok && i < abs32_relocs_.size(); ++i) { |