summaryrefslogtreecommitdiffstats
path: root/courgette/encoded_program.cc
diff options
context:
space:
mode:
authorcsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 23:26:37 +0000
committercsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 23:26:37 +0000
commitf9e11f6d768d37ca829c2b84f34886ca21109990 (patch)
tree8a155f171684ea973343b77fa990e6cce40cc648 /courgette/encoded_program.cc
parent31cee2c4aa51b30ed1cf9f970bc2caa6b86575c6 (diff)
downloadchromium_src-f9e11f6d768d37ca829c2b84f34886ca21109990.zip
chromium_src-f9e11f6d768d37ca829c2b84f34886ca21109990.tar.gz
chromium_src-f9e11f6d768d37ca829c2b84f34886ca21109990.tar.bz2
Revert 108929 - Add Elf 32 Support to Courgette.
This change takes advantage of recent refactoring and adds support for Elf X86 32 executables to courgette. It should have no effect on handling of Windows PE executables. We have planned ahead to be able to restrict the code size of the courgette library in different cases to reduce patcher sizes, but this change does not yet take advantage of that (all platforms are supported everywhere). Also, the patcher class currently contains a very small amount of Elf/PE specific code for recreating relocation tables that cannot (currently) be compiled out. BUG=chromium-os:22149 TEST=Please verify that Chrome/Chromium patches can still be generated and work. Also, please see how much the updater executable which is downloaded to users has changed in size since R16. Review URL: http://codereview.chromium.org/8428009 TBR=dgarrett@chromium.org Review URL: http://codereview.chromium.org/8490023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108934 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/encoded_program.cc')
-rw-r--r--courgette/encoded_program.cc67
1 files changed, 12 insertions, 55 deletions
diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc
index b5e7310..a675dc2 100644
--- a/courgette/encoded_program.cc
+++ b/courgette/encoded_program.cc
@@ -16,7 +16,6 @@
#include "base/utf_string_conversions.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
-#include "courgette/types_elf.h"
namespace courgette {
@@ -242,12 +241,8 @@ CheckBool EncodedProgram::AddRel32(int label_index) {
return ops_.push_back(REL32) && rel32_ix_.push_back(label_index);
}
-CheckBool EncodedProgram::AddPeMakeRelocs() {
- return ops_.push_back(MAKE_PE_RELOCATION_TABLE);
-}
-
-CheckBool EncodedProgram::AddElfMakeRelocs() {
- return ops_.push_back(MAKE_ELF_RELOCATION_TABLE);
+CheckBool EncodedProgram::AddMakeRelocs() {
+ return ops_.push_back(MAKE_BASE_RELOCATION_TABLE);
}
void EncodedProgram::DebuggingSummary() {
@@ -404,9 +399,8 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
RVA current_rva = 0;
- bool pending_pe_relocation_table = false;
- bool pending_elf_relocation_table = false;
- SinkStream bytes_following_relocation_table;
+ bool pending_base_relocation_table = false;
+ SinkStream bytes_following_base_relocation_table;
SinkStream* output = final_buffer;
@@ -484,16 +478,16 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
break;
}
- case MAKE_PE_RELOCATION_TABLE: {
+ case MAKE_BASE_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_pe_relocation_table) // Can't have two base relocation
+ if (pending_base_relocation_table) // Can't have two base relocation
// tables.
return false;
- pending_pe_relocation_table = true;
- output = &bytes_following_relocation_table;
+ pending_base_relocation_table = true;
+ output = &bytes_following_base_relocation_table;
break;
// There is a potential problem *if* the instruction stream contains
// some REL32 relocations following the base relocation and in the same
@@ -504,31 +498,12 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
// executable except some padding zero bytes. We could fix this by
// emitting an ORIGIN after the MAKE_BASE_RELOCATION_TABLE.
}
-
- 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.
- return false;
-
- pending_elf_relocation_table = true;
- output = &bytes_following_relocation_table;
- break;
- }
}
}
- if (pending_pe_relocation_table) {
- if (!GeneratePeRelocations(final_buffer) ||
- !final_buffer->Append(&bytes_following_relocation_table))
- return false;
- }
-
- if (pending_elf_relocation_table) {
- if (!GenerateElfRelocations(final_buffer) ||
- !final_buffer->Append(&bytes_following_relocation_table))
+ if (pending_base_relocation_table) {
+ if (!GenerateBaseRelocations(final_buffer) ||
+ !final_buffer->Append(&bytes_following_base_relocation_table))
return false;
}
@@ -582,7 +557,7 @@ class RelocBlock {
RelocBlockPOD pod;
};
-CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer) {
+CheckBool EncodedProgram::GenerateBaseRelocations(SinkStream* buffer) {
std::sort(abs32_relocs_.begin(), abs32_relocs_.end());
RelocBlock block;
@@ -602,24 +577,6 @@ CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer) {
return ok;
}
-CheckBool EncodedProgram::GenerateElfRelocations(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;
-
- bool ok = true;
- for (size_t i = 0; ok && i < abs32_relocs_.size(); ++i) {
- relocation_block.r_offset = abs32_relocs_[i];
- ok = buffer->Write(&relocation_block, sizeof(Elf32_Rel));
- }
-
- printf("Emitting size %ld\n", sizeof(Elf32_Rel) * abs32_relocs_.size());
-
- return ok;
-}
////////////////////////////////////////////////////////////////////////////////
Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink) {