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 crash on stable #70078

Closed
DutchGhost opened this issue Mar 17, 2020 · 4 comments
Closed

rustc crash on stable #70078

DutchGhost opened this issue Mar 17, 2020 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Mar 17, 2020

I tried this code:

mod internal {
    extern "C" {
        pub static main: fn();
    }
}

fn main() {
    unsafe { internal::main() }
}

I expected to see this happen: This program should compile, and probably crash at runtime

Instead, this happened: rustc crashes with exit code: 0xc0000374, STATUS_HEAP_CORRUPTION), (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION), and (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN). Each time I run cargo build, rustc exits with one of those 3 statuses.

Oh, and one time I got it to ICE instead, which the backtrace is from

Meta

rustc --version --verbose:

rustc 1.41.1 (f3e1a954d 2020-02-24)
Backtrace

warning: `extern` block uses type `fn()`, which is not FFI-safe
 --> src\main.rs:3:26
  |
3 |         pub static main: fn();
  |                          ^^^^ not FFI-safe
  |
  = note: `#[warn(improper_ctypes)]` on by default
  = help: consider using an `extern fn(...) -> ...` function pointer instead
  = note: this function pointer has Rust-specific calling convention

thread 'rustc' panicked at 'out of bounds argument access: 0 out of 0 arguments', src\librustc_codegen_llvm\llvm\mod.rs:200:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSliceMut as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: std::panicking::begin_panic_fmt
   9: rustc_codegen_llvm::abi::<impl rustc_codegen_ssa::traits::abi::AbiBuilderMethods for rustc_codegen_llvm::builder::Builder>::get_param
  10: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  11: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  12: <rustc_codegen_llvm::base::ValueIter as core::iter::traits::iterator::Iterator>::next
  13: <rustc_codegen_llvm::back::lto::ThinLTOImports as core::fmt::Debug>::fmt
  14: <rustc_codegen_llvm::base::ValueIter as core::iter::traits::iterator::Iterator>::next
  15: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  16: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  17: rustc_interface::passes::QueryContext::print_stats
  18: rustc_interface::passes::QueryContext::print_stats
  19: <env_logger::filter::inner::Filter as core::fmt::Debug>::fmt
  20: rustc_interface::queries::Queries::ongoing_codegen
  21: rustc_driver::pretty::print_after_hir_lowering
  22: <syntax_pos::symbol::SymbolStr as core::fmt::Display>::fmt
  23: <chalk_engine::stack::StackIndex as core::convert::From<usize>>::from
  24: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  25: <chalk_engine::stack::StackIndex as core::convert::From<usize>>::from
  26: _rust_maybe_catch_panic
  27: rustc_driver::pretty::print_after_hir_lowering
  28: ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Send$u2b$core..marker..Sync$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  29: std::sys::windows::thread::Thread::new
  30: BaseThreadInitThunk
  31: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.41.1 (f3e1a954d 2020-02-24) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `mainfun`.

@DutchGhost DutchGhost added the C-bug Category: This is a bug. label Mar 17, 2020
@Aaron1011
Copy link
Member

On beta and nightly, this gives the following error:

error: entry symbol `main` declared multiple times
 --> src/main.rs:7:1
  |
7 | / fn main() {
8 | |     unsafe { internal::main() }
9 | | }
  | |_^
  |
  = help: did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead

@jonas-schievink
Copy link
Contributor

This issue looks like #67946, which was fixed by #69379, so closing as fixed.

@DutchGhost
Copy link
Contributor Author

And what about the ICE? has that been fixed as well?

@jonas-schievink
Copy link
Contributor

It should, since this code is rejected before hitting codegen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants