Fix stack size calculation overflow in AMD GCN targets
Corrected stack size and offset calculations to prevent overflow on AMD GCN targets.
This commit addresses an integer overflow vulnerability in stack size and offset calculations for AMD GCN targets. By using 64-bit integers for these calculations, GCC now safely handles larger stack requirements. The fix impacts the libgomp plugin’s kernel creation, the kernel prologue’s stack pointer initialization, and Newlib’s reent struct location, preventing potential crashes or incorrect behavior due to exceeding UINT_MAX.
In Details
The gcn_expand_prologue and gcn_expand_builtin_1 functions within config/gcn/gcn.cc were susceptible to stack size and offset calculation overflows when exceeding UINT_MAX. This commit rectifies this by promoting wave_offset and fp_hi calculations to 64-bit, and stack_limit_offset_di similarly. Additionally, libgomp's gomp_gcn_enter_kernel and configure_ephemeral_memories in the plugin now use size_t for robust size calculations, mitigating PR target/128366.
- AMD GCN
- Advanced Micro Devices Graphics Core Next, an architecture for GPUs used in various AMD graphics cards.
- libgomp
- The GNU Offloading and Monitorability Library, which provides support for OpenMP in GCC.
- kernel prologue
- The initial part of a function's machine code that sets up the stack frame, saves registers, and prepares for execution.
- reent struct
- A structure used by reentrant C library functions to store thread-specific data, ensuring thread safety.
- UINT_MAX
- The maximum value for an unsigned integer type, defined in <limits.h>. Calculations exceeding this can lead to overflow.