Avoid UB and division by zero in reloc handling for alpha, rl78, rx
Binutils fixes undefined behavior and division by zero in relocation handling for alpha, rl78, and rx architectures.
Binutils has corrected undefined behavior and potential division-by-zero errors within the relocation handling logic for Alpha, RL78, and RX architectures. The changes involve carefully managing arithmetic operations, particularly right shifts, division, and modulo, by adding checks for shift amounts and using unsigned arithmetic where appropriate to ensure defined overflow behavior. This improves the robustness and correctness of the relocation process for these architectures.
In Details
This commit addresses several instances of undefined behavior and potential division-by-zero exceptions in the BFD library's relocation processing code for alpha (ECOFF), rl78 (ELF32), and rx (ELF32) targets. For Alpha, alpha_ecoff_get_relocated_section_contents and alpha_relocate_section now check if shift amounts exceed 63 before performing a right shift (>>) to prevent UB. For RL78 and RX, arithmetic operations within relocation computations are guarded to avoid division by zero and ensure correct outcomes, aligning with the defined behavior of unsigned arithmetic and specific…
- Undefined Behavior (UB)
- Behavior that results from an operation or construct that is not specified by the C++ standard. Such behavior is not portable and can lead to unexpected results or crashes.
- Relocation
- The process of adjusting symbolic addresses in an object file or executable to their final memory locations during linking or loading.
- BFD (Binary File Descriptor)
- A library within GNU Binutils that provides a generic interface for reading and writing various binary file formats, including object files and executables.
- Alpha
- A 64-bit reduced instruction set computing (RISC) microprocessor architecture developed by Digital Equipment Corporation (DEC).
- RL78
- A family of microcontrollers from Renesas Electronics, often programmed using an ELF toolchain.
- RX
- A 32-bit CISC microcontroller architecture from Renesas Electronics, also typically using an ELF toolchain.