This is an archive of the discontinued LLVM Phabricator instance.

[Support][RISCV] Disable use of backtrace() for RISC-V backtraces
AbandonedPublic

Authored by luismarques on Feb 16 2023, 2:11 AM.

Details

Reviewers
None
Summary

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.

Diff Detail

Event Timeline

luismarques created this revision.Feb 16 2023, 2:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2023, 2:11 AM
luismarques requested review of this revision.Feb 16 2023, 2:11 AM
luismarques added inline comments.Feb 16 2023, 2:13 AM
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.

reames added a subscriber: reames.Feb 21 2023, 8:35 AM

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.

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

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.

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

luismarques added a comment.EditedMar 2 2023, 7:48 AM

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.

Maybe we should do that anyway, but AFAICT it would not improve the GNU backtrace situation. See also my D144178, which I guess will be less needed if your D145164 gets merged.

AFAICT it would not improve the GNU backtrace situation.

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.

luismarques abandoned this revision.Mar 6 2023, 8:03 AM