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

Open
thesam opened this Issue Jan 24, 2015 · 8 comments

Comments

Projects
None yet
9 participants
@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

This comment has been minimized.

Copy link
Contributor

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!

@tamird

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

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.

@steveklabnik steveklabnik referenced this issue Oct 23, 2015

Closed

Add ICEs to Glacier #29249

171 of 200 tasks complete

wheals added a commit to wheals/glacier that referenced this issue Oct 26, 2015

@wheals wheals referenced this issue Oct 26, 2015

Merged

21599 #61

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Nov 4, 2015

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

This comment has been minimized.

Copy link
Contributor

brson commented Apr 11, 2017

@steveklabnik's code is no longer valid.

@jonas-schievink

This comment has been minimized.

Copy link
Member

jonas-schievink commented Mar 1, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

jonas-schievink commented Oct 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.