Msg/ClobberedRA: Difference between revisions
From CPUlator Wiki
< Msg
< Msg
Line 27: | Line 27: | ||
Function: | Function: | ||
addi ra, ra, 4 | addi ra, ra, 4 # Modify ra | ||
ret # return to a different location | ret # return to a different location | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 07:13, 10 March 2019
A function should normally return to the instruction after the call instruction in the caller that called this function. This message tells you that this didn't happen: the function return is returning somewhere other than the instruction following the matching call.
Examples
ARMv7
.global _start
_start:
mov sp, #0x1000 // Initialize SP to something sane
bl MyFunction
nop // Should return here
nop // Actually returns here
# ...
MyFunction:
add lr, #4 // Change LR
bx lr // return to a different location
Nios II
.global _start
_start:
movi sp, 0x1000 # Initialize SP
call Function
nop # Should return here
nop # Actually returns here
Function:
addi ra, ra, 4 # Modify ra
ret # return to a different location
Debugging
- Fundamentally, this message is complaining that the return address differs between the start of the function and at the function return. Use breakpoints and make a note of the value of the return address (ra or lr) at both the function entry and return. Are they the same?
- Typically, the return address register is not used in a function body except for saving and restoring it to the stack due to the need for a nested function call. A common cause of the return address changing is a problem during save and restore, e.g., popping from a different location than the corresponding push, or modifying the value that was on the stack. Watch the return address's save and restore and ensure that both the location on the stack and values are the same.
Implementation
The simulator identifies idiomatic call and return instructions executed at runtime. It records the values of registers when executing call instructions, and verifies at return instructions that the return address matches the location of the matching call. This warning is generated at the return instruction.
Disabling this message
This debugging check can be disabled in the Debugging Checks section of the Settings box: Function clobbered ra or sp.