summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authorbradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 01:03:43 +0000
committerbradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 01:03:43 +0000
commit104a608acbf0fe57728f95d21c59ed25f61b0482 (patch)
treef62f6ce78a3379b043e0ff71cfccef0baa46d98f /courgette
parentc840d52c54743d3353e90136fe17b8c697083d25 (diff)
downloadchromium_src-104a608acbf0fe57728f95d21c59ed25f61b0482.zip
chromium_src-104a608acbf0fe57728f95d21c59ed25f61b0482.tar.gz
chromium_src-104a608acbf0fe57728f95d21c59ed25f61b0482.tar.bz2
Also build a 64-bit exe version of the 32-bit courgette
utility + library to support larger input sizes. BUG=63793 TEST=None Review URL: http://codereview.chromium.org/5096007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette')
-rw-r--r--courgette/adjustment_method.cc5
-rw-r--r--courgette/adjustment_method_2.cc19
-rw-r--r--courgette/assembly_program.cc6
-rw-r--r--courgette/courgette.gyp115
-rw-r--r--courgette/courgette_tool.cc2
-rw-r--r--courgette/disassembler.cc6
-rw-r--r--courgette/encoded_program.cc10
-rw-r--r--courgette/ensemble_apply.cc2
-rw-r--r--courgette/ensemble_create.cc4
-rw-r--r--courgette/image_info.cc4
-rw-r--r--courgette/streams.cc18
-rw-r--r--courgette/streams.h4
-rw-r--r--courgette/third_party/bsdiff_create.cc4
-rw-r--r--courgette/win32_x86_generator.h4
14 files changed, 130 insertions, 73 deletions
diff --git a/courgette/adjustment_method.cc b/courgette/adjustment_method.cc
index eabb684..4f16944 100644
--- a/courgette/adjustment_method.cc
+++ b/courgette/adjustment_method.cc
@@ -524,7 +524,7 @@ class AssignmentProblem {
Node* MakeRootNode(const Trace& trace) {
Node* node = new Node(NULL, NULL);
all_nodes_.push_back(node);
- for (size_t i = 0; i < trace.size(); ++i) {
+ for (uint32 i = 0; i < trace.size(); ++i) {
++node->count_;
node->places_.push_back(i);
}
@@ -635,7 +635,8 @@ class GraphAdjuster : public AdjustmentMethod {
}
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
- trace->push_back(MakeLabelInfo(label, is_model, trace->size()));
+ trace->push_back(MakeLabelInfo(label, is_model,
+ static_cast<uint32>(trace->size())));
}
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
diff --git a/courgette/adjustment_method_2.cc b/courgette/adjustment_method_2.cc
index b487320..cacf33e 100644
--- a/courgette/adjustment_method_2.cc
+++ b/courgette/adjustment_method_2.cc
@@ -389,8 +389,10 @@ class Shingle {
}
LabelInfo* at(size_t i) const { return trace_[exemplar_position_ + i]; }
- void add_position(size_t position) { positions_.push_back(position); }
- size_t position_count() const { return positions_.size(); }
+ void add_position(size_t position) {
+ positions_.push_back(static_cast<uint32>(position));
+ }
+ int position_count() const { return static_cast<int>(positions_.size()); }
bool InModel() const { return at(0)->is_model_; }
@@ -436,7 +438,7 @@ std::string ToString(const Shingle* instance) {
s += ToString(instance->at(i));
sep = ", ";
}
- base::StringAppendF(&s, ">(%" PRIuS ")@{%" PRIuS "}",
+ base::StringAppendF(&s, ">(%" PRIuS ")@{%d}",
instance->exemplar_position_,
instance->position_count());
return s;
@@ -493,7 +495,7 @@ class ShinglePattern {
class FreqView {
public:
explicit FreqView(const Shingle* instance) : instance_(instance) {}
- size_t count() const { return instance_->position_count(); }
+ int count() const { return instance_->position_count(); }
const Shingle* instance() const { return instance_; }
struct Greater {
bool operator()(const FreqView& a, const FreqView& b) const {
@@ -554,7 +556,7 @@ std::string HistogramToString(const ShinglePattern::Histogram& histogram,
s += " ...";
break;
}
- base::StringAppendF(&s, " %" PRIuS, p->count());
+ base::StringAppendF(&s, " %d", p->count());
}
return s;
}
@@ -574,7 +576,7 @@ std::string HistogramToStringFull(const ShinglePattern::Histogram& histogram,
s += "...\n";
break;
}
- base::StringAppendF(&s, "(%" PRIuS ") ", p->count());
+ base::StringAppendF(&s, "(%d) ", p->count());
s += ToString(&(*p->instance()));
s += "\n";
}
@@ -647,7 +649,7 @@ ShinglePattern::Index::Index(const Shingle* instance) {
unique_variables_ = 0;
first_variable_index_ = 255;
- for (size_t i = 0; i < Shingle::kWidth; ++i) {
+ for (uint32 i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* info = instance->at(i);
uint32 kind = 0;
int code = -1;
@@ -1275,7 +1277,8 @@ class Adjuster : public AdjustmentMethod {
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
trace->push_back(
- label_info_maker_.MakeLabelInfo(label, is_model, trace->size()));
+ label_info_maker_.MakeLabelInfo(label, is_model,
+ static_cast<uint32>(trace->size())));
}
AssemblyProgram* prog_; // Program to be adjusted, owned by caller.
diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc
index e160d767..345ca89 100644
--- a/courgette/assembly_program.cc
+++ b/courgette/assembly_program.cc
@@ -228,10 +228,10 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) {
Label* current = p->second;
if (current->index_ == Label::kNoIndex) {
- size_t index = 0;
+ int index = 0;
if (prev && prev->index_ != Label::kNoIndex)
index = prev->index_ + 1;
- if (index < available.size() && available.at(index)) {
+ if (index < static_cast<int>(available.size()) && available.at(index)) {
current->index_ = index;
available.at(index) = false;
++fill_forward_count;
@@ -254,7 +254,7 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
if (prev)
prev_index = prev->index_;
else
- prev_index = available.size();
+ prev_index = static_cast<uint32>(available.size());
if (prev_index != 0 &&
prev_index != Label::kNoIndex &&
available.at(prev_index - 1)) {
diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp
index c45b3ac..a192050 100644
--- a/courgette/courgette.gyp
+++ b/courgette/courgette.gyp
@@ -5,6 +5,39 @@
{
'variables': {
'chromium_code': 1,
+ 'courgette_lib_sources': [
+ 'adjustment_method.cc',
+ 'adjustment_method_2.cc',
+ 'adjustment_method.h',
+ 'assembly_program.cc',
+ 'assembly_program.h',
+ 'third_party/bsdiff.h',
+ 'third_party/bsdiff_apply.cc',
+ 'third_party/bsdiff_create.cc',
+ 'third_party/paged_array.h',
+ 'courgette.h',
+ 'crc.cc',
+ 'crc.h',
+ 'difference_estimator.cc',
+ 'difference_estimator.h',
+ 'disassembler.cc',
+ 'disassembler.h',
+ 'encoded_program.cc',
+ 'encoded_program.h',
+ 'ensemble.cc',
+ 'ensemble.h',
+ 'ensemble_apply.cc',
+ 'ensemble_create.cc',
+ 'image_info.cc',
+ 'image_info.h',
+ 'region.h',
+ 'simple_delta.cc',
+ 'simple_delta.h',
+ 'streams.cc',
+ 'streams.h',
+ 'win32_x86_generator.h',
+ 'win32_x86_patcher.h',
+ ],
},
'targets': [
{
@@ -16,58 +49,28 @@
],
'msvs_guid': '9A72A362-E617-4205-B9F2-43C6FB280FA1',
'sources': [
- 'adjustment_method.cc',
- 'adjustment_method_2.cc',
- 'adjustment_method.h',
- 'assembly_program.cc',
- 'assembly_program.h',
- 'third_party/bsdiff.h',
- 'third_party/bsdiff_apply.cc',
- 'third_party/bsdiff_create.cc',
- 'third_party/paged_array.h',
- 'courgette.h',
- 'crc.cc',
- 'crc.h',
- 'difference_estimator.cc',
- 'difference_estimator.h',
- 'disassembler.cc',
- 'disassembler.h',
- 'encoded_program.cc',
- 'encoded_program.h',
- 'ensemble.cc',
- 'ensemble.h',
- 'ensemble_apply.cc',
- 'ensemble_create.cc',
- 'image_info.cc',
- 'image_info.h',
- 'region.h',
- 'simple_delta.cc',
- 'simple_delta.h',
- 'streams.cc',
- 'streams.h',
- 'win32_x86_generator.h',
- 'win32_x86_patcher.h',
+ '<@(courgette_lib_sources)'
],
},
- {
+ {
'target_name': 'courgette',
'type': 'executable',
'msvs_guid': '4EA8CE12-9C6F-45E5-9D08-720383FE3685',
'sources': [
'courgette_tool.cc',
- ],
+ ],
'dependencies': [
'courgette_lib',
'../base/base.gyp:base',
],
},
- {
+ {
'target_name': 'courgette_minimal_tool',
'type': 'executable',
'msvs_guid': 'EB79415F-2F17-4BDC-AADD-4CA4C2D21B73',
'sources': [
'courgette_minimal_tool.cc',
- ],
+ ],
'dependencies': [
'courgette_lib',
'../base/base.gyp:base',
@@ -87,7 +90,7 @@
'run_all_unittests.cc',
'streams_unittest.cc',
'third_party/paged_array_unittest.cc'
- ],
+ ],
'dependencies': [
'courgette_lib',
'../base/base.gyp:base',
@@ -107,7 +110,7 @@
}],
],
},
- {
+ {
'target_name': 'courgette_fuzz',
'type': 'executable',
'msvs_guid': '57C27529-8CA9-4FC3-9C02-DA05B172F785',
@@ -134,6 +137,44 @@
],
},
],
+ 'conditions': [
+ ['OS=="win"', {
+ 'targets': [
+ {
+ 'target_name': 'courgette_lib64',
+ 'type': '<(library)',
+ 'dependencies': [
+ '../base/base.gyp:base_nacl_win64',
+ '../third_party/lzma_sdk/lzma_sdk.gyp:lzma_sdk64',
+ ],
+ 'sources': [
+ '<@(courgette_lib_sources)',
+ ],
+ 'configurations': {
+ 'Common_Base': {
+ 'msvs_target_platform': 'x64',
+ },
+ },
+ },
+ {
+ 'target_name': 'courgette64',
+ 'type': 'executable',
+ 'sources': [
+ 'courgette_tool.cc',
+ ],
+ 'dependencies': [
+ 'courgette_lib64',
+ '../base/base.gyp:base_nacl_win64',
+ ],
+ 'configurations': {
+ 'Common_Base': {
+ 'msvs_target_platform': 'x64',
+ },
+ },
+ },
+ ],
+ }],
+ ],
}
# Local Variables:
diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc
index 9a0a5ea..5e37f30 100644
--- a/courgette/courgette_tool.cc
+++ b/courgette/courgette_tool.cc
@@ -68,7 +68,7 @@ void WriteSinkToFile(const courgette::SinkStream *sink,
int count =
file_util::WriteFile(output_path,
reinterpret_cast<const char*>(sink->Buffer()),
- sink->Length());
+ static_cast<int>(sink->Length()));
if (count == -1)
Problem("Can't write output.");
if (static_cast<size_t>(count) != sink->Length())
diff --git a/courgette/disassembler.cc b/courgette/disassembler.cc
index b3b5577..2b4db2c 100644
--- a/courgette/disassembler.cc
+++ b/courgette/disassembler.cc
@@ -166,7 +166,7 @@ void DisassemblerWin32X86::ParseRel32RelocsFromSection(const Section* section) {
// Find the rel32 relocations.
const uint8* p = start_pointer;
while (p < end_pointer) {
- RVA current_rva = p - adjust_pointer_to_rva;
+ RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
if (current_rva == relocs_start_rva) {
uint32 relocs_size = pe_info().base_relocation_table().size_;
if (relocs_size) {
@@ -195,7 +195,7 @@ void DisassemblerWin32X86::ParseRel32RelocsFromSection(const Section* section) {
}
}
if (rel32) {
- RVA rel32_rva = rel32 - adjust_pointer_to_rva;
+ RVA rel32_rva = static_cast<RVA>(rel32 - adjust_pointer_to_rva);
// Is there an abs32 reloc overlapping the candidate?
while (abs32_pos != abs32_locations_.end() && *abs32_pos < rel32_rva - 3)
@@ -297,7 +297,7 @@ void DisassemblerWin32X86::ParseFileRegion(
const uint8* p = start_pointer;
while (p < end_pointer) {
- RVA current_rva = p - adjust_pointer_to_rva;
+ RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
// The base relocation table is usually in the .relocs section, but it could
// actually be anywhere. Make sure we skip it because we will regenerate it
diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc
index 4c84e05..f09a350 100644
--- a/courgette/encoded_program.cc
+++ b/courgette/encoded_program.cc
@@ -42,10 +42,10 @@ EncodedProgram::~EncodedProgram() {}
template<typename T>
void WriteVector(const std::vector<T>& items, SinkStream* buffer) {
size_t count = items.size();
- buffer->WriteVarint32(count);
+ buffer->WriteSizeVarint32(count);
for (size_t i = 0; i < count; ++i) {
COMPILE_ASSERT(sizeof(T) <= sizeof(uint32), T_must_fit_in_uint32);
- buffer->WriteVarint32(static_cast<uint32>(items[i]));
+ buffer->WriteSizeVarint32(items[i]);
}
}
@@ -70,7 +70,7 @@ bool ReadVector(std::vector<T>* items, SourceStream* buffer) {
// Serializes a vector, using delta coding followed by Varint32 coding.
void WriteU32Delta(const std::vector<uint32>& set, SinkStream* buffer) {
size_t count = set.size();
- buffer->WriteVarint32(count);
+ buffer->WriteSizeVarint32(count);
uint32 prev = 0;
for (size_t i = 0; i < count; ++i) {
uint32 current = set[i];
@@ -111,8 +111,8 @@ static bool ReadU32Delta(std::vector<uint32>* set, SourceStream* buffer) {
//
template<typename T>
void WriteVectorU8(const std::vector<T>& items, SinkStream* buffer) {
- uint32 count = items.size();
- buffer->WriteVarint32(count);
+ size_t count = items.size();
+ buffer->WriteSizeVarint32(count);
if (count != 0) {
size_t byte_count = count * sizeof(T);
buffer->Write(static_cast<const void*>(&items[0]), byte_count);
diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc
index 3643129..d1310b4 100644
--- a/courgette/ensemble_apply.cc
+++ b/courgette/ensemble_apply.cc
@@ -399,7 +399,7 @@ Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name,
file_util::WriteFile(
new_file_path,
reinterpret_cast<const char*>(new_sink_stream.Buffer()),
- new_sink_stream.Length());
+ static_cast<int>(new_sink_stream.Length()));
if (written == -1)
return C_WRITE_OPEN_ERROR;
if (static_cast<size_t>(written) != new_sink_stream.Length())
diff --git a/courgette/ensemble_create.cc b/courgette/ensemble_create.cc
index b155106..98b7ba0 100644
--- a/courgette/ensemble_create.cc
+++ b/courgette/ensemble_create.cc
@@ -232,8 +232,8 @@ Status GenerateEnsemblePatch(SourceStream* base,
SinkStream* transformed_elements_correction = patch_streams.stream(2);
SinkStream* ensemble_correction = patch_streams.stream(3);
- uint32 number_of_transformations = generators.size();
- tranformation_descriptions->WriteVarint32(number_of_transformations);
+ size_t number_of_transformations = generators.size();
+ tranformation_descriptions->WriteSizeVarint32(number_of_transformations);
for (size_t i = 0; i < number_of_transformations; ++i) {
CourgettePatchFile::TransformationMethodId kind = generators[i]->Kind();
diff --git a/courgette/image_info.cc b/courgette/image_info.cc
index 8d1b9aa..0c8cdf6 100644
--- a/courgette/image_info.cc
+++ b/courgette/image_info.cc
@@ -50,7 +50,7 @@ PEInfo::PEInfo()
void PEInfo::Init(const void* start, size_t length) {
start_ = reinterpret_cast<const uint8*>(start);
- length_ = length;
+ length_ = static_cast<int>(length);
end_ = start_ + length_;
failure_reason_ = "unparsed";
}
@@ -329,7 +329,7 @@ bool PEInfo::ReadDataDirectory(int index, ImageDataDirectory* directory) {
// TODO(sra): validate RVA.
directory->address_ = rva;
- directory->size_ = size;
+ directory->size_ = static_cast<uint32>(size);
return true;
} else {
directory->address_ = 0;
diff --git a/courgette/streams.cc b/courgette/streams.cc
index fec16fa..26c7f2e 100644
--- a/courgette/streams.cc
+++ b/courgette/streams.cc
@@ -21,6 +21,7 @@
#include <memory.h>
#include "base/basictypes.h"
+#include "base/logging.h"
namespace courgette {
@@ -201,6 +202,13 @@ void SinkStream::WriteVarint32Signed(int32 value) {
WriteVarint32(value * 2);
}
+void SinkStream::WriteSizeVarint32(size_t value) {
+ uint32 narrowed_value = static_cast<uint32>(value);
+ // On 32-bit, the compiler should figure out this test always fails.
+ LOG_ASSERT(value == narrowed_value);
+ WriteVarint32(narrowed_value);
+}
+
void SinkStream::Append(SinkStream* other) {
Write(other->buffer_.c_str(), other->buffer_.size());
other->buffer_.clear();
@@ -316,9 +324,9 @@ void SinkStreamSet::Init(size_t stream_index_limit) {
// <version><N><length1><length2>...<lengthN>
void SinkStreamSet::CopyHeaderTo(SinkStream* header) {
header->WriteVarint32(kStreamsSerializationFormatVersion);
- header->WriteVarint32(count_);
+ header->WriteSizeVarint32(count_);
for (size_t i = 0; i < count_; ++i) {
- header->WriteVarint32(stream(i)->Length());
+ header->WriteSizeVarint32(stream(i)->Length());
}
}
@@ -341,15 +349,15 @@ bool SinkStreamSet::WriteSet(SinkStreamSet* set) {
size_t stream_count = 0;
for (size_t i = 0; i < kMaxStreams; ++i) {
SinkStream* stream = set->stream(i);
- lengths[i] = stream->Length();
+ lengths[i] = static_cast<uint32>(stream->Length());
if (lengths[i] > 0)
stream_count = i + 1;
}
SinkStream* control_stream = this->stream(0);
- control_stream->WriteVarint32(stream_count);
+ control_stream->WriteSizeVarint32(stream_count);
for (size_t i = 0; i < stream_count; ++i) {
- control_stream->WriteVarint32(lengths[i]);
+ control_stream->WriteSizeVarint32(lengths[i]);
}
for (size_t i = 0; i < stream_count; ++i) {
diff --git a/courgette/streams.h b/courgette/streams.h
index 3309571..144dca7 100644
--- a/courgette/streams.h
+++ b/courgette/streams.h
@@ -126,6 +126,10 @@ class SinkStream {
// Appends the 'varint32' encoding of |value| to the stream.
void WriteVarint32Signed(int32 value);
+ // Appends the 'varint32' encoding of |value| to the stream.
+ // On platforms where sizeof(size_t) != sizeof(int32), do a safety check.
+ void WriteSizeVarint32(size_t value);
+
// Contents of |other| are appended to |this| stream. The |other| stream
// becomes retired.
void Append(SinkStream* other);
diff --git a/courgette/third_party/bsdiff_create.cc b/courgette/third_party/bsdiff_create.cc
index 21c45bb..111c9f0 100644
--- a/courgette/third_party/bsdiff_create.cc
+++ b/courgette/third_party/bsdiff_create.cc
@@ -215,7 +215,7 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
SinkStream* extra_bytes = patch_streams.stream(5);
const uint8* old = old_stream->Buffer();
- const int oldsize = old_stream->Remaining();
+ const int oldsize = static_cast<int>(old_stream->Remaining());
uint32 pending_diff_zeros = 0;
@@ -241,7 +241,7 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
V.clear();
const uint8* newbuf = new_stream->Buffer();
- const int newsize = new_stream->Remaining();
+ const int newsize = static_cast<int>(new_stream->Remaining());
int control_length = 0;
int diff_bytes_length = 0;
diff --git a/courgette/win32_x86_generator.h b/courgette/win32_x86_generator.h
index c0302ca..d716543 100644
--- a/courgette/win32_x86_generator.h
+++ b/courgette/win32_x86_generator.h
@@ -27,8 +27,8 @@ class CourgetteWin32X86PatchGenerator : public TransformationPatchGenerator {
}
Status WriteInitialParameters(SinkStream* parameter_stream) {
- parameter_stream->WriteVarint32(old_element_->offset_in_ensemble());
- parameter_stream->WriteVarint32(old_element_->region().length());
+ parameter_stream->WriteSizeVarint32(old_element_->offset_in_ensemble());
+ parameter_stream->WriteSizeVarint32(old_element_->region().length());
return C_OK;
// TODO(sra): Initialize |patcher_| with these parameters.
}