signalapp / libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
GNU Affero General Public License v3.0
3.62k stars 420 forks source link

Compilation failed on Linux aarch64 using rustc 1.62.0-nightly (52ca603da 2022-04-12) toolchain #461

Closed iamdavidcz closed 2 years ago

iamdavidcz commented 2 years ago
$ cargo build
   Compiling rsa v0.4.1
   Compiling poksho v0.7.0 (/root/libsignal/rust/poksho)
   Compiling picky-asn1-x509 v0.6.1
   Compiling libsignal-protocol v0.1.0 (/root/libsignal/rust/protocol)
thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/check_unsafety.rs:514:36
stack backtrace:
   0:       0x7fa871e1d8 - std::backtrace_rs::backtrace::libunwind::trace::h484ea3288d633977
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:       0x7fa871e1d8 - std::backtrace_rs::backtrace::trace_unsynchronized::hf6f44f74ad5255b6
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:       0x7fa871e1d8 - std::sys_common::backtrace::_print_fmt::hfcddfe9b7a5ed382
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys_common/backtrace.rs:66:5
   3:       0x7fa871e1d8 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h881a03b519e3e9f3
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys_common/backtrace.rs:45:22
   4:       0x7fa87736e4 - core::fmt::write::h3f9a80509a88c90a
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/core/src/fmt/mod.rs:1194:17
   5:       0x7fa8710990 - std::io::Write::write_fmt::h78481ac4b0957cc7
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/io/mod.rs:1655:15
   6:       0x7fa8720b50 - std::sys_common::backtrace::_print::ha3ddb3273e8daef4
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys_common/backtrace.rs:48:5
   7:       0x7fa8720b50 - std::sys_common::backtrace::print::h4a4b88b11e571ff2
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys_common/backtrace.rs:35:9
   8:       0x7fa8720b50 - std::panicking::default_hook::{{closure}}::heebed878ea6e2d44
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/panicking.rs:295:22
   9:       0x7fa87207b4 - std::panicking::default_hook::hf2d8370112732138
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/panicking.rs:314:9
  10:       0x7fa93910f0 - rustc_driver[ae28b9b1542d7bda]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:       0x7fa87212e8 - std::panicking::rust_panic_with_hook::h7db474d300eff9a4
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/panicking.rs:702:17
  12:       0x7fa87210f4 - std::panicking::begin_panic_handler::{{closure}}::h2e0df0e7ab4e8173
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/panicking.rs:588:13
  13:       0x7fa871e680 - std::sys_common::backtrace::__rust_end_short_backtrace::hf8112199756561af
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys_common/backtrace.rs:138:18
  14:       0x7fa8720e40 - rust_begin_unwind
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/panicking.rs:584:5
  15:       0x7fa86ecf50 - core::panicking::panic_fmt::h35b4d57f126ce24c
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/core/src/panicking.rs:142:14
  16:       0x7fabe50718 - <rustc_data_structures[2ea9f384568c344]::steal::Steal<rustc_middle[1e95c5eaee15de15]::mir::Body>>::borrow
  17:       0x7fabf022e8 - rustc_mir_transform[469e02878311fe1a]::check_unsafety::unsafety_check_result
  18:       0x7fabefeb40 - <rustc_mir_transform[469e02878311fe1a]::check_unsafety::provide::{closure#0} as core[779b785b2414ef9d]::ops::function::FnOnce<(rustc_middle[1e95c5eaee15de15]::ty::context::TyCtxt, rustc_span[1dd2111b1c0d1e99]::def_id::LocalDefId)>>::call_once
  19:       0x7facbaef4c - rustc_query_system[fee54666fb3fac7d]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[ff68f0ff9563a4b5]::plumbing::QueryCtxt, rustc_span[1dd2111b1c0d1e99]::def_id::LocalDefId, &rustc_middle[1e95c5eaee15de15]::mir::query::UnsafetyCheckResult>
  20:       0x7facb4983c - rustc_query_system[fee54666fb3fac7d]::query::plumbing::try_execute_query::<rustc_query_impl[ff68f0ff9563a4b5]::plumbing::QueryCtxt, rustc_query_system[fee54666fb3fac7d]::query::caches::DefaultCache<rustc_span[1dd2111b1c0d1e99]::def_id::LocalDefId, &rustc_middle[1e95c5eaee15de15]::mir::query::UnsafetyCheckResult>>
  21:       0x7facbf2a00 - rustc_query_system[fee54666fb3fac7d]::query::plumbing::get_query::<rustc_query_impl[ff68f0ff9563a4b5]::queries::unsafety_check_result, rustc_query_impl[ff68f0ff9563a4b5]::plumbing::QueryCtxt>
  22:       0x7fabf02cc4 - rustc_mir_transform[469e02878311fe1a]::check_unsafety::check_unsafety
  23:       0x7fa947fc98 - <rustc_session[fffb1e732fe80054]::session::Session>::time::<(), rustc_interface[35a34b3241e021d9]::passes::analysis::{closure#3}>
  24:       0x7fa9459148 - rustc_interface[35a34b3241e021d9]::passes::analysis
  25:       0x7facdbe454 - <rustc_query_system[fee54666fb3fac7d]::dep_graph::graph::DepGraph<rustc_middle[1e95c5eaee15de15]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[1e95c5eaee15de15]::ty::context::TyCtxt, (), core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>
  26:       0x7facb7d8c4 - rustc_query_system[fee54666fb3fac7d]::query::plumbing::try_execute_query::<rustc_query_impl[ff68f0ff9563a4b5]::plumbing::QueryCtxt, rustc_query_system[fee54666fb3fac7d]::query::caches::DefaultCache<(), core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>>
  27:       0x7facc16ba0 - rustc_query_system[fee54666fb3fac7d]::query::plumbing::get_query::<rustc_query_impl[ff68f0ff9563a4b5]::queries::analysis, rustc_query_impl[ff68f0ff9563a4b5]::plumbing::QueryCtxt>
  28:       0x7fa9350524 - <rustc_interface[35a34b3241e021d9]::passes::QueryContext>::enter::<rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>
  29:       0x7fa933666c - <rustc_interface[35a34b3241e021d9]::interface::Compiler>::enter::<rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}::{closure#2}, core[779b785b2414ef9d]::result::Result<core[779b785b2414ef9d]::option::Option<rustc_interface[35a34b3241e021d9]::queries::Linker>, rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>
  30:       0x7fa9396c9c - rustc_span[1dd2111b1c0d1e99]::with_source_map::<core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>, rustc_interface[35a34b3241e021d9]::interface::create_compiler_and_run<core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>, rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}>::{closure#1}>
  31:       0x7fa9337148 - <scoped_tls[dbc99e10f95707b0]::ScopedKey<rustc_span[1dd2111b1c0d1e99]::SessionGlobals>>::set::<rustc_interface[35a34b3241e021d9]::interface::run_compiler<core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>, rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}>::{closure#0}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>
  32:       0x7fa9358624 - std[e71c88b05adb18dd]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[35a34b3241e021d9]::util::run_in_thread_pool_with_globals<rustc_interface[35a34b3241e021d9]::interface::run_compiler<core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>, rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}>::{closure#0}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>::{closure#0}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>
  33:       0x7fa93592dc - <<std[e71c88b05adb18dd]::thread::Builder>::spawn_unchecked_<rustc_interface[35a34b3241e021d9]::util::run_in_thread_pool_with_globals<rustc_interface[35a34b3241e021d9]::interface::run_compiler<core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>, rustc_driver[ae28b9b1542d7bda]::run_compiler::{closure#1}>::{closure#0}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>::{closure#0}, core[779b785b2414ef9d]::result::Result<(), rustc_errors[b2cdd915cfbd9f03]::ErrorGuaranteed>>::{closure#1} as core[779b785b2414ef9d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:       0x7fa872a9c8 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hca674f6abb1c4582
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/alloc/src/boxed.rs:1866:9
  35:       0x7fa872a9c8 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc4256bbc46f51587
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/alloc/src/boxed.rs:1866:9
  36:       0x7fa872a9c8 - std::sys::unix::thread::Thread::new::thread_start::h2fa2ad1961a39a6f
                               at /rustc/52ca603da73ae9eaddf96f77953b33ad8c47cc8e/library/std/src/sys/unix/thread.rs:108:17
  37:       0x7fa84af628 - start_thread
  38:       0x7fa85e601c - <unknown>
  39:                0x0 - <unknown>

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.62.0-nightly (52ca603da 2022-04-12) running on aarch64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `shohmacsha256::HASH_LEN`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `poksho`
warning: build failed, waiting for other jobs to finish...
error[E0786]: found invalid metadata files for crate `num_enum_derive` which `num_enum` depends on
  --> rust/protocol/src/protocol.rs:28:45
   |
28 | #[derive(Copy, Clone, Eq, PartialEq, Debug, num_enum::TryFromPrimitive)]
   |                                             ^^^^^^^^
   |
   = note: invalid metadata version found: /root/libsignal/target/debug/deps/libnum_enum_derive-f6179561222696ce.so

error: cannot determine resolution for the derive macro `num_enum::TryFromPrimitive`
  --> rust/protocol/src/protocol.rs:28:45
   |
28 | #[derive(Copy, Clone, Eq, PartialEq, Debug, num_enum::TryFromPrimitive)]
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

For more information about this error, try `rustc --explain E0786`.
error: could not compile `libsignal-protocol` due to 2 previous errors
awaitlink commented 2 years ago

Have you tried using libsignal's pinned Rust version, which currently is nightly-2021-09-16?

Regarding the compilation issues, there's an ICE that appears to have already been reported in https://github.com/rust-lang/rust/issues/91015 (it could be worth mentioning this issue there explicitly as another example of where it might occur). According to https://github.com/rust-lang/rust/issues/91015#issuecomment-974094077, the issue may be solved if you turn off incremental compilation (I think that can be done by setting the environment variable CARGO_INCREMENTAL=0).

Regarding error[E0786]: found invalid metadata files, perhaps running cargo clean and then building again may resolve it?

Not sure what specifically you could do about error: cannot determine resolution for the derive macro but it may be better to first resolve the other issues, especially the ICE, after which this one might resolve itself.

iamdavidcz commented 2 years ago

@u32i64 I can confirm that with rust version 1.57.0-nightly (2c7bc5e33 2021-09-15) toolchain libsignal compiles just fine. @jrose-signal what is the status of stable toolchain support on aarch64? I can see that https://github.com/signalapp/libsignal/pull/337 has been already merged. Does it mean that stable rust toolchain is now supported on aarch64 or there are still some blockers there?

jrose-signal commented 2 years ago

The only use of nightly is to enable aarch64 builtins in some of our dependent packages that would otherwise run more slowly, so you should be able to use stable to compile; we just don't ourselves. There might be some places where this is enabled unconditionally by target, but that should only be in the bridge crates, not the base ones you'd use from other Rust code.

jrose-signal commented 2 years ago

I just did a cross-compile cargo +stable check --target aarch64-unknown-linux-gnu and it worked fine, so you should be good to go with stable. If that solves your immediate use case, let's close this; if not…we should probably still close this, cause you hit a nightly compiler bug rather than a bug in this library.

iamdavidcz commented 2 years ago

@jrose-signal I can confirm that with the latest stable toolchain rust version 1.60.0 (7737e0b5c 2022-04-04) libsignal compiles fine. Probably it would be good idea to eventually migrate to stable toolchain instead of still relying on old nightly...

jrose-signal commented 2 years ago

We can't do that without taking a speed hit, but we do update to newer nightlies every now and then.