What is Return address?
The address to go back to when a function finishes. In RISC-V, jal puts the next instruction's address in ra (x1); in x86, call pushes it on the stack.
Japanese name: リターンアドレス
The address to go back to when a function finishes. In RISC-V, jal puts the next instruction's address in ra (x1); in x86, call pushes it on the stack.
Japanese name: リターンアドレス
A call must record where execution should resume, which is the address of the instruction after the call. In RISC-V, jal (jump and link) writes PC + 4 into a register, by convention ra (x1), and jumps; the return is ret, a pseudo-instruction for jalr x0, 0(ra). Calls through function pointers, virtual functions and shared-library stubs use jalr with a register target. In x86, call pushes the return address onto the stack and ret pops it back into the instruction pointer, so the stack always holds it.
Because every jal overwrites ra, a RISC-V function that calls other functions must save its own return address first. A typical prologue is addi sp, sp, -16 to allocate a frame on the downward-growing stack, then sw ra, 12(sp) and sw s0, 8(sp) to save ra and a callee-saved register. The epilogue reloads them, restores sp and executes ret. A leaf function, which calls nothing, can leave ra in its register and may need no stack frame at all, which makes small functions cheap.
A return address stored on the stack sits next to local buffers, so a buffer overflow can overwrite it and redirect execution when the function returns. Classic attacks wrote machine code onto the stack and jumped to it; W^X policies with the page-table no-execute bit block that. Attackers then shifted to return-oriented programming, chaining existing code fragments. Further defenses include stack canaries checked before return, address-space layout randomization and hardware shadow stacks that keep a protected second copy of each return address.
Out-of-order CPUs predict where a return will go long before ra or the stack is read. A return address stack (RAS) in the branch predictor pushes the fall-through address on each call and pops it on each return, giving very accurate predictions for well-nested code. Exceptions and interrupts are different: the CPU saves the interrupted PC in a dedicated register such as RISC-V mepc or sepc, together with the previous privilege mode, and mret or sret restores all of them at once rather than a plain ret.
Answer: A. The stack
Calling a subroutine pushes the return address, registers to be preserved and local variables onto the stack. On ARM and RISC-V, the return address first goes into a link register and is saved to the stack when needed. Its last-in, first-out (LIFO) structure ensures correct returns even with nested or recursive calls, and the stack pointer marks its top. Excessive recursion exhausts it (stack overflow), and buffer overruns that overwrite return addresses are a classic attack.
In register ra (x1), written by jal or jalr at the call. A non-leaf function copies it to its stack frame before making its own calls and restores it before ret.
x86 call always pushes the return address onto the stack and ret pops it, while RISC-V jal places it in a register and only touches memory if the function chooses to save it.
When the function returns, the CPU jumps to whatever address is there, so an attacker who overwrites it through a buffer overflow can take control of the program.
Return address appears in 11 practice questions across 3 topics, including ISA & Assembly, Hardware Security: Advanced Topics and Trends, CPUs and architecture.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.