GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
target/riscv

RISC-V: Correctly attach DEF_CFA note to stack pointer copy instruction.

The DEF_CFA debugging information is now attached to the correct instruction on RISC-V, fixing a correctness issue.

This commit corrects an issue on the RISC-V architecture where the REG_CFA_DEF_CFA debugging note was being attached to the wrong instruction. Specifically, the note, which defines the Call Frame Address (CFA), should be associated with the instruction that copies the stack pointer to a temporary register, but it was previously attached to the instruction preceding this copy.

This incorrect placement could lead to inaccurate stack unwinding information. The fix ensures the note is correctly associated with the stack pointer copy, improving the reliability of debugging information, although it does not affect code generation itself.

In Details

For the RISC-V target, the riscv_v_adjust_scalable_frame function is corrected to ensure that the REG_CFA_DEF_CFA note is attached to the instruction that copies from the stack pointer (sp) into a temporary register. Previously, this note was attached to the preceding instruction, leading to incorrect CFA definitions that could be further disrupted by instruction scheduling. This is a correctness fix for DWARF generation on RISC-V.

For Context
DEF_CFA
A DWARF (Debugging With Attributed Record Formats) macro that defines the Call Frame Address (CFA). The CFA is the canonical stack pointer value for a given frame, used for stack unwinding.
RISC-V
An open-standard instruction set architecture (ISA) based on reduced instruction set computer (RISC) principles, designed for simplicity and modularity.
insn
Abbreviation for instruction, a single operation executed by a processor.
DWARF
A standard file format that contains debugging information for executable files, allowing debuggers to map machine code back to the original source code.
stack unwinding
The process of reconstructing the call stack by following return addresses and frame pointers, typically performed by a debugger when an exception occurs or when examining a program's state.
Filed Under: RISC-Vdebuggingcorrectness