rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.26k stars 12.71k forks source link

"thread 'rustc' has overflowed its stack" in glium on Linux #26467

Closed tomaka closed 6 years ago

tomaka commented 9 years ago

Glium's master branch currently compiles just fine, but this simple pull request makes the compilation fail with:

thread 'rustc' has overflowed its stack

This only happens on Linux and not Windows. Stable and nightly are both affected.

The gl_generator dependency is only used a build dependency to generate some Rust code that is then include!ed in glium. There are only three differences between the Rust code generated by gl_generator 0.0.27 (which overflows) and the code generated by gl_generator 0.0.25 (which works). Two #[derive(Clone)] lines added and one #[allow(raw_pointer_derive)].

One of the two structs newly affected by #[derive(Clone)] is huge (around 2000 members). However the struct compiles just fine by itself. It is used as a field in glium's Context struct but Context itself doesn't derive Clone.

Because of this diagnostic I fear that this is a "real" stack overflow and not just a bug leading to an infinite recursion.

arielb1 commented 9 years ago

Could someone post a stack trace with debuginfo?

alexcrichton commented 9 years ago

Can you also try compiling with RUST_MIN_STACK set to a large value? This may be a legitimate stack overflow.

tomaka commented 9 years ago

Can you also try compiling with RUST_MIN_STACK set to a large value? This may be a legitimate stack overflow.

It worked with 20000000

arielb1 commented 9 years ago

I don't think we should use a stack so large! Could you gist a stack-trace so we can fix this worst-case?

tomaka commented 9 years ago

For some reason RUST_BACKTRACE=1 cargo build doesn't work (no backtrace is shown).

I tried to manually run rustc with RUST_BACKTRACE=1 by copy-pasting the command printed by cargo build --verbose, but that didn't print a backtrace either. And because of multirust I didn't manage to run it in gdb.

alexcrichton commented 9 years ago

@tomaka you may be able to get the most mileage out of:

multirust run stable gdb --args rustc ...
tomaka commented 9 years ago

That worked!

#0  0x00007ffff75a7d6e in rust_stack_exhausted ()
   from /home/pierre/.multirust/toolchains/stable/lib/libstd-4e7c5e5c.so
#1  0x00007ffff57f2081 in __morestack ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc-4e7c5e5c.so
#2  0x00007ffff55b7a5a in middle::subst::SubstFolder$LT$$u27$a$C$$u20$$u27$tcx$GT$.TypeFolder$LT$$u27$tcx$GT$::fold_ty::h8e9ff889f5da0ecfizN ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc-4e7c5e5c.so
#3  0x00007ffff6dae7d4 in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#4  0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#5  0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#6  0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#7  0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#8  0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#9  0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#10 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#11 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#12 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#13 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#14 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#15 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#16 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#17 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#18 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#19 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#20 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#21 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#22 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#23 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#24 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#25 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#26 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#27 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#28 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#29 0x00007ffff6db2b1b in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so

... and so on ...

#2766 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2767 0x00007ffff6db027c in trans::_match::compile_submatch_continue::h394de38ef5e3510afAH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2768 0x00007ffff6dadbb6 in trans::_match::compile_submatch::hbf2d0204fcc69edaluH ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2769 0x00007ffff6db56aa in trans::_match::trans_match_inner::h6119af2a2800890b61H ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2770 0x00007ffff6d766b4 in trans::expr::trans_rvalue_dps_unadjusted::h7c0140fcbfb13319C5A ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2771 0x00007ffff6d4afd8 in trans::expr::trans_into::h10885d95ed8d401aX6z ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2772 0x00007ffff6ccfb0f in trans::controlflow::trans_block::hfa898015a1217b0b02u ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2773 0x00007ffff6cce5b2 in trans::base::trans_closure::h8e5687f4ccb96c5eLCh ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2774 0x00007ffff6cd00eb in trans::base::trans_fn::h0bc8fb6dbe17d6adtNh ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2775 0x00007ffff6cd3c45 in trans::base::trans_item::h4f9c99b1e4474396Fbi ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2776 0x00007ffff6cd3ab9 in trans::base::trans_item::h4f9c99b1e4474396Fbi ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2777 0x00007ffff6ce156e in trans::base::trans_crate::haa02506df24d5efcF0i ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_trans-4e7c5e5c.so
#2778 0x00007ffff7af70fb in driver::phase_4_translate_to_llvm::h86d6fb84c5c936d5hOa ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2779 0x00007ffff7acefab in driver::compile_input::hb78754f2f33c01efQba ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2780 0x00007ffff7b904d2 in run_compiler::h258d36d5501c1cdfz4b ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2781 0x00007ffff7b8e123 in boxed::F.FnBox$LT$A$GT$::call_box::h7239693171334256553 ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2782 0x00007ffff7b8d65a in rt::unwind::try::try_fn::h14329119008520845439 ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2783 0x00007ffff7623ac9 in rust_try_inner ()
   from /home/pierre/.multirust/toolchains/stable/lib/libstd-4e7c5e5c.so
#2784 0x00007ffff7623ab6 in rust_try ()
   from /home/pierre/.multirust/toolchains/stable/lib/libstd-4e7c5e5c.so
#2785 0x00007ffff7b8d909 in boxed::F.FnBox$LT$A$GT$::call_box::h17332056298259451807 ()
   from /home/pierre/.multirust/toolchains/stable/lib/librustc_driver-4e7c5e5c.so
#2786 0x00007ffff75b0042 in sys::thread::create::thread_start::h490278b5c3c0b49faqv () from /home/pierre/.multirust/toolchains/stable/lib/libstd-4e7c5e5c.so
#2787 0x00007ffff1e32182 in start_thread (arg=0x7ffff03ff700)
    at pthread_create.c:312
#2788 0x00007ffff71fa47d in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
arielb1 commented 9 years ago

Ah well trans::_match. That code needs a rewrite, and probably also a "naïve" mode (to avoid blowups).

tomaka commented 9 years ago

Does someone have an idea about what exactly is causing the problem? (I have absoutely no idea what trans::_match is doing and reading the code didn't help) Too many members in the struct? Can it be caused by derive? (would implementing Clone manually solve it?)

This problem is really blocking me. Even if it gets fixed, I don't want to wait until Rust 1.3 or 1.4 is released.

tomaka commented 9 years ago

Note that this problem is still there, but I added a work-around. If someone wants to reproduce, just remove this line and compile glium.

jonas-schievink commented 8 years ago

This works with -Zorbit, so MIR trans will fix this once it's enabled by default

andybarron commented 8 years ago

Isn't MIR enabled by default as of Rust 1.12? And if so, can we close this?

steveklabnik commented 8 years ago

It is, and so we probably can. @tomaka has this ICE gone away?

jonas-schievink commented 6 years ago

https://github.com/glium/glium/pull/1676 suggests this bug is gone for good now

tomaka commented 6 years ago

:tada: