Skip to content

Segfault in _Unwind_Backtrace when using compiler-rt #93360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SchrodingerZhu opened this issue Jan 27, 2022 · 4 comments
Closed

Segfault in _Unwind_Backtrace when using compiler-rt #93360

SchrodingerZhu opened this issue Jan 27, 2022 · 4 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.

Comments

@SchrodingerZhu
Copy link

SchrodingerZhu commented Jan 27, 2022

The error was similar as #47551, but it was not exactly the same.

To make sure full LLVM env on Linux, I tried something like:

#!/usr/bin/env bash
/usr/local/bin/clang++ -rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -Wl,-Bdynamic -l:libunwind.so -l:libc++abi.so -l:libc++.so /usr/local/lib/clang/13.0.0/lib/x86_64-unknown-linux-gnu/libclang_rt.builtins.a ${@//*gcc_s*}

and used it as the linker.
Everything is working except that the program crashes in unwinding progress.
image

I have already posted a related thread at LLVM's discourse (please refer this link for more inspections on eh_frame sections): https://llvm.discourse.group/t/segfault-in-libunwind-during-cpu-profiling/5806. But given #47551, I think rustc can also be a cause of the problem.

I have already switched back to shared linkage as it is shown in the script above, but the problem persists, just in different frames.

Versions

LLVM 13.0.0
Rust nightly-2021-04-15

@SchrodingerZhu SchrodingerZhu added the C-bug Category: This is a bug. label Jan 27, 2022
@bossmc
Copy link
Contributor

bossmc commented Jan 27, 2022

Unwinding from Rust into C++ is complex (might even be UB today, I'm not 100% sure, it was blocked in Rust 1.33 but then re-allowed soon after with large safety warnings) - https://github.com/rust-lang/project-ffi-unwind/blob/master/faq.md and related pages might tell you more about the current state of the world.

The presence of the zero terminator suggests this isn't the same issue as #47551 though it might be worth checking that it's at the end of the section and hasn't been inserted in the wrong place (seems unlikely but should be easy to check).

@SchrodingerZhu
Copy link
Author

SchrodingerZhu commented Jan 28, 2022

As a result, we have decided to quit using compiler-rt and llvm's libunwind. Though, I am still looking forward for solutions!

@Enselic
Copy link
Member

Enselic commented Jun 22, 2024

Triage: Can this still be reproduced with latest versions of everything? If yes, please provide detailed step by step instructions on how to reproduce in a fresh docker container.

@jieyouxu
Copy link
Member

Based on https://doc.rust-lang.org/nomicon/unwinding.html unwinding across FFI boundary into another language is at present not supported.

Rust's unwinding strategy is not specified to be fundamentally compatible with any other language's unwinding. As such, unwinding into Rust from another language, or unwinding into another language from Rust is Undefined Behavior. You must absolutely catch any panics at the FFI boundary! What you do at that point is up to you, but something must be done. If you fail to do this, at best, your application will crash and burn. At worst, your application won't crash and burn, and will proceed with completely clobbered state.

Please feel free to reopen if this is about Rust code unwinding into Rust.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
@jieyouxu jieyouxu added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage-legacy labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.
Projects
None yet
Development

No branches or pull requests

5 participants