-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Print backtraces for LLVM segfaults and aborts #79153
Comments
Will like to work on this. |
@in42 Awesome! You can claim the issue by adding a comment with
See the rustc dev guide for more information about contributing and working in the compiler codebase. Support is on the #t-compiler/help zulip stream. (I can also answer questions here, but I'll be on vacation next week.) |
@rustbot claim |
Is there a test case which will crash the rustc compiler? |
Stack overflow (in LLVM): $ python3 -c 's = "fn main() {"; s += "\n".join("let x = 0;" for _ in range(6000)); s+= "}"; print(s)' > a.rs
$ rustc -Aunused -g a.rs
thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow Incorrect use of a naked attribute: $ cat b.rs
#![feature(asm)]
#![feature(naked_functions)]
#[naked]
pub unsafe fn f(a: usize, b: usize) -> ! {
asm!("/*{0}*//*{1}*/", in(reg) a, in(reg) b);
unreachable!()
}
$ rustc --crate-type=lib b.rs -O
terminated by signal SIGSEGV (Address boundary error) |
So, I built the However, when trying to check if Where in the |
I may have found the root cause. LLVM tools generally call the
But in the rustc code, neither |
Should I add code to call
? |
Nice find! Adding it directly in librustc_driver isn't ideal since most of the compiler interacts with codegen backends like LLVM through the librustc_codegen_ssa abstraction traits. The actual call to InitLLVM should go somewhere in librustc_codegen_llvm. We should probably wait until right before codegen starts to call it, too, just to avoid doing work we don't have to (if this invocation never gets to codegen. Unless we call into LLVM outside of codegen, but I can't think of rustc ever doing that.) This way you can drop the call into an existing method without having to plumb it through the traits in the ssa crate. I’m not sure the exact best place to call it -- constructor of the CodegenCx maybe? One question to keep in mind is whether we need to do this per codegen backend thread -- I’m guessing not, since it will install a global signal handler. |
I am little bit not sure where InitLLVM is supposed to be called when using llvm as a library as is being done in rustc. Here is the documentation in
So it is probably meant to be called once per process whereas |
I think the query |
@in42 Checking in, were you able to make progress on this? Feel free to ping me on Zulip/Discord if that's easier. |
@rustbot claim |
Implement printing of stack traces on LLVM segfaults and aborts Implement rust-lang#79153 Based on discussion, try to extend the rust_backtrace=1 feature to handle segfault or aborts in the llvm backend
Implement printing of stack traces on LLVM segfaults and aborts Implement rust-lang#79153 Based on discussion, try to extend the rust_backtrace=1 feature to handle segfault or aborts in the llvm backend
When a crash happens in an LLVM tool, it prints a nice backtrace:
But when an LLVM crash happens in rustc we don't, even when RUST_BACKTRACE=1.
This may be a simple matter of calling some LLVM function to set up hooks, but it might be more complicated than that.
The text was updated successfully, but these errors were encountered: