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

Stack overflow in rustc when trying to make bare metal executable #20918

Closed
jacquesf opened this issue Jan 11, 2015 · 3 comments
Closed

Stack overflow in rustc when trying to make bare metal executable #20918

jacquesf opened this issue Jan 11, 2015 · 3 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

Comments

@jacquesf
Copy link

I’m playing with making a bare-metal executable in rust. I fully admit to not knowing what I’m doing, but I thought this was worth reporting given that it resulted in a stack overflow in rustc. This was produced with the rust nightly from 2014/1/10. I’m on OS X 10.10.1 and installed rustc from the OS X .pkg flle.

Here’s how I invoked the compiler:

$ rustc spin.rs
spin.rs:4:1: 4:19 warning: use of unstable item, #[warn(unstable)] on by default
spin.rs:4 extern crate core;
          ^~~~~~~~~~~~~~~~~~

thread 'rustc' has overflowed its stack
Illegal instruction: 4

Here’s spin.rs:

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

extern crate core;

use core::fmt::Arguments;

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

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

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

#[lang="panic_fmt"]
pub fn panic_fmt(_fmt: &Arguments, _file_line: &(&'static str, usize)) -> ! {
  loop { }
}

#[lang="start"]
fn main() {
    loop {
    }
}
@jacquesf
Copy link
Author

Backtrace with lldb shows:

  * frame #0: 0x00000001037d3c75 libstd-4e7c5e5c.dylib`rust_stack_exhausted + 37
    frame #1: 0x00000001002f2d5a librustc_trans-4e7c5e5c.dylib`lint::LintId.PartialEq::eq::h6538516d9011515alCr
    frame #2: 0x0000000100188f5c librustc_trans-4e7c5e5c.dylib`trans::common::erase_regions::RegionEraser$LT$$u{27}a$C$$u{20}$u{27}tcx$GT$.TypeFolder$LT$$u{27}tcx$GT$::fold_ty::hdb11fe61773fd770oKk + 44
    frame #3: 0x0000000100188ddd librustc_trans-4e7c5e5c.dylib`trans::common::erase_regions::h7703105742785118771 + 77
    frame #4: 0x000000010018815e librustc_trans-4e7c5e5c.dylib`trans::monomorphize::normalize_associated_type::h3997050791613523510 + 302
    frame #5: 0x0000000100254be5 librustc_trans-4e7c5e5c.dylib`trans::base::decl_rust_fn::h212c352cd5fc4cf8s1r + 325
    frame #6: 0x000000010026665e librustc_trans-4e7c5e5c.dylib`trans::base::register_fn::h4ce0eb41cba7c025dEu + 126
    frame #7: 0x0000000100183948 librustc_trans-4e7c5e5c.dylib`trans::base::get_item_val::hefbbd5389b60e7afc1u + 3752
    frame #8: 0x0000000100266d5d librustc_trans-4e7c5e5c.dylib`trans::base::create_entry_wrapper::create_entry_fn::h2d1d7fcb17403f8awSu + 973
    frame #9: 0x000000010026591a librustc_trans-4e7c5e5c.dylib`trans::base::finish_register_fn::ha1aeb097c10d306eOCu + 666
    frame #10: 0x00000001002666b5 librustc_trans-4e7c5e5c.dylib`trans::base::register_fn::h4ce0eb41cba7c025dEu + 213
    frame #11: 0x0000000100183948 librustc_trans-4e7c5e5c.dylib`trans::base::get_item_val::hefbbd5389b60e7afc1u + 3752
    frame #12: 0x0000000100266d5d librustc_trans-4e7c5e5c.dylib`trans::base::create_entry_wrapper::create_entry_fn::h2d1d7fcb17403f8awSu + 973

<snip>

    frame #11888: 0x0000000100266d1d librustc_trans-4e7c5e5c.dylib`trans::base::create_entry_wrapper::create_entry_fn::hbeda99ebf9512f9fwSu + 973
    frame #11889: 0x00000001002658da librustc_trans-4e7c5e5c.dylib`trans::base::finish_register_fn::hcfc60154d1285818OCu + 666
    frame #11890: 0x0000000100266675 librustc_trans-4e7c5e5c.dylib`trans::base::register_fn::h0ee69c538bdaf7b2dEu + 213
    frame #11891: 0x0000000100183908 librustc_trans-4e7c5e5c.dylib`trans::base::get_item_val::h697b171366de28ecc1u + 3752
    frame #11892: 0x0000000100266d1d librustc_trans-4e7c5e5c.dylib`trans::base::create_entry_wrapper::create_entry_fn::hbeda99ebf9512f9fwSu + 973
    frame #11893: 0x00000001002658da librustc_trans-4e7c5e5c.dylib`trans::base::finish_register_fn::hcfc60154d1285818OCu + 666
    frame #11894: 0x0000000100266675 librustc_trans-4e7c5e5c.dylib`trans::base::register_fn::h0ee69c538bdaf7b2dEu + 213
    frame #11895: 0x0000000100183908 librustc_trans-4e7c5e5c.dylib`trans::base::get_item_val::h697b171366de28ecc1u + 3752
    frame #11896: 0x0000000100180ce7 librustc_trans-4e7c5e5c.dylib`trans::base::trans_item::hdbddd5abd5742b0cEwu + 1063
    frame #11897: 0x000000010026a02c librustc_trans-4e7c5e5c.dylib`trans::base::trans_crate::h6077c32a4f7ba4e9lsv + 6044
    frame #11898: 0x000000010002ab3e librustc_driver-4e7c5e5c.dylib`driver::phase_4_translate_to_llvm::ha92297f2357a645fPFa + 1118
    frame #11899: 0x0000000100006f4b librustc_driver-4e7c5e5c.dylib`driver::compile_input::h31580cbd7ea87613xba + 8075
    frame #11900: 0x00000001000d1fda librustc_driver-4e7c5e5c.dylib`monitor::unboxed_closure.22557 + 6218
    frame #11901: 0x00000001000d0735 librustc_driver-4e7c5e5c.dylib`thunk::F.Invoke$LT$A$C$$u{20}R$GT$::invoke::h6367419564961841226 + 309
    frame #11902: 0x00000001000cf510 librustc_driver-4e7c5e5c.dylib`rt::unwind::try::try_fn::h7763956589852599824 + 160
    frame #11903: 0x000000010383d2a9 libstd-4e7c5e5c.dylib`rust_try_inner + 9
    frame #11904: 0x000000010383d296 libstd-4e7c5e5c.dylib`rust_try + 6
    frame #11905: 0x00000001000cfc0c librustc_driver-4e7c5e5c.dylib`thunk::F.Invoke$LT$A$C$$u{20}R$GT$::invoke::h16724184168577887652 + 1196
    frame #11906: 0x00000001037c4154 libstd-4e7c5e5c.dylib`sys::thread::thread_start::hbd8f2f8bdd3a3baadrw + 164
    frame #11907: 0x00007fff8e51d2fc libsystem_pthread.dylib`_pthread_body + 131
    frame #11908: 0x00007fff8e51d279 libsystem_pthread.dylib`_pthread_start + 176
    frame #11909: 0x00007fff8e51b4b1 libsystem_pthread.dylib`thread_start + 13

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

tamird commented Apr 21, 2015

This no longer overflows the stack - it triggers an LLVM assertion instead. I've reduced the repro case:

#![feature(lang_items, no_std, core)]
#![no_std]
extern crate core;

#[lang = "stack_exhausted"]
extern {}
#[lang = "eh_personality"]
extern {}
#[lang = "panic_fmt"]
extern {}
#[lang = "start"]
fn main() {}
$ rustc main.rs
Incorrect number of arguments passed to called function!
  call void @_ZN4main20hb92ff91aa006d85cgaaE(i8* bitcast (void ()* @_ZN4main20hb92ff91aa006d85cgaaE to i8*), i64 %0, i8** %1)
Function return type does not match operand type of return inst!
  ret void <badref>
 i64LLVM ERROR: Broken function found, compilation aborted!

That said, I'm not really sure what the expected behaviour is.

@steveklabnik steveklabnik added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Apr 21, 2015
@alexcrichton
Copy link
Member

It sounds like the stack overflow has been fixed and otherwise the error here is the signature of the #[lang = "start"] function, you can see the standard library's copy for what the signature should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
Projects
None yet
Development

No branches or pull requests

5 participants