rust-lang / rust

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

`rustc` v1.37.0 freezing when passed `--emit` #64729

Closed staticfloat closed 4 years ago

staticfloat commented 4 years ago

I am distributing rust 1.37.0 (obtained through rustup) inside of an Alpine linux-based container for cross-compiling software for a large number target architectures. While I have successfully managed to install rustc in such a way that I can compile (using rustc --target=${RUST_TRIPLET} -C linker=${TRIPLET}-gcc -o hello hello.rs) for all the different architectures I want, I have noticed that if I pass --emit to rustc, (even just --emit=link, which I believe should be the default) it freezes, spinning forever.

I have been unable to determine why this freezing occurs when --emit is passed but doesn't occur when it's omitted. Running rustc within gdb gives some hints that something is going wrong, but not many:

sandbox:${WORKSPACE}/hello # gdb --args /opt/x86_64-linux-gnu/bin/rustc --target=x86_64-unknown-linux-gnu -C linker=x86_64-linux-gnu-gcc src/main.rs --emit=link
Reading symbols from /opt/x86_64-linux-gnu/bin/rustc...done.
(gdb) r
Starting program: /opt/x86_64-linux-gnu/bin/rustc --target=x86_64-unknown-linux-gnu -C linker=x86_64-linux-gnu-gcc src/main.rs --emit=link
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
process 182 is executing new program: /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fffef7ff700 (LWP 186)]
^C
Thread 1 "rustc" received signal SIGINT, Interrupt.
0x00007ffff759c92d in __GI___pthread_timedjoin_ex (threadid=140737211528960, thread_return=0x0, abstime=0x0, block=<optimized out>) at pthread_join_common.c:89
89      pthread_join_common.c: No such file or directory.

There are two running threads:

(gdb) info threads
  Id   Target Id                               Frame
* 1    Thread 0x7ffff7fe1340 (LWP 193) "rustc" 0x00007ffff759c92d in __GI___pthread_timedjoin_ex (threadid=140737211528960, thread_return=0x0, abstime=0x0, block=<optimized out>)
    at pthread_join_common.c:89
  2    Thread 0x7fffef7ff700 (LWP 197) "rustc" 0x00007ffff7df24b4 in __libc_read (fd=5, buf=0x7fffef7f1080, nbytes=254) at ../sysdeps/unix/sysv/linux/read.c:27

The first is stuck here:

(gdb) bt
#0  0x00007ffff759c92d in __GI___pthread_timedjoin_ex (threadid=140737211528960, thread_return=0x0, abstime=0x0, block=<optimized out>) at pthread_join_common.c:89
#1  0x00007ffff782a22d in std::sys::unix::thread::Thread::join () at src/libstd/sys/unix/thread.rs:165
#2  0x00007ffff7aec4f3 in std::thread::JoinHandle<T>::join () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#3  0x00007ffff7ad9557 in rustc_interface::util::spawn_thread_pool () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#4  0x00007ffff7b3cbe5 in rustc_driver::run_compiler () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#5  0x00007ffff7b0b8e3 in <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once ()
   from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#6  0x00007ffff7ae70c9 in std::panicking::try::do_call () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#7  0x00007ffff782b48a in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:82
#8  0x00007ffff7b45592 in rustc_driver::report_ices_to_stderr_if_any () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#9  0x00007ffff7b45dec in rustc_driver::main () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#10 0x0000555555559423 in std::rt::lang_start::{{closure}} ()
#11 0x00007ffff781a4e3 in std::rt::lang_start_internal::{{closure}} () at src/libstd/rt.rs:49
#12 std::panicking::try::do_call () at src/libstd/panicking.rs:296
#13 0x00007ffff782b48a in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:82
#14 0x00007ffff781b0ad in std::panicking::try () at src/libstd/panicking.rs:275
#15 std::panic::catch_unwind () at src/libstd/panic.rs:394
#16 std::rt::lang_start_internal () at src/libstd/rt.rs:48
#17 0x0000555555559412 in main ()
(gdb)

The second is stuck here:

(gdb) thread 2
[Switching to thread 2 (Thread 0x7fffef7ff700 (LWP 197))]
#0  0x00007ffff7df24b4 in __libc_read (fd=5, buf=0x7fffef7f1080, nbytes=254) at ../sysdeps/unix/sysv/linux/read.c:27
27      ../sysdeps/unix/sysv/linux/read.c: No such file or directory.
(gdb) bt
#0  0x00007ffff7df24b4 in __libc_read (fd=5, buf=0x7fffef7f1080, nbytes=254) at ../sysdeps/unix/sysv/linux/read.c:27
#1  0x00007ffff7ddd8b3 in validate_lib (fd=fd@entry=5, dynamic_addr=<optimized out>, dynamic_size=<optimized out>) at dl-load.c:1422
#2  0x00007ffff7ddf073 in open_verify (
    name=name@entry=0x7fffef7f1250 "/opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/../lib/libLLVM-8-rust-1.37.0-stable.so",
    fbp=fbp@entry=0x7fffef7f14e0, loader=loader@entry=0x7fffed2b5000, whatcode=whatcode@entry=4, mode=mode@entry=-2147483648, found_other_class=found_other_class@entry=0x7fffef7f14cf, free_name=false,
    fd=5) at dl-load.c:1748
#3  0x00007ffff7ddf63d in open_path (name=name@entry=0x7fffecc9861b "libLLVM-8-rust-1.37.0-stable.so", namelen=namelen@entry=32, mode=mode@entry=-2147483648, sps=0x7fffed2b5318,
    realname=realname@entry=0x7fffef7f14d0, fbp=fbp@entry=0x7fffef7f14e0, loader=0x7fffed2b5000, whatcode=4, found_other_class=0x7fffef7f14cf) at dl-load.c:1824
#4  0x00007ffff7de0fe9 in _dl_map_object (loader=0x7fffed2b5000, name=0x7fffecc9861b "libLLVM-8-rust-1.37.0-stable.so", type=2, trace_mode=0, mode=<optimized out>, nsid=<optimized out>) at dl-load.c:2037
#5  0x00007ffff7de5132 in openaux (a=a@entry=0x7fffef7f1d10) at dl-deps.c:63
#6  0x00007ffff6eff18c in __GI__dl_catch_exception (exception=0x7fffef7f1cf0, operate=0x7ffff7de5100 <openaux>, args=0x7fffef7f1d10) at dl-error-skeleton.c:196
#7  0x00007ffff7de5350 in _dl_map_object_deps (map=map@entry=0x7fffed2b5000, preloads=preloads@entry=0x0, npreloads=npreloads@entry=0, trace_mode=trace_mode@entry=0,
    open_mode=open_mode@entry=-2147483648) at dl-deps.c:249
#8  0x00007ffff7deb044 in dl_open_worker (a=a@entry=0x7fffef7f1f50) at dl-open.c:267
#9  0x00007ffff6eff18c in __GI__dl_catch_exception (exception=0x7fffef7f1f30, operate=0x7ffff7deaf40 <dl_open_worker>, args=0x7fffef7f1f50) at dl-error-skeleton.c:196
#10 0x00007ffff7deab9a in _dl_open (
    file=0x7fffed2980a0 "/opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so", mode=-2147483647,
    caller_dlopen=0x7ffff552aff0 <rustc_metadata::dynamic_lib::DynamicLibrary::open+320>, nsid=<optimized out>, argc=6, argv=<optimized out>, env=0x7fffffffdb10) at dl-open.c:594
#11 0x00007ffff7390f26 in dlopen_doit (a=a@entry=0x7fffef7f2180) at dlopen.c:66
#12 0x00007ffff6eff18c in __GI__dl_catch_exception (exception=exception@entry=0x7fffef7f2120, operate=0x7ffff7390ed0 <dlopen_doit>, args=0x7fffef7f2180) at dl-error-skeleton.c:196
#13 0x00007ffff6eff1ff in __GI__dl_catch_error (objname=0x7fffed200070, errstring=0x7fffed200078, mallocedp=0x7fffed200068, operate=<optimized out>, args=<optimized out>) at dl-error-skeleton.c:215
#14 0x00007ffff7391565 in _dlerror_run (operate=operate@entry=0x7ffff7390ed0 <dlopen_doit>, args=args@entry=0x7fffef7f2180) at dlerror.c:162
#15 0x00007ffff7390fc1 in __dlopen (file=<optimized out>, mode=<optimized out>) at dlopen.c:87
#16 0x00007ffff552aff0 in rustc_metadata::dynamic_lib::DynamicLibrary::open ()
   from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/librustc_metadata-f289cf194b04b3f9.so
#17 0x00007ffff6ad72cb in rustc_interface::util::load_backend_from_dylib () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/librustc_interface-7691d2a4317831ca.so
#18 0x00007ffff6ad80f1 in rustc_interface::util::get_codegen_sysroot () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/librustc_interface-7691d2a4317831ca.so
#19 0x00007ffff6b17ec7 in std::sync::once::Once::call_once::{{closure}} () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/librustc_interface-7691d2a4317831ca.so
#20 0x00007ffff7815b54 in std::sync::once::Once::call_inner () at src/libstd/sync/once.rs:392
#21 0x00007ffff6ad6b6a in rustc_interface::util::create_session () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/librustc_interface-7691d2a4317831ca.so
#22 0x00007ffff7ae97b3 in rustc_interface::interface::run_compiler_in_existing_thread_pool ()
   from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#23 0x00007ffff7b0cd42 in std::thread::local::LocalKey<T>::with () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#24 0x00007ffff7b20891 in scoped_tls::ScopedKey<T>::set () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#25 0x00007ffff7b388b4 in syntax::with_globals () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#26 0x00007ffff7b63b1d in std::sys_common::backtrace::__rust_begin_short_backtrace () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#27 0x00007ffff782b48a in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:82
#28 0x00007ffff7aeccc9 in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-1aa233c0fa499347.so
#29 0x00007ffff77fde0f in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/liballoc/boxed.rs:746
#30 0x00007ffff782a170 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/liballoc/boxed.rs:746
#31 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:13
#32 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:79
#33 0x00007ffff759b507 in start_thread (arg=0x7fffef7ff700) at pthread_create.c:463
#34 0x00007ffff6ec657f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Note that there are a few peculiarities about the system it's running inside of:

staticfloat commented 4 years ago

Upon investigating this further, this is almost certainly a problem in our patched glibc; Initially I thought that dl-load.c was in rust, but it's actually within libc, so the most likely issue is that rustc is triggering a codepath that nothing else in our system does. I will re-open if this turns out to be something pathological inside rustc, otherwise sorry for the noise!