Fix ImageSpace relocation direction check.
The correct check whether `begin+diff` would overflow
uint32_t is `begin >= -diff` in unsigned arithmetic.
Note that with the current ranges of relocation diff and
ART_BASE_ADDRESS, the result of the check is the same as
before.
Test: m test-art-host-gtest
Bug: 77856493
Change-Id: Ic0ded458ad8fa327ea74e2e0ebdd4de18c4e5b04
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 173e879..3d676ae 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -1625,7 +1625,7 @@
// First patch the image header. The `diff` is OK for patching 32-bit fields but
// the 64-bit method fields in the ImageHeader may need a negative `delta`.
reinterpret_cast<ImageHeader*>(space->Begin())->RelocateImage(
- (reinterpret_cast32<uint32_t>(space->Begin()) < diff)
+ (reinterpret_cast32<uint32_t>(space->Begin()) >= -diff) // Would `begin+diff` overflow?
? -static_cast<int64_t>(-diff) : static_cast<int64_t>(diff));
// Patch fields and methods.