[Zucchini] Fix patch apply failure from untranslatable abs32 references.
Disassembler (Win32 and ELF) uses reloc to find abs32 locations, which
are stored in (1) |abs32_locations_|. Later on, (1) is filtered to
generate (2) actual abs32 locations.
A patching failure case was discovered: Equivalence blocks must never
cut across reference boundaries. However, it turns out blocks generated
using (2) were subject to checks using (1), which triggers a failure
since (1) - (2) is nonempty.
One way for (1) != (2) to happen is from CURRENT_MODULE() usage, which
creates an abs32 reference outside a section. This results in an abs32
target whose RVA does not map to an offset using section data, and
gets rejected by filtering logic for (2).
Fix: Apply the filtering logic direcly to (1), so (1) == (2). Details:
* Add RemoveUntranslatableAbs32() (abs32_utils.h), which uses the
filtering logic for (2) to preemptively remove problematic RVAs
from (1), so |abs32_locations_| matches (2). Extensive unit tests
are added.
* DisassemblerWin32<Traits>::ParseAndStoreAbs32(): Initialize
|abs32_locations_| with 3 steps: Naive extraction from relocs,
RemoveUntranslatableAbs32(), and RemoveOverlappingAbs32Locations().
* DisassemblerElf<Traits>::GetAbs32FromRelocSections(): Do the same,
noting that ELF's image base is always 0.
Additional fixes:
* address_translator.h: kInvalidRva was -1, but it should be -2 to
better match kInvalidOffset.
* Abs32RvaExtractorWin32::Abs32RvaExtractorWin32: The lambda
|find_and_check| binds |addr|, which has been std::move()'ed.
Better to just bind |this| and use |addr_|.
Bug: 892284
Change-Id: I628f4668ea231c7e06f35bd924652ca4d74bb848
Reviewed-on: https://chromium-review.googlesource.com/c/1263877
Reviewed-by: Greg Thompson <[email protected]>
Reviewed-by: Samuel Huang <[email protected]>
Commit-Queue: Samuel Huang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#598342}
diff --git a/components/zucchini/reloc_win32.cc b/components/zucchini/reloc_win32.cc
index dcf40bb..6da48f2 100644
--- a/components/zucchini/reloc_win32.cc
+++ b/components/zucchini/reloc_win32.cc
@@ -152,7 +152,7 @@
offset_t target = entry_rva_to_offset_.Convert(unit->target_rva);
if (target == kInvalidOffset)
continue;
- // Ensures the target (abs32 reference) lies entirely within the image.
+ // Ensure that |target| (abs32 reference) lies entirely within the image.
if (target >= offset_bound_)
continue;
offset_t location = unit->location;