Similar to D90898 (Linux AArch64) and D124765 (SystemZ).
On an Arch Linux RISC-V (riscv64gc), the following code
#define _GNU_SOURCE #include <dlfcn.h> #include <libunwind.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> static void handler(int signo) { unw_context_t context; unw_cursor_t cursor; unw_getcontext(&context); unw_init_local(&cursor, &context); unw_word_t pc, sp; do { unw_get_reg(&cursor, UNW_REG_IP, &pc); unw_get_reg(&cursor, UNW_REG_SP, &sp); printf("pc=0x%016zx sp=0x%016zx", (size_t)pc, (size_t)sp); Dl_info info = {}; if (dladdr((void *)pc, &info)) printf(" %s:%s", info.dli_fname, info.dli_sname ? info.dli_sname : ""); puts(""); } while (unw_step(&cursor) > 0); exit(0); } int main() { signal(SIGUSR1, handler); raise(SIGUSR1); return 1; }
linked with -Wl,--export-dynamic gives an output like
pc=0x0000000000010a82 sp=0x00007fffd8a0b910 ./b: pc=0x00007fffa7e77800 sp=0x00007fffd8a0c520 linux-vdso.so.1:__vdso_rt_sigreturn pc=0x00007fffa7d73bee sp=0x00007fffd8a0c960 /usr/lib/libc.so.6: pc=0x00007fffa7d3ed66 sp=0x00007fffd8a0c9b0 /usr/lib/libc.so.6:gsignal pc=0x0000000000010a3c sp=0x00007fffd8a0c9c0 ./b:main pc=0x00007fffa7d2f1d4 sp=0x00007fffd8a0c9e0 /usr/lib/libc.so.6: pc=0x00007fffa7d2f27c sp=0x00007fffd8a0cb10 /usr/lib/libc.so.6:__libc_start_main pc=0x00000000000109a0 sp=0x00007fffd8a0cb60 ./b:_start
Co-Authored-By: Fangrui Song <i@maskray.me>
Where is __default_sa_restorer defined? Isn't it only used by Linux arm?