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

no_std + owned_box: thread 'rustc' has overflowed its stack Illegal instruction (core dumped) #21599

Closed
thesam opened this issue Jan 24, 2015 · 10 comments
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@thesam
Copy link

thesam commented Jan 24, 2015

The following code makes rustc core dump. It is hardly a normal use case, but it would be nice if rustc failed more gracefully.

$ cat main.rs
#![no_std]
#![feature(box_syntax)]
#![feature(lang_items)]

extern crate core;

use core::ptr::Unique;

#[lang="owned_box"]
pub struct Box<T>(Unique<T>);

#[lang="start"]
fn main() {
    let mut test:[isize;1] = [0;1];
    let a = box 5;
    test[*a] = 0;
}

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop{} }
$ rustc main.rs
main.rs:5:1: 5:19 warning: use of unstable item, #[warn(unstable)] on by default
main.rs:5 extern crate core;
          ^~~~~~~~~~~~~~~~~~

thread 'rustc' has overflowed its stack
Illegal instruction (core dumped)
@nagisa
Copy link
Member

nagisa commented Jan 24, 2015

Stacktrace:

#0  0x00007ffff75a4a9e in rust_stack_exhausted () from /usr/lib/libstd-4e7c5e5c.so
#1  0x00007ffff6daf2d1 in __morestack () from /usr/lib/librustc_trans-4e7c5e5c.so
#2  0x00007ffff6c44afb in trans::common::erase_regions::h1897340133958074975 () from /usr/lib/librustc_trans-4e7c5e5c.so
#3  0x00007ffff6c43e79 in trans::monomorphize::normalize_associated_type::h13331913048497014448 () from /usr/lib/librustc_trans-4e7c5e5c.so
#4  0x00007ffff6d12601 in trans::base::decl_rust_fn::h0d9b25ac4d9ad3da12r () from /usr/lib/librustc_trans-4e7c5e5c.so
#5  0x00007ffff6d244db in trans::base::register_fn::h30f94f1763494759FDu () from /usr/lib/librustc_trans-4e7c5e5c.so
#6  0x00007ffff6c3f2d3 in trans::base::get_item_val::ha6e256745ba88016f0u () from /usr/lib/librustc_trans-4e7c5e5c.so
#7  0x00007ffff6d24b36 in trans::base::create_entry_wrapper::create_entry_fn::h20ccd41c2d9748a5QRu () from /usr/lib/librustc_trans-4e7c5e5c.so
#8  0x00007ffff6d23823 in trans::base::finish_register_fn::hb6e1021049970835hCu () from /usr/lib/librustc_trans-4e7c5e5c.so
#9  0x00007ffff6d24525 in trans::base::register_fn::h30f94f1763494759FDu () from /usr/lib/librustc_trans-4e7c5e5c.so
#10 0x00007ffff6c3f2d3 in trans::base::get_item_val::ha6e256745ba88016f0u () from /usr/lib/librustc_trans-4e7c5e5c.so
#11 0x00007ffff6d24b36 in trans::base::create_entry_wrapper::create_entry_fn::h20ccd41c2d9748a5QRu () from /usr/lib/librustc_trans-4e7c5e5c.so
#12 0x00007ffff6d23823 in trans::base::finish_register_fn::hb6e1021049970835hCu () from /usr/lib/librustc_trans-4e7c5e5c.so
#13 0x00007ffff6d24525 in trans::base::register_fn::h30f94f1763494759FDu () from /usr/lib/librustc_trans-4e7c5e5c.so
#14 0x00007ffff6c3f2d3 in trans::base::get_item_val::ha6e256745ba88016f0u () from /usr/lib/librustc_trans-4e7c5e5c.so
#15 0x00007ffff6d24b36 in trans::base::create_entry_wrapper::create_entry_fn::h20ccd41c2d9748a5QRu () from /usr/lib/librustc_trans-4e7c5e5c.so
…
#11405 0x00007ffff6d24525 in trans::base::register_fn::h30f94f1763494759FDu () from /usr/lib/librustc_trans-4e7c5e5c.so
#11406 0x00007ffff6c3f2d3 in trans::base::get_item_val::ha6e256745ba88016f0u () from /usr/lib/librustc_trans-4e7c5e5c.so
#11407 0x00007ffff6c3c325 in trans::base::trans_item::hd3c6f46fbe0526db9vu () from /usr/lib/librustc_trans-4e7c5e5c.so
#11408 0x00007ffff6d27bc9 in trans::base::trans_crate::h2ae8e61ccf7256ccjrv () from /usr/lib/librustc_trans-4e7c5e5c.so
#11409 0x00007ffff7af9b44 in driver::phase_4_translate_to_llvm::h9a9812d78c6f6f7bSNa () from /usr/lib/librustc_driver-4e7c5e5c.so
#11410 0x00007ffff7ad5af7 in driver::compile_input::hf24449271908df73Bba () from /usr/lib/librustc_driver-4e7c5e5c.so
#11411 0x00007ffff7b98a5d in run_compiler::hd7bb31ad4d130831R8b () from /usr/lib/librustc_driver-4e7c5e5c.so
#11412 0x00007ffff7b95dd9 in thunk::F.Invoke$LT$A$C$$u{20}R$GT$::invoke::h8032505569135520355 () from /usr/lib/librustc_driver-4e7c5e5c.so
#11413 0x00007ffff7b94b7f in rt::unwind::try::try_fn::h5190150401514006474 () from /usr/lib/librustc_driver-4e7c5e5c.so
#11414 0x00007ffff7611609 in rust_try_inner () from /usr/lib/libstd-4e7c5e5c.so
#11415 0x00007ffff76115f6 in rust_try () from /usr/lib/libstd-4e7c5e5c.so
#11416 0x00007ffff7b951d0 in thunk::F.Invoke$LT$A$C$$u{20}R$GT$::invoke::h18133957152747329837 () from /usr/lib/librustc_driver-4e7c5e5c.so
#11417 0x00007ffff7593a96 in sys::thread::thread_start::h9000ab048e180f84aPw () from /usr/lib/libstd-4e7c5e5c.so
#11418 0x00007ffff1808314 in start_thread () from /usr/lib/libpthread.so.0
#11419 0x00007ffff71a924d in clone () from /usr/lib/libc.so.6

Appears like a more minimal

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

extern crate core;

#[lang="start"]
fn main() {
}

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop{} }

still causes it, which suggests this is a duplicate of #20918.

Thanks for the report!

@kmcallister kmcallister added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-freestanding labels Jan 25, 2015
@tamird
Copy link
Contributor

tamird commented Apr 21, 2015

Doesn't look like a dupe to me, and still ICEs with minor changes:

#![no_std]
#![feature(box_syntax,unique)]
#![feature(no_std,core,lang_items)]

extern crate core;

use core::ptr::Unique;

#[lang="owned_box"]
pub struct Box<T>(Unique<T>);

#[lang="start"]
fn main() {
    let mut test:[isize;1] = [0;1];
    let a = box 5;
    test[*a] = 0;
}

#[lang = "exchange_malloc"] extern fn exchange_malloc() {}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop{} }
$ rustc main.rs
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: dest.is_some()', /Users/tamird/src/rust/src/librustc_trans/trans/callee.rs:844

@nagisa
Copy link
Member

nagisa commented Apr 22, 2015

The backtrace for above:

stack backtrace:
   1:     0x7f0b44c45b39 - sys::backtrace::write::hc94f8d9af2b8711fGUs
   2:     0x7f0b44c4d7c6 - panicking::on_panic::hc9accb046dad794bVhx
   3:     0x7f0b44c0b6f2 - rt::unwind::begin_unwind_inner::ha72df769ba895a835Ww
   4:     0x7f0b4431937e - rt::unwind::begin_unwind::h5106877066291017917
   5:     0x7f0b44366c26 - trans::callee::trans_lang_call::h18525ebc83fc18a5iYn
   6:     0x7f0b4442b2bb - trans::expr::trans_uniq_expr::h6a032a77291fe948WRB
   7:     0x7f0b4442bd76 - trans::expr::trans_unary::hc90e278c567e6845VMB
   8:     0x7f0b4442239c - trans::expr::trans_unadjusted::hef36e85b12071ac58zA
   9:     0x7f0b443f7d98 - trans::expr::trans_into::hd1fc0e2f51949c52W6z
  10:     0x7f0b44477aca - trans::_match::mk_binding_alloca::h12461994849321920681
  11:     0x7f0b4436c47e - trans::base::init_local::hb395d1fe1d0a10ffNVg
  12:     0x7f0b4437cd2e - trans::controlflow::trans_block::h3006d43e68f8b11dZ2u
  13:     0x7f0b4437baf1 - trans::base::trans_closure::h58b74be4b3f2d114KCh
  14:     0x7f0b4437d62a - trans::base::trans_fn::h8b381b99cc95435dsNh
  15:     0x7f0b443806c7 - trans::base::trans_item::h0f743e9af025fb97Ebi
  16:     0x7f0b4438ea1d - trans::base::trans_crate::hc043d7f7defe4b48E0i
  17:     0x7f0b451b6e0a - driver::phase_4_translate_to_llvm::h646ecc6a8cb7c383lOa
  18:     0x7f0b4518f0ba - driver::compile_input::h3818778b4ba8e92bQba
  19:     0x7f0b4524f331 - run_compiler::h474493aa09b9a3f5D4b
  20:     0x7f0b4524cf82 - boxed::F.FnBox<A>::call_box::h16338820608853103440
  21:     0x7f0b4524c4b9 - rt::unwind::try::try_fn::h1219638071771381846
  22:     0x7f0b44cc4fd8 - rust_try_inner
  23:     0x7f0b44cc4fc5 - rust_try
  24:     0x7f0b4524c768 - boxed::F.FnBox<A>::call_box::h2630035671385432388
  25:     0x7f0b44c4c6b1 - sys::thread::create::thread_start::h8a67470ee39a7f26cgw
  26:     0x7f0b3ed03373 - start_thread
  27:     0x7f0b4489427c - clone
  28:                0x0 - <unknown>

This bug appears to be caused by invalid signature of start language item. This will be fixed when (is a dupe, in a sense) #9307 is.

wheals added a commit to wheals/glacier that referenced this issue Oct 26, 2015
@steveklabnik
Copy link
Member

New updated code:

#![no_std]
#![feature(box_syntax)]
#![feature(unique)]
#![feature(no_std)]
#![feature(lang_items)]

use core::ptr::Unique;

#[lang="owned_box"]
pub struct Box<T>(Unique<T>);

#[lang="start"]
fn main() {
    let mut test:[isize;1] = [0;1];
    let a = box 5;
    test[*a] = 0;
}

#[lang = "exchange_malloc"] extern fn exchange_malloc() {}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop{} }

@brson
Copy link
Contributor

brson commented Apr 11, 2017

@steveklabnik's code is no longer valid.

@brson brson added P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 11, 2017
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed C-bug Category: This is a bug. labels Jul 22, 2017
@jonas-schievink
Copy link
Contributor

Updated code:

#![no_std]
#![feature(box_syntax)]
#![feature(unique)]
#![feature(lang_items, ptr_internals)]

use core::ptr::Unique;

#[lang="owned_box"]
pub struct Box<T>(Unique<T>);

#[lang="start"]
fn main() {
    let mut test:[isize;1] = [0;1];
    let a = box 5;
    test[*a] = 0;
}

#[lang = "exchange_malloc"] extern fn exchange_malloc() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop{} }

Current error message:

Incorrect number of arguments passed to called function!
  call void @_ZN10playground15exchange_malloc17h12d7890b832cc498E(i64 8, i64 8), !dbg !22
Invalid bitcast
  %5 = bitcast void <badref> to i64*, !dbg !22
LLVM ERROR: Broken function found, compilation aborted!

Duplicate of #9307

@euclio
Copy link
Contributor

euclio commented Oct 11, 2018

Still reproduces. Updated code:

#![no_std]
#![feature(box_syntax)]
#![feature(lang_items, ptr_internals)]

use core::panic::PanicInfo;
use core::ptr::Unique;

#[lang="owned_box"]
pub struct Box<T>(Unique<T>);

#[lang="start"]
fn main() {
    let mut test:[isize;1] = [0;1];
    let a = box 5;
    test[*a] = 0;
}

#[lang = "exchange_malloc"] extern fn exchange_malloc() {}
#[lang = "eh_personality"] extern fn eh_personality() {}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! { loop {} }

@jonas-schievink
Copy link
Contributor

Still a duplicate of #9307 - the signatures of at least start and exchange_malloc are wrong

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
Alexendoo added a commit to Alexendoo/cargo-bisect-rustc that referenced this issue Apr 20, 2020
This matches the definition [used in glacier], which includes exit status
101 without an accompanying diagnostic (such as rust-lang/rust#21599), and when
rustc is killed by a signal (rust-lang/rust#13368)

This also means no processing modes are capturing stdio, but I didn't
remove it as it may be desired for the regex features discussed in rust-lang#53

[used in glacier]: https://github.com/rust-lang/glacier/blob/77029d8e7f755bd95913d3c741738674d5ccadc3/src/lib.rs#L51-L56
@osa1
Copy link
Contributor

osa1 commented Jan 28, 2021

Last repro above is still valid. Current error message:

$ RUST_BACKTRACE=1 rustc +stage1 test.rs
warning: unused variable: `info`
  --> test.rs:24:10
   |
24 | fn panic(info: &PanicInfo) -> ! {
   |          ^^^^ help: if this is intentional, prefix it with an underscore: `_info`
   |
   = note: `#[warn(unused_variables)]` on by default

Incorrect number of arguments passed to called function!
  call void @_ZN4test15exchange_malloc17hf9eb16c8bdf498d0E(i64 8, i64 8)
Invalid bitcast
  %4 = bitcast void <badref> to i64*
in function _ZN4test4main17h3085c8a5747c85a8E
LLVM ERROR: Broken function found, compilation aborted!

@jonas-schievink
Copy link
Contributor

I don't think there's much point in leaving this open as a duplicate of #9307, so closing in favor of that

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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests