Fixes SSP assembly generation with xtheadmemidx extension in RISC-V.
Fixes stack smashing protection (SSP) assembly generation for RISC-V when the xtheadmemidx extension is enabled, using correct move instructions.
When the RISC-V extension xtheadmemidx is enabled, the compiler needs to employ different instructions for stack smashing protection (SSP). The original code was hardcoding ld/sd instructions which are not suitable for all memory operands accepted by the m constraint. This commit replaces the hardcoded instructions with a call to riscv_output_move() to select the correct assembly template. This ensures that SSP works correctly with the xtheadmemidx extension.
In Details
Stack Smashing Protection (SSP) involves adding extra checks to protect against buffer overflows on the stack. The RISC-V xtheadmemidx extension provides additional memory access instructions. The m constraint in GCC inline assembly accepts various memory operands beyond simple loads/stores. The fix replaces the hardcoded <load> and <store> in stack_protect_test_<mode> and stack_protect_set_<mode> with a call to riscv_output_move(), which allows the backend to select the appropriate instruction based on the memory operand type.
For Context
Stack Smashing Protection (SSP) is a security mechanism used to detect and prevent buffer overflow attacks on the stack. A buffer overflow occurs when a program writes beyond the boundaries of allocated memory, potentially overwriting critical data or injecting malicious code. The RISC-V xtheadmemidx extension is an extension which adds instructions for accessing memory using a thread ID. This commit fixes an issue where the compiler was generating incorrect assembly code for SSP when the xtheadmemidx extension was enabled, ensuring that stack protection works correctly in these scenarios.