- int64_t Addend = getAddend32LE(R);
- return RelocToApply(Value + Addend, 4);
+ int64_t Addend;
+ getELFRelocationAddend(R, Addend);
+ int64_t Res = Value + Addend;
+
+ // Overflow check allows for both signed and unsigned interpretation.
+ if (Res < INT32_MIN || Res > UINT32_MAX)
+ HasError = true;
+
+ return RelocToApply(static_cast<uint32_t>(Res), 4);