Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISC-V: add CFI directives #10473

Merged
merged 4 commits into from
Jun 25, 2021
Merged

RISC-V: add CFI directives #10473

merged 4 commits into from
Jun 25, 2021

Commits on Jun 24, 2021

  1. runtime/riscv.S: introduce END_FUNCTION macro

    To have a convenient place to add a CFI_ENDPROC call.
    
    Signed-off-by: Edwin Török <edwin@etorok.net>
    edwintorok committed Jun 24, 2021
    Configuration menu
    Copy the full SHA
    26cc0f6 View commit details
    Browse the repository at this point in the history
  2. runtime/riscv.S: add DWARF CFI directives

    This is needed for backtraces to function in GDB.
    
    CFI_{START,END}PROC is added to FUNCTION/END_FUNCTION.
    .Ltrap_handler needs its own CFI_STARTPROC because it doesn't use
    FUNCTION.
    
    The rules for CFI_ADJUST are fairly simple: whenever the `sp` is
    manipulated add a CFI_ADJUST right after it with an opposite sign.
    This allows the unwinder to always find the frame even when the sp
    gets moved multiple times.
    
    CFI_OFFSET is used to tell the unwinder where the various registers are
    saved on the stack. At a minimum we need to tell it where to find `ra`,
    so that it can continue unwinding the stack.
    The value for CFI_OFFSET is calculated by undoing the adjustment
    made by CFI_ADJUST (so we get the value of the sp from the frame),
    and then adding the same offset use by the STORE instruction.
    
    Signed-off-by: Edwin Török <edwin@etorok.net>
    edwintorok committed Jun 24, 2021
    Configuration menu
    Copy the full SHA
    d4b73d3 View commit details
    Browse the repository at this point in the history
  3. asmcomp/riscv: emit CFI directives

    Needed for stacktraces to work in a debugger.
    cfi_startproc/cfi_endproc marks the boundaries of a function.
    
    adjust_stack_offset updates the offset between the stackpointer and the
    frame as the stackpointer is adjusted the offset is adjusted in opposite
    direction.
    Every `addi sp` needs a corresponding adjust_cfa_offset.
    This is not done for tailcalls where other backends have a comment about
    undoing CFA adjustments because the function may continue.
    
    cfi_offset is for telling the unwinder where to find register on the
    stack, at a minimum we need to tell it about the location of `ra`.
    
    Note that there is a difference here: in OCaml code it is at c-8,
    whereas in caml_call_gc it is at c-16
    (c-8 is unused gap due to alignment).
    
    This change was modeled after arm64/emit.mlp
    
    Signed-off-by: Edwin Török <edwin@etorok.net>
    edwintorok committed Jun 24, 2021
    Configuration menu
    Copy the full SHA
    e015077 View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2021

  1. Configuration menu
    Copy the full SHA
    0692959 View commit details
    Browse the repository at this point in the history