Skip to content

rustc: assertion failiure in llvm when defining __CxxFrameHandler3 #38641

@JoNil

Description

@JoNil

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions