Is llvm-libunwind safe to call from signal handler?

273 views Asked by At

There is a multithreaded app running on Linux, CPU architecture is x86_64. I want to be able to obtain stack trace as backtrace() function does. After signal handler returns the app will continue running. This is SIGUSR1 handler.

backtrace() is considered not signal safe and I can’t convince myself it can be used from signal handler in this scenario.

I saw couple comments stating LLVM libunwind is signal safe, though didn’t find such statement e.g. in library docs.

So is it safe to use libunwind from a signal handler? If yes, why?

If not, what are other options?

1

There are 1 answers

1
Tanner Firl On

So long as you are unwinding locally (i.e. from the process you are acquiring the call stack of), backtrace is signal-safe. From the libunwind's docs:

The manual page for each libunwind routine identifies whether or not it is signal-safe, but as a general rule, any routine that may be needed for local unwinding is signal-safe (e.g., unw_step() for local unwinding is signal-safe). For remote-unwinding, none of the libunwind routines are guaranteed to be signal-safe.