AFAIK backtrace is fundamentally broken for RISC-V, even if you compile everything with frame pointers. Even if it could be fixed, right now it's broken in ~all systems so I think it's best to disable it for RISC-V.
Details
- Reviewers
- None
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Support/Unix/Signals.inc | ||
---|---|---|
566 | The "Linux" in the comment will be removed before committing. |
I am almost certain backtrace() does work on FreeBSD, so there should be a __linux__ check as well.
The comment says it only exists on glibc systems, but on FreeBSD libexecinfo provides this functionality.
Can you give a bit more context on *why* backtrace is broken? And on which systems you've observed this? This is the first time I'm hearing this.
https://forums.sifive.com/t/how-to-get-backtrace-in-rtos-based-on-risc-v-64/5643/2:
On RISC-V, the only reliable way to backtrace is to use the EH unwind info. I don’t think that the glibc backtrace() function will work.
I've observed this in Linux glibc RV64 systems (Fedora and Ubuntu).
RISC-V GCC has added -fasynchronous-unwind-tables to the default option for linux, maybe we should do that on clang side? this should able improve the situation.
https://github.com/gcc-mirror/gcc/commit/3cd08f7168c196d7a481b9ed9f4289fd1f14eea8
Maybe it's the reason why FreeBSD work fine:
ToolChain::UnwindTableLevel FreeBSD::getDefaultUnwindTableLevel(const ArgList &Args) const { return UnwindTableLevel::Asynchronous; }
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/FreeBSD.cpp#L489
Sorry, I was speaking from memory and it had been a while since I looked at this. I went back to check my notes/tests and -fasynchronous-unwind-tables does help for backtrace.
The "Linux" in the comment will be removed before committing.