Skip to content

Stack frame layout for __riscv_{save,restore}_N #35

@dramforever

Description

@dramforever

Currently it (at least seems to me that) the stack frame layout used for __riscv_{save,restore}_N functions is the same for both GCC and LLVM:

And it's compatible with the frame pointer convention defined over at psABI at https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention.

Is perhaps worthwhile to standardize the layout in which ra and s registers are saved on the stack somewhat? Like for example, how many bytes of stack are used for each N and the order for them. It would allow for frame pointers to be used with -msave-restore, and would allow for calculating the precise stack usage when using these routines.

Observation: For now, LLVM can use __riscv_save_N with addi s0, sp, ... for -msave-restore -fno-omit-frame-pointers, but GCC (as of 12.2.0) doesn't seem to know how to do that and emits longhand sequences for the saves and restores instead (See https://godbolt.org/z/6YYhxxzxx).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions