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

internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1038:9: no MIR available for DefId #115052

Closed
ctz opened this issue Aug 21, 2023 · 5 comments · Fixed by #115114
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ctz
Copy link
Contributor

ctz commented Aug 21, 2023

Code

Sorry, haven't tried to minimise this yet. The repro steps are here:

$ git clone https://github.com/ctz/rustls-experimental.git --branch jbp-generalise-crypto-usage-pt2-ice
$ cd rustls-experimental/
$ cargo +stable test --features secret_extraction
(normal crate compiling output...)
error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1038:9: no MIR available for DefId(20:1808 ~ rustls[ff5a]::tls13::chacha20_poly1305_extract_keys)
(see full error output below...)

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)

Also reproduces in rustc 1.74.0-nightly (5c6a7e71c 2023-08-20)

Error output

   Compiling rustls v0.22.0-alpha.0 (/home/jbp/rustls/rustls)
error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1038:9: no MIR available for DefId(20:1808 ~ rustls[b796]::tls13::chacha20_poly1305_extract_keys)

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/compiler/rustc_errors/src/lib.rs:1651:9
stack backtrace:
   0:     0x7f9ab9475071 - std::backtrace_rs::backtrace::libunwind::trace::h782cc21a5acaf6cb
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f9ab9475071 - std::backtrace_rs::backtrace::trace_unsynchronized::hc579eb24ab204515
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9ab9475071 - std::sys_common::backtrace::_print_fmt::h7223525cfdbacda2
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f9ab9475071 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbd7d55b7108d2ab8
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f9ab94d4d9f - core::fmt::rt::Argument::fmt::hb4f4a02b9bd9dd49
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/fmt/rt.rs:138:9
   5:     0x7f9ab94d4d9f - core::fmt::write::h6d54cd7c9e155ec5
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f9ab9468311 - std::io::Write::write_fmt::h6a453a71c692f63b
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/io/mod.rs:1713:15
   7:     0x7f9ab9474e85 - std::sys_common::backtrace::_print::h1cbaa8b42678f928
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f9ab9474e85 - std::sys_common::backtrace::print::h4ddf81241a51b337
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f9ab9477b47 - std::panicking::default_hook::{{closure}}::hff91f1f484ade5cd
  10:     0x7f9ab9477934 - std::panicking::default_hook::h21f14afd59f7aef9
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:288:9
  11:     0x7f9ab82f70cb - <rustc_driver_impl[a4629e012e48ffc1]::install_ice_hook::{closure#0} as core[95ee2d8017598cc7]::ops::function::FnOnce<(&core[95ee2d8017598cc7]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f9ab947828d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha1f76bdae3c27ab6
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/boxed.rs:1999:9
  13:     0x7f9ab947828d - std::panicking::rust_panic_with_hook::h45f66047b14c555c
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:709:13
  14:     0x7f9ab8801951 - std[edecf719d62c0e6b]::panicking::begin_panic::<rustc_errors[f0469ee7e5c3d3ff]::ExplicitBug>::{closure#0}
  15:     0x7f9ab87fd976 - std[edecf719d62c0e6b]::sys_common::backtrace::__rust_end_short_backtrace::<std[edecf719d62c0e6b]::panicking::begin_panic<rustc_errors[f0469ee7e5c3d3ff]::ExplicitBug>::{closure#0}, !>
  16:     0x7f9ab87fd136 - std[edecf719d62c0e6b]::panicking::begin_panic::<rustc_errors[f0469ee7e5c3d3ff]::ExplicitBug>
  17:     0x7f9ab87f6d94 - <rustc_errors[f0469ee7e5c3d3ff]::HandlerInner>::bug::<alloc[dfb0c3e97fe8b89b]::string::String>
  18:     0x7f9ab87f6b36 - <rustc_errors[f0469ee7e5c3d3ff]::Handler>::bug::<alloc[dfb0c3e97fe8b89b]::string::String>
  19:     0x7f9ab8884fac - rustc_middle[c682e143f9d710c7]::util::bug::opt_span_bug_fmt::<rustc_span[c2ff3b0962b898e5]::span_encoding::Span>::{closure#0}
  20:     0x7f9ab888167a - rustc_middle[c682e143f9d710c7]::ty::context::tls::with_opt::<rustc_middle[c682e143f9d710c7]::util::bug::opt_span_bug_fmt<rustc_span[c2ff3b0962b898e5]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f9ab888164a - rustc_middle[c682e143f9d710c7]::ty::context::tls::with_context_opt::<rustc_middle[c682e143f9d710c7]::ty::context::tls::with_opt<rustc_middle[c682e143f9d710c7]::util::bug::opt_span_bug_fmt<rustc_span[c2ff3b0962b898e5]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f9ab69ba1dd - rustc_middle[c682e143f9d710c7]::util::bug::bug_fmt
  23:     0x7f9ab72d8beb - rustc_monomorphize[9472dad9f96b1e7f]::collector::should_codegen_locally
  24:     0x7f9ab71e506b - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_miri
  25:     0x7f9ab71e4ff7 - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_miri
  26:     0x7f9ab71e4ff7 - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_miri
  27:     0x7f9ab71e4ff7 - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_miri
  28:     0x7f9ab71cd527 - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_items_rec
  29:     0x7f9ab76bace7 - rustc_data_structures[8548742d45a93e9b]::sync::par_for_each_in::<alloc[dfb0c3e97fe8b89b]::vec::Vec<rustc_middle[c682e143f9d710c7]::mir::mono::MonoItem>, rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  30:     0x7f9ab76ba9a0 - <rustc_session[b7d9e6f930bc0bce]::session::Session>::time::<(), rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_crate_mono_items::{closure#1}>
  31:     0x7f9ab76ba5c0 - rustc_monomorphize[9472dad9f96b1e7f]::collector::collect_crate_mono_items
  32:     0x7f9ab76b89a7 - rustc_monomorphize[9472dad9f96b1e7f]::partitioning::collect_and_partition_mono_items
  33:     0x7f9ab79055b9 - rustc_query_impl[6e478c483b869c25]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6e478c483b869c25]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c682e143f9d710c7]::query::erase::Erased<[u8; 24usize]>>
  34:     0x7f9ab790558b - <rustc_query_impl[6e478c483b869c25]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[95ee2d8017598cc7]::ops::function::FnOnce<(rustc_middle[c682e143f9d710c7]::ty::context::TyCtxt, ())>>::call_once
  35:     0x7f9ab7b3ce42 - rustc_query_system[93b6edfdc601e81a]::query::plumbing::try_execute_query::<rustc_query_impl[6e478c483b869c25]::DynamicConfig<rustc_query_system[93b6edfdc601e81a]::query::caches::SingleCache<rustc_middle[c682e143f9d710c7]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[6e478c483b869c25]::plumbing::QueryCtxt, true>
  36:     0x7f9ab7b3c9e6 - rustc_query_impl[6e478c483b869c25]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  37:     0x7f9ab793c769 - rustc_codegen_ssa[b3c509f34a4358db]::base::codegen_crate::<rustc_codegen_llvm[6b638aae027b3fd2]::LlvmCodegenBackend>
  38:     0x7f9ab793c54b - <rustc_codegen_llvm[6b638aae027b3fd2]::LlvmCodegenBackend as rustc_codegen_ssa[b3c509f34a4358db]::traits::backend::CodegenBackend>::codegen_crate
  39:     0x7f9ab75560a2 - <rustc_session[b7d9e6f930bc0bce]::session::Session>::time::<alloc[dfb0c3e97fe8b89b]::boxed::Box<dyn core[95ee2d8017598cc7]::any::Any>, rustc_interface[c65fde630b50e8]::passes::start_codegen::{closure#0}>
  40:     0x7f9ab7555beb - rustc_interface[c65fde630b50e8]::passes::start_codegen
  41:     0x7f9ab7553cdd - <rustc_middle[c682e143f9d710c7]::ty::context::GlobalCtxt>::enter::<<rustc_interface[c65fde630b50e8]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[95ee2d8017598cc7]::result::Result<alloc[dfb0c3e97fe8b89b]::boxed::Box<dyn core[95ee2d8017598cc7]::any::Any>, rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>
  42:     0x7f9ab7551e8d - <rustc_interface[c65fde630b50e8]::queries::Queries>::ongoing_codegen
  43:     0x7f9ab75514a9 - <rustc_interface[c65fde630b50e8]::interface::Compiler>::enter::<rustc_driver_impl[a4629e012e48ffc1]::run_compiler::{closure#1}::{closure#2}, core[95ee2d8017598cc7]::result::Result<core[95ee2d8017598cc7]::option::Option<rustc_interface[c65fde630b50e8]::queries::Linker>, rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>
  44:     0x7f9ab754f5c4 - rustc_span[c2ff3b0962b898e5]::set_source_map::<core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>, rustc_interface[c65fde630b50e8]::interface::run_compiler<core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>, rustc_driver_impl[a4629e012e48ffc1]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  45:     0x7f9ab754f1a1 - <scoped_tls[24938f349c8d16f0]::ScopedKey<rustc_span[c2ff3b0962b898e5]::SessionGlobals>>::set::<rustc_interface[c65fde630b50e8]::interface::run_compiler<core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>, rustc_driver_impl[a4629e012e48ffc1]::run_compiler::{closure#1}>::{closure#0}, core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>
  46:     0x7f9ab754e796 - std[edecf719d62c0e6b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c65fde630b50e8]::util::run_in_thread_pool_with_globals<rustc_interface[c65fde630b50e8]::interface::run_compiler<core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>, rustc_driver_impl[a4629e012e48ffc1]::run_compiler::{closure#1}>::{closure#0}, core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>
  47:     0x7f9ab7ba64c5 - <<std[edecf719d62c0e6b]::thread::Builder>::spawn_unchecked_<rustc_interface[c65fde630b50e8]::util::run_in_thread_pool_with_globals<rustc_interface[c65fde630b50e8]::interface::run_compiler<core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>, rustc_driver_impl[a4629e012e48ffc1]::run_compiler::{closure#1}>::{closure#0}, core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95ee2d8017598cc7]::result::Result<(), rustc_span[c2ff3b0962b898e5]::ErrorGuaranteed>>::{closure#1} as core[95ee2d8017598cc7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x7f9ab94827b5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he3e5dbdfabe0b668
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/boxed.rs:1985:9
  49:     0x7f9ab94827b5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h246f7c7964633611
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/boxed.rs:1985:9
  50:     0x7f9ab94827b5 - std::sys::unix::thread::Thread::new::thread_start::hadf9e3501ff0df23
                               at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys/unix/thread.rs:108:17
  51:     0x7f9ab4e94b43 - start_thread
                               at ./nptl/pthread_create.c:442:8
  52:     0x7f9ab4f26a00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  53:                0x0 - <unknown>

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.71.1 (eb26296b5 2023-08-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `rustls` (example "bench")
Backtrace

$ RUST_BACKTRACE=1 cargo +stable test --features secret_extraction
   Compiling rustls v0.22.0-alpha.0 (/home/jbp/rustls/rustls)
error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1038:9: no MIR available for DefId(20:1808 ~ rustls[b796]::tls13::chacha20_poly1305_extract_keys)

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/compiler/rustc_errors/src/lib.rs:1651:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::HandlerInner>::bug::<alloc::string::String>
   2: <rustc_errors::Handler>::bug::<alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_monomorphize::collector::should_codegen_locally
   8: rustc_monomorphize::collector::collect_miri
   9: rustc_monomorphize::collector::collect_miri
  10: rustc_monomorphize::collector::collect_miri
  11: rustc_monomorphize::collector::collect_miri
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  14: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  15: rustc_monomorphize::collector::collect_crate_mono_items
  16: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  17: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  19: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  20: rustc_interface::passes::start_codegen
  21: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
  22: <rustc_interface::queries::Queries>::ongoing_codegen
  23: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  24: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  25: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.71.1 (eb26296b5 2023-08-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `rustls` (example "bench")

@ctz ctz added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 21, 2023
@ctz
Copy link
Contributor Author

ctz commented Aug 21, 2023

Hoisting the inline structure initialisation into statics makes the ICE go away. That... doesn't make a lot of sense to me.

Diff

diff --git a/rustls/src/tls13/mod.rs b/rustls/src/tls13/mod.rs
index 641d2bfd..e946c4ef 100644
--- a/rustls/src/tls13/mod.rs
+++ b/rustls/src/tls13/mod.rs
@@ -38,11 +38,7 @@ pub(crate) static TLS13_CHACHA20_POLY1305_SHA256_INTERNAL: &Tls13CipherSuite = &
         hash_provider: &crypto::ring::hash::SHA256,
     },
     hmac_provider: &crypto::ring::hmac::HMAC_SHA256,
-    aead_alg: &AeadAlgorithm {
-        alg: &ring::aead::CHACHA20_POLY1305,
-        #[cfg(feature = "secret_extraction")]
-        key_extractor: chacha20_poly1305_extract_keys,
-    },
+    aead_alg: &CHACHA20_POLY1305_AEAD,
     #[cfg(feature = "quic")]
     confidentiality_limit: u64::MAX,
     #[cfg(feature = "quic")]
@@ -58,11 +54,7 @@ pub static TLS13_AES_256_GCM_SHA384: SupportedCipherSuite =
             hash_provider: &crypto::ring::hash::SHA384,
         },
         hmac_provider: &crypto::ring::hmac::HMAC_SHA384,
-        aead_alg: &AeadAlgorithm {
-            alg: &ring::aead::AES_256_GCM,
-            #[cfg(feature = "secret_extraction")]
-            key_extractor: aes_256_gcm_extract_keys,
-        },
+        aead_alg: &AES_256_GCM_AEAD,
         #[cfg(feature = "quic")]
         confidentiality_limit: 1 << 23,
         #[cfg(feature = "quic")]
@@ -80,11 +72,7 @@ pub(crate) static TLS13_AES_128_GCM_SHA256_INTERNAL: &Tls13CipherSuite = &Tls13C
         hash_provider: &crypto::ring::hash::SHA256,
     },
     hmac_provider: &crypto::ring::hmac::HMAC_SHA256,
-    aead_alg: &AeadAlgorithm {
-        alg: &ring::aead::AES_128_GCM,
-        #[cfg(feature = "secret_extraction")]
-        key_extractor: aes_128_gcm_extract_keys,
-    },
+    aead_alg: &AES_128_GCM_AEAD,
     #[cfg(feature = "quic")]
     confidentiality_limit: 1 << 23,
     #[cfg(feature = "quic")]
@@ -188,6 +176,24 @@ impl Tls13AeadAlgorithm for AeadAlgorithm {
     }
 }
 
+static CHACHA20_POLY1305_AEAD: AeadAlgorithm = AeadAlgorithm {
+    alg: &ring::aead::CHACHA20_POLY1305,
+    #[cfg(feature = "secret_extraction")]
+    key_extractor: chacha20_poly1305_extract_keys,
+};
+
+static AES_256_GCM_AEAD: AeadAlgorithm = AeadAlgorithm {
+    alg: &ring::aead::AES_256_GCM,
+    #[cfg(feature = "secret_extraction")]
+    key_extractor: aes_256_gcm_extract_keys,
+};
+
+static AES_128_GCM_AEAD: AeadAlgorithm = AeadAlgorithm {
+    alg: &ring::aead::AES_128_GCM,
+    #[cfg(feature = "secret_extraction")]
+    key_extractor: aes_128_gcm_extract_keys,
+};
+
 struct Tls13MessageEncrypter {
     enc_key: ring::aead::LessSafeKey,
     iv: Iv,

@ctz
Copy link
Contributor Author

ctz commented Aug 21, 2023

Also reproduces in rustc 1.60.0 (7737e0b5c 2022-04-04) which is our current MSRV

@tmiasko
Copy link
Contributor

tmiasko commented Aug 21, 2023

$ cat a.rs
pub static G: &fn() = &F;
pub(crate) static F: fn() = f;
fn f() {}
$ cat b.rs
pub static H: fn() = *a::G;
$ rustc --edition=2021 --crate-type=lib a.rs 
$ rustc --edition=2021 --crate-type=lib b.rs -L. --extern a

The implementation here should probably also recurse into DefKind::Static(_):

// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
self.worklist.push(def_id);
}

@tmiasko tmiasko removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 21, 2023
@estebank
Copy link
Contributor

@tmiasko I can confirm that the ICE goes away with the suggested patch.

@estebank estebank added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Aug 21, 2023
@ctz
Copy link
Contributor Author

ctz commented Aug 22, 2023

Hoisting the inline structure initialisation into statics makes the ICE go away. That... doesn't make a lot of sense to me.

Possibly related -- while this made the ICE go away, the code when compiled in --release mode seems to not link.

mysterious link error

warning: `rustls` (lib) generated 1 warning
warning: `rustls` (lib test) generated 1 warning (1 duplicate)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jbp/toolchain/bin:/home/jbp/.cargo/bin:/home/jbp/bin:/home/jbp/.cargo/bin:/home/jbp/bin:/home/jbp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/usr/local/go/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcgj1adm/symbols.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.00.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.01.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.02.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.03.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.04.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.05.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.06.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.07.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.08.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.09.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.10.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.11.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.12.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.13.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.14.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.15.rcgu.o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.4yfxgmi0yd4167ki.rcgu.o" "-Wl,--as-needed" "-L" "/home/jbp/rustls/target/release/deps" "-L" "/home/jbp/rustls/target/release/build/ring-ca5d7c3832353211/out" "-L" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/jbp/rustls/target/release/deps/librustls_pemfile-699db5640a12b66b.rlib" "/home/jbp/rustls/target/release/deps/libbase64-5135c0ba5599734c.rlib" "/home/jbp/rustls/target/release/deps/librustls-3437a4b9d1ad923e.rlib" "/home/jbp/rustls/target/release/deps/libsubtle-125740b2f580e146.rlib" "/home/jbp/rustls/target/release/deps/libwebpki-05e0d6066b17c12b.rlib" "/home/jbp/rustls/target/release/deps/libring-4e12904ac70eb113.rlib" "/home/jbp/rustls/target/release/deps/libspin-2d84d685cee078a5.rlib" "/home/jbp/rustls/target/release/deps/libuntrusted-0b41fa6b505980ec.rlib" "/home/jbp/rustls/target/release/deps/libonce_cell-6f3cf8d745c17842.rlib" "/home/jbp/rustls/target/release/deps/liblibc-34f851571fe4293c.rlib" "/home/jbp/rustls/target/release/deps/liblog-cef6d989ca439e0c.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-19964a87984cce8a.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-0ad64a60ea2c4aaa.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-37a5cbc9c5c20c04.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-e8cedd2960ff146a.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-5deb081ad96d9130.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-22c964fd8f2dfaf9.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-6971442fd1c2cfbb.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-ec7906ee77b1d540.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-4307a3ebc7f0bfcf.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-c2ab156d57b93da1.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-763bbb8717f828b7.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-eb9ba65f17380c5d.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-4286d0bf3addfc05.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fa17a4d002f91ad9.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ff4ae84067796be3.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-6f47c72c85a10103.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-cd2f2bc505f56f50.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-ec02dd343723da85.rlib" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-4df0073ab5846ddb.rlib" "-Wl,-Bdynamic" "-lc" "-lm" "-lrt" "-lpthread" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/jbp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/jbp/rustls/target/release/examples/bench-c7c088c20838e815" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.01.rcgu.o:(.data.rel.ro..Lanon.6c8d586243fa4a749cdd4345bf6f8b3a.58+0x10): undefined reference to `rustls::crypto::ring::tls13::CHACHA20_POLY1305_AEAD'
          /usr/bin/ld: /home/jbp/rustls/target/release/examples/bench-c7c088c20838e815.bench.7b72daa210fee4e9-cgu.01.rcgu.o:(.data.rel.ro..Lanon.6c8d586243fa4a749cdd4345bf6f8b3a.60+0x10): undefined reference to `rustls::crypto::ring::tls13::AES_128_GCM_AEAD'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `rustls` (example "bench") due to previous error
warning: build failed, waiting for other jobs to finish...

Naively -- with no understanding of rustc internals -- it feels like a reachability pass that doesn't find these values won't emit them into the library?

Slapping some extra #[used] attributes around the place is a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants