SPARC return instructions avoid frame memory loads in delay slots.
SPARC return instructions no longer perform loads from the function's frame in delay slots, preventing data corruption and traps.
On SPARC V9, loads from a function’s own frame are now disallowed in the delay slot of return instructions. This is because the delay slot executes after the register window has been restored, meaning such loads would access memory below the stack pointer. A trap or signal during this operation could corrupt the loaded data, leading to incorrect behavior. This change also simplifies related logic for identifying eligible instructions in delay slots.
In Details
This commit addresses an issue on SPARC V9 where instructions placed in the delay slot of a return instruction could load from the function's stack frame. After a ret instruction, the register window is restored, and the stack pointer (sp) points to the base of the caller's frame. Loading from sp + offset in the delay slot would then access memory belonging to the current function's frame, which might have been deallocated or is otherwise unstable. The change modifies eligible_for_restore_insn and related functions to prevent memory loads from the current function's frame in return de…
- SPARC V9
- A 64-bit version of the SPARC instruction set architecture, developed by Sun Microsystems.
- delay slot
- An instruction slot immediately following a control-flow instruction (like branches or jumps) in some architectures (e.g., MIPS, SPARC). The instruction in the delay slot is always executed, regardless of whether the control-flow transfer occurs.
- register window
- A feature in SPARC processors where a set of physical registers is divided into overlapping windows. Each function call gets a new window, reducing the need for stack-based register saves and restores.
- stack pointer (sp)
- A register that holds the address of the top of the stack in memory. It is decremented when data is pushed onto the stack and incremented when data is popped off.
- trap
- An exception or interrupt signal generated by the processor, typically due to an error condition (e.g., division by zero, invalid memory access) or an external event.