[all-commits] [llvm/llvm-project] a1803e: [libc] implement sigsetjmp/siglongjmp for riscv (#...

Schrodinger ZHU Yifan via All-commits all-commits at lists.llvm.org
Sun May 4 13:22:10 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a1803ea063c06c005ba50053f0e2cdb8f852871f
      https://github.com/llvm/llvm-project/commit/a1803ea063c06c005ba50053f0e2cdb8f852871f
  Author: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
  Date:   2025-05-04 (Sun, 04 May 2025)

  Changed paths:
    M libc/config/linux/riscv/entrypoints.txt
    M libc/include/llvm-libc-types/jmp_buf.h
    M libc/src/setjmp/riscv/CMakeLists.txt
    A libc/src/setjmp/riscv/sigsetjmp.cpp

  Log Message:
  -----------
  [libc] implement sigsetjmp/siglongjmp for riscv (#137992)

See https://godbolt.org/z/jo7s6j7sq for compiled code.

```c++
#if __riscv_xlen == 64
#define STORE(A, B, C) "sd " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "ld " #A ", %c[" #B "](" #C ")\n\t"
#elif __riscv_xlen == 32
#define STORE(A, B, C) "sw " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "lw " #A ", %c[" #B "](" #C ")\n\t"
#else
#error "Unsupported RISC-V architecture"
#endif

namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
  // clang-format off
  asm("beqz a1, .Lnosave\n\t"
      STORE(ra, retaddr, a0)
      STORE(s0, extra, a0)
      "mv s0, a0\n\t"
      "call %c[setjmp]\n\t"
      "mv a1, a0\n\t"
      "mv a0, s0\n\t"
      LOAD(s0, extra, a0)
      LOAD(ra, retaddr, a0)
      "tail %c[epilogue]\n"
".Lnosave:\n\t"
      "tail %c[setjmp]"
      // clang-format on
      ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
      [extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
      [epilogue] "i"(sigsetjmp_epilogue)
      : "a0", "a1", "s0");
}
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list