diff options
author | Samuel Huang <huangs@chromium.org> | 2018-06-26 14:47:02 +0000 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2021-07-25 20:00:46 -0700 |
commit | 8fdb8ba40fec579b42a7dc8bbd1475ee91e1aa42 (patch) | |
tree | 84e44e900bb34a13691345dfb4299caaeed9d1a8 /zucchini_gen.cc | |
parent | f35146e48edca6755e98749a2cb5cc00272d308b (diff) | |
download | zucchini-8fdb8ba40fec579b42a7dc8bbd1475ee91e1aa42.tar.gz |
[Zucchini] Fix underflow / overflow for extended forward-projection.
Forward-projection is how Zucchini uses the equivalence map to create
estimated "new" targets from "old" targets. Extended forward-projection
is defined to transform non-covered offsets: Given an offset, it finds
the equivalence unit with nearest "old" block, then applies the
"old"-to-"new" displacement to the offset. However, this makes it
possible to map an "old" offset to an offset outside "new" image.
Another issue is that Zucchini uses "dangling targets" that use "fake
offsets" outside the image file to represent .bss data. These targets
also undergo forward-projection, and should be properly handled.
This CL fixes the existing behavior, where underflow / overflow go
unchecked (although these values are rendered benign downstream, since
the nearest actual "new" target is found). The updated extended
forward-projection specifies:
- For "old" targets with real offsets: Take nearest equivalence unit,
clamp output to be inside [0, "new" image size).
- For "old" dangling targets with fake offsets: Use difference in
file size as displacement.
The main impact w.r.t. patch is to reduce possible variance in patch
sizes -- dangling targets are now handled better. Extensive unit tests
are also added.
Bug: 832572
Change-Id: I41fea175e4c13585d14a97a712a191afc2fcc6d6
Reviewed-on: https://chromium-review.googlesource.com/1111467
Reviewed-by: Samuel Huang <huangs@chromium.org>
Reviewed-by: Greg Thompson <grt@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570401}
NOKEYCHECK=True
GitOrigin-RevId: ad7a5c086f00de62997714b84d6d6b5817ccc9d8
Diffstat (limited to 'zucchini_gen.cc')
-rw-r--r-- | zucchini_gen.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/zucchini_gen.cc b/zucchini_gen.cc index 19da0af..0bb4658 100644 --- a/zucchini_gen.cc +++ b/zucchini_gen.cc @@ -211,7 +211,8 @@ bool GenerateReferencesDelta(const ReferenceSet& src_refs, dst_ref->location - equiv.dst_offset); offset_t old_offset = src_refs.target_pool().OffsetForKey(src_ref->target_key); - offset_t new_estimated_offset = offset_mapper.ForwardProject(old_offset); + offset_t new_estimated_offset = + offset_mapper.ExtendedForwardProject(old_offset); offset_t new_estimated_key = projected_target_pool.KeyForNearestOffset(new_estimated_offset); offset_t new_offset = @@ -288,7 +289,7 @@ bool GenerateExecutableElement(ExecutableType exe_type, EquivalenceMap equivalences = CreateEquivalenceMap(old_image_index, new_image_index, new_disasm->num_equivalence_iterations()); - OffsetMapper offset_mapper(equivalences); + OffsetMapper offset_mapper(equivalences, old_image.size(), new_image.size()); ReferenceDeltaSink reference_delta_sink; for (const auto& old_targets : old_image_index.target_pools()) { |