rust-lang / rust

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

ICE when compiling an aya-based program #105130

Closed dmitris closed 1 year ago

dmitris commented 1 year ago

I'm doing a program based on Aya library https://aya-rs.dev/ and in the ebpf-side program (similar to https://github.com/aya-rs/book/blob/main/examples/tc-egress/tc-egress-ebpf/src/main.rs), I added these lines:

use aya_bpf::maps::Array;
#[map(name = "CTRLPARAMS")]
static mut CTRLPARAMS: Array<_, CtrlParams> = Array::<CtrlParams>::with_max_entries(1, 0);

the CtrlParams is defined in the "common" module (like https://github.com/aya-rs/book/blob/main/examples/tc-egress/tc-egress-common/src/lib.rs):

pub struct CtrlParams {
    pub ipv4on: bool,
    pub ipv6on: bool,
}

The ICE happens repeatedly and I saved (checked-in internally) the program that produces this.

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (b7bc90fea 2022-11-21) running on x86_64-unknown-linux-gnu

output of rustup check:

$ rustup check
stable-x86_64-unknown-linux-gnu - Up to date : 1.65.0 (897e37553 2022-11-02)
nightly-x86_64-unknown-linux-gnu - Update available : 1.67.0-nightly (b7bc90fea 2022-11-21) -> 1.67.0-nightly (c97b539e4 2022-11-30)
rustup - Up to date : 1.25.1

compiler flags: --crate-type bin -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 -Z unstable-options

Error output

error: could not compile `ebpftm-ebpf`

Caused by:
  process didn't exit successfully: `rustc --crate-name ebpftm --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 -C metadata=6aecc52ac448e73d -C extra-filename=-6aecc52ac448e73d --out-dir /peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps --target bpfel-unknown-none -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/release/deps --extern aya_bpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libaya_bpf-e57cf92f174fb24f.rlib --extern aya_log_ebpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libaya_log_ebpf-259ee95263fd2745.rlib --extern 'noprelude:compiler_builtins=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libcompiler_builtins-75f59f7760a4a109.rlib' --extern 'noprelude:core=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libcore-bf46212ff7284dad.rlib' --extern ebpftm_common=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libebpftm_common-3e389811fbecf2bb.rlib --extern network_types=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/release/deps/libnetwork_types-d32e77d64f6f4f61.rlib -Z unstable-options` (exit status: 101)
thread 'main' panicked at 'assertion failed: status.success()', xtask/src/build_ebpf.rs:63:5

Full output: https://gist.github.com/dmitris/7c2ac7f25f5dff3e0cb611c4ea15a52f

Backtrace

``` Running `target/debug/xtask build-ebpf` Fresh unicode-ident v1.0.5 Fresh core v0.0.0 (/home/vagrant/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core) Fresh proc-macro2 v1.0.47 Fresh rustc-std-workspace-core v1.99.0 (/home/vagrant/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core) Fresh quote v1.0.21 Fresh compiler_builtins v0.1.82 Fresh syn v1.0.104 Fresh rustversion v1.0.9 Fresh num_enum_derive v0.5.7 Fresh aya-bpf-cty v0.2.1 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh aya-bpf-bindings v0.1.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh num_enum v0.5.7 Fresh aya-bpf-macros v0.1.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh aya-log-common v0.1.13 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh enum-try-from v0.0.1 Fresh aya-log-parser v0.1.11-dev.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh aya-bpf v0.1.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh network-types v0.0.2 Fresh ebpftm-common v0.1.0 (/peng/ebpf-telemetry/ebpftm-common) Fresh aya-log-ebpf-macros v0.1.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Fresh aya-log-ebpf v0.1.0 (http://github.com/aya-rs/aya?branch=main#7fef833e) Compiling ebpftm-ebpf v0.1.0 (/peng/ebpf-telemetry/ebpftm-ebpf) Running `rustc --crate-name ebpftm --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 -C metadata=6aecc52ac448e73d -C extra-filename=-6aecc52ac448e73d --out-dir /peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps --target bpfel-unknown-none -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/debug/deps --extern aya_bpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libaya_bpf-e57cf92f174fb24f.rlib --extern aya_log_ebpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libaya_log_ebpf-259ee95263fd2745.rlib --extern 'noprelude:compiler_builtins=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libcompiler_builtins-75f59f7760a4a109.rlib' --extern 'noprelude:core=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libcore-bf46212ff7284dad.rlib' --extern ebpftm_common=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libebpftm_common-3e389811fbecf2bb.rlib --extern network_types=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libnetwork_types-d32e77d64f6f4f61.rlib -Z unstable-options` error: internal compiler error: /rustc/b7bc90fea3b441234a84b49fdafeb75815eebbab/compiler/rustc_middle/src/ty/visit.rs:103:17: expect tcx.sess.has_errors return true thread 'rustc' panicked at 'Box', /rustc/b7bc90fea3b441234a84b49fdafeb75815eebbab/compiler/rustc_errors/src/lib.rs:1560:9 stack backtrace: 0: std::panicking::begin_panic:: 1: std::panic::panic_any:: 2: ::bug::<&alloc::string::String> 3: ::bug::<&alloc::string::String> 4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, ()>::{closure#0}, ()> 5: rustc_middle::util::bug::opt_span_bug_fmt:: 6: rustc_middle::util::bug::bug_fmt 7: ::error_reported 8: ::write_ty 9: ::enter::::{closure#0}::{closure#1}, &rustc_middle::ty::context::TypeckResults> 10: rustc_hir_typeck::diagnostic_only_typeck 11: rustc_query_system::query::plumbing::try_execute_query::> 12: rustc_query_system::query::plumbing::get_query:: 13: rustc_hir_analysis::collect::type_of::infer_placeholder_type 14: rustc_hir_analysis::collect::type_of::type_of 15: rustc_query_system::query::plumbing::get_query:: 16: rustc_hir_analysis::collect::convert_item 17: ::visit_item_likes_in_module:: 18: rustc_hir_analysis::collect::collect_mod_item_types 19: rustc_query_system::query::plumbing::try_execute_query::> 20: rustc_query_system::query::plumbing::get_query:: 21: ::track_errors:: 22: rustc_hir_analysis::check_crate 23: rustc_interface::passes::analysis 24: rustc_query_system::query::plumbing::try_execute_query::>> 25: rustc_query_system::query::plumbing::get_query:: 26: ::enter::> 27: ::enter::, rustc_errors::ErrorGuaranteed>> 28: rustc_span::with_source_map::, rustc_interface::interface::run_compiler, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#1}> 29: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 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.67.0-nightly (b7bc90fea 2022-11-21) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type bin -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 -Z unstable-options note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [diagnostic_only_typeck] type-checking `CTRLPARAMS` #1 [type_of] computing type of `CTRLPARAMS` #2 [collect_mod_item_types] collecting item types in top-level module #3 [analysis] running analysis passes on this crate end of query stack error: could not compile `ebpftm-ebpf` Caused by: process didn't exit successfully: `rustc --crate-name ebpftm --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 -C metadata=6aecc52ac448e73d -C extra-filename=-6aecc52ac448e73d --out-dir /peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps --target bpfel-unknown-none -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps -L dependency=/peng/ebpf-telemetry/ebpftm-ebpf/../target/debug/deps --extern aya_bpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libaya_bpf-e57cf92f174fb24f.rlib --extern aya_log_ebpf=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libaya_log_ebpf-259ee95263fd2745.rlib --extern 'noprelude:compiler_builtins=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libcompiler_builtins-75f59f7760a4a109.rlib' --extern 'noprelude:core=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libcore-bf46212ff7284dad.rlib' --extern ebpftm_common=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libebpftm_common-3e389811fbecf2bb.rlib --extern network_types=/peng/ebpf-telemetry/ebpftm-ebpf/../target/bpfel-unknown-none/debug/deps/libnetwork_types-d32e77d64f6f4f61.rlib -Z unstable-options` (exit status: 101) thread 'main' panicked at 'assertion failed: status.success()', xtask/src/build_ebpf.rs:63:5 stack backtrace: 0: rust_begin_unwind at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14 2: core::panicking::panic at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5 3: xtask::build_ebpf::build_ebpf at ./xtask/src/build_ebpf.rs:63:5 4: xtask::main at ./xtask/src/main.rs:27:28 5: core::ops::function::FnOnce::call_once at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

dmitris commented 1 year ago

the expected error is:

error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
  --> src/main.rs:34:24
   |
34 | static mut CTRLPARAMS: Array<_, CtrlParams> = Array::<CtrlParams>::with_max_entries(1, 0);
   |                        ^^^^^^^^^^^^^^^^^^^^
   |                        |
   |                        not allowed in type signatures
   |                        help: replace with the correct type: `Array<CtrlParams>`

For more information about this error, try `rustc --explain E0121`.
error: could not compile `ebpftm-ebpf` due to previous error
dmitris commented 1 year ago

after updating the nightly compiler with rustup update from c97b539e4 2022-11-30 to b7bc90fea 2022-11-21, the ICE went away, therefore closing.

albertlarsan68 commented 1 year ago

Can I have the source code that reproduced the ICE @dmitris ? I think it would be beneficial to bisect the fix.

dmitris commented 1 year ago

@albertlarsan68 I'm trying now to reproduce it myself and ... are unable to do so, getting only the legitimate error - even though I have

$ rustup default
nightly-2022-11-22-x86_64-unknown-linux-gnu (default)

and

$ rustc -V
rustc 1.67.0-nightly (b7bc90fea 2022-11-21)

the same code, the same Vagrant VM (Fedora37). The rustup update must have killed it. Do you have any suggestions how to get back to the ICE-producing state? I was doing this:

rustup toolchain install nightly-2022-11-22
rustup default nightly-2022-11-22-x86_64-unknown-linux-gnu
cargo xtask build-ebpf --release

Do you think it would still be helpful for you to see the source code? Nothing particularly special about it but since it's internal, I'd need to ask for a permission and go through the motions.

albertlarsan68 commented 1 year ago

If you can't reproduce it with the same conditions, there is not many chances that I can reproduce it with my setup, but I can try anyway if it does not incur too much overhead on your side.