LoongArch relocation addend dumping avoids signed overflow.
Binutils' LoongArch relocation dumping now safely handles INT64_MIN addends to prevent signed overflow.
The binutils library’s LoongArch relocation dumping function has been fixed to avoid signed overflow when negating negative addends. Specifically, when encountering the minimum signed 64-bit integer (INT64_MIN), its negation overflows. The fix uses bfd_vma subtraction to compute the absolute value, ensuring correct output and preventing undefined behavior.
In Details
The loongarch_dump_reloc_record function in bfd/elfnn-loongarch.c incorrectly negated a negative larch_reloc_queue[i].addend using a signed long. When the addend is INT64_MIN, this negation overflows, invoking undefined behavior. The patch modifies this to use bfd_vma subtraction to calculate the absolute value (bfd_vma) 0 - (bfd_vma) addend, which correctly handles INT64_MIN without overflow, and then prints it using PRIu64.
- Addend
- A value added to a symbol's address or a relocation offset during the relocation process.
- Relocation
- The process of updating symbolic references in object code to absolute addresses or offsets, typically performed by the linker.
- INT64_MIN
- The smallest representable value for a 64-bit signed integer, typically -2^63.
- bfd_vma
- BFD's generic type for virtual memory addresses, typically an unsigned integer type wide enough to hold any memory address on the target architecture.