Skip to content
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

rustc: assertion failiure in llvm when defining __CxxFrameHandler3 #38641

Open
JoNil opened this issue Dec 27, 2016 · 4 comments
Open

rustc: assertion failiure in llvm when defining __CxxFrameHandler3 #38641

JoNil opened this issue Dec 27, 2016 · 4 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. O-windows Operating system: Windows

Comments

@JoNil
Copy link

JoNil commented Dec 27, 2016

I'm building a 64k demo on windows so i'm building without std and without libc. When writing some code a reference to __CxxFrameHandler3 is emitted even though i'm building with panic=abort. I suspect this is because libcore is built with unwinding. In release builds the symbol __CxxFrameHandler3 is optimized away so the program links successfully. If i try to define __CxxFrameHandler3 i get an assertion failure in llvm.

I tried this code:

Build with rustc --crate-type bin -C panic=abort main.rs

#![feature(lang_items)]
#![feature(link_args)]

#![no_std]
#![no_main]

#[link_args = "/SUBSYSTEM:WINDOWS"]
extern "C" {}

#[no_mangle]
pub extern "system" fn __CxxFrameHandler3(_: *mut u8, _: *mut u8, _: *mut u8, _: *mut u8) -> i32 { 0 }

#[no_mangle]
pub extern "system" fn WinMainCRTStartup() {

    for _ in 0..1 {}
}

#[lang = "panic_fmt"]
#[no_mangle]
pub extern "C" fn rust_begin_panic(_: core::fmt::Arguments, _: &'static str, _: u32) -> ! { loop {} }

I expected to see this happen:
Preferably the symbol __CxxFrameHandler3 would not be emitted. But being able to define it without a crash is ok as well.

Instead, this happened:
The symbol __CxxFrameHandler3 is emitted and when i try to define it i get a crash.

Current workaround is to pass /FORCE to the linker to ignore the unresolved symbol.

Meta

rustc --version --verbose:

rustc 1.15.0-nightly (71c06a56a 2016-12-18)
binary: rustc
commit-hash: 71c06a56a120a0d5e3b224105ee3e6754f83e5fa
commit-date: 2016-12-18
host: x86_64-pc-windows-msvc
release: 1.15.0-nightly
LLVM version: 3.9

Output from rustc

Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible type!", file C:\bot\slave\nightly-dist-rustc-win-msvc-64\build\src\llvm\include\llvm/Support/Casting.h, line 237

Backtrace

msvcr120.dll!_wassert(const wchar_t * expr, const wchar_t * filename, unsigned int lineno) Line 142
rustc_llvm-039c192262ead9ec.dll!00007ff969b9b87c()
rustc_trans-ba0c504011b26d52.dll!00007ff970296ccb()
rustc_trans-ba0c504011b26d52.dll!00007ff97026d1b4()
rustc_trans-ba0c504011b26d52.dll!00007ff9702b673b()
rustc_trans-ba0c504011b26d52.dll!00007ff9702debd2()
rustc_trans-ba0c504011b26d52.dll!00007ff97023b9fd()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff9754b8383()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff97548a519()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff9754b5580()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff975404ec9()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff975486553()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff9754d6f77()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff9753bd69f()
std-efe4996faa4fd772.dll!00007ff974114612()
rustc_driver-9b39ebb875ea3d3d.dll!00007ff9753e6bc5()
std-efe4996faa4fd772.dll!00007ff97410c2ff()
@brson
Copy link
Contributor

brson commented Dec 29, 2016

Thanks for the detailed report @JoNil !

cc @vadimcn this might interest you.

@brson brson added O-windows Operating system: Windows A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-wrong labels Dec 29, 2016
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed I-wrong labels Jul 26, 2017
@lygstate
Copy link
Contributor

anyway to resolve this issue?

@Lokathor
Copy link
Contributor

I haven't checked myself but the newish -Zbuild-std=core cargo flag might clear this up, assuming it really is a problem with libcore being compiled with unwinding.

@HoShiMin
Copy link

HoShiMin commented Aug 15, 2023

Still actual - I tried to build a Windows kernel driver using a stable Rust and it failed due to unresolved __CxxFrameHandler3 in libcore for profile.dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

6 participants