Skip to content

ICE: index out of bounds in cg_ssa/src/back/archive.rs #129557

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

Closed
rogelx opened this issue Aug 25, 2024 · 18 comments
Closed

ICE: index out of bounds in cg_ssa/src/back/archive.rs #129557

rogelx opened this issue Aug 25, 2024 · 18 comments
Labels
C-gub Category: the reverse of a compiler bug is generally UB 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.

Comments

@rogelx
Copy link

rogelx commented Aug 25, 2024

Code

<code>

Meta

rustc --version --verbose:

<version>

Error output

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/archive.rs:453:29:
range end index 56048152 out of range for slice of length 54914853
Backtrace

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/archive.rs:453:29:
range end index 56048152 out of range for slice of length 54914853
stack backtrace:
   0:     0x7943a4a7dae5 - std::backtrace::Backtrace::create::h7d2dc8e7359e23d1
   1:     0x7943a31d7fe5 - std::backtrace::Backtrace::force_capture::h9da8509fb866dd5e
   2:     0x7943a2365fce - std[a1dbd854c1325271]::panicking::update_hook::<alloc[3fbf3ac9bf9e6fee]::boxed::Box<rustc_driver_impl[efee53de8626d180]::install_ice_hook::{closure#0}>>::{closure#0}
   3:     0x7943a31efe57 - std::panicking::rust_panic_with_hook::h76eaaf856d4627ce
   4:     0x7943a31efb17 - std::panicking::begin_panic_handler::{{closure}}::h822501910e3f1a1e
   5:     0x7943a31ed319 - std::sys::backtrace::__rust_end_short_backtrace::hd0a94a8e1050aebb
   6:     0x7943a31ef7e4 - rust_begin_unwind
   7:     0x7943a10be9b3 - core::panicking::panic_fmt::h20afa97c0700e760
   8:     0x7943a0d84537 - core::slice::index::slice_end_index_len_fail::h67e874000ea72dbd
   9:     0x7943a470bf7a - <rustc_codegen_ssa[ab9517ab64be802e]::back::archive::ArArchiveBuilder>::build_inner
  10:     0x7943a47095f0 - <rustc_codegen_ssa[ab9517ab64be802e]::back::archive::ArArchiveBuilder as rustc_codegen_ssa[ab9517ab64be802e]::back::archive::ArchiveBuilder>::build
  11:     0x7943a1aa6fec - rustc_codegen_ssa[ab9517ab64be802e]::back::link::link_binary
  12:     0x7943a49209be - <rustc_codegen_llvm[9d3d159f4de86b58]::LlvmCodegenBackend as rustc_codegen_ssa[ab9517ab64be802e]::traits::backend::CodegenBackend>::link
  13:     0x7943a4920434 - <rustc_interface[aa59e22bcd409986]::queries::Linker>::link
  14:     0x7943a47ebb23 - rustc_interface[aa59e22bcd409986]::interface::run_compiler::<core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>, rustc_driver_impl[efee53de8626d180]::run_compiler::{closure#0}>::{closure#1}
  15:     0x7943a236fd5d - <rayon_core[3d20b23d40a5251c]::job::StackJob<rayon_core[3d20b23d40a5251c]::latch::LatchRef<rayon_core[3d20b23d40a5251c]::latch::LockLatch>, <rayon_core[3d20b23d40a5251c]::registry::Registry>::in_worker_cold<<rayon_core[3d20b23d40a5251c]::thread_pool::ThreadPool>::install<rustc_interface[aa59e22bcd409986]::util::run_in_thread_pool_with_globals<rustc_interface[aa59e22bcd409986]::interface::run_compiler<core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>, rustc_driver_impl[efee53de8626d180]::run_compiler::{closure#0}>::{closure#1}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}::{closure#0}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#0}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>> as rayon_core[3d20b23d40a5251c]::job::Job>::execute
  16:     0x7943a1e8d8de - <rayon_core[3d20b23d40a5251c]::registry::WorkerThread>::wait_until_cold
  17:     0x7943a1e8b469 - <rayon_core[3d20b23d40a5251c]::registry::ThreadBuilder>::run
  18:     0x7943a2368617 - <<crossbeam_utils[12652dbc0cf7bb47]::thread::ScopedThreadBuilder>::spawn<<rayon_core[3d20b23d40a5251c]::ThreadPoolBuilder>::build_scoped<rustc_interface[aa59e22bcd409986]::util::run_in_thread_pool_with_globals<rustc_interface[aa59e22bcd409986]::interface::run_compiler<core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>, rustc_driver_impl[efee53de8626d180]::run_compiler::{closure#0}>::{closure#1}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[aa59e22bcd409986]::util::run_in_thread_pool_with_globals<rustc_interface[aa59e22bcd409986]::interface::run_compiler<core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>, rustc_driver_impl[efee53de8626d180]::run_compiler::{closure#0}>::{closure#1}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[ba50336fd15f7b99]::result::Result<(), rustc_span[7709997ecec77dfd]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[ba50336fd15f7b99]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  19:     0x7943a235be0e - std[a1dbd854c1325271]::sys::backtrace::__rust_begin_short_backtrace::<alloc[3fbf3ac9bf9e6fee]::boxed::Box<dyn core[ba50336fd15f7b99]::ops::function::FnOnce<(), Output = ()> + core[ba50336fd15f7b99]::marker::Send>, ()>
  20:     0x7943a236830a - <<std[a1dbd854c1325271]::thread::Builder>::spawn_unchecked_<alloc[3fbf3ac9bf9e6fee]::boxed::Box<dyn core[ba50336fd15f7b99]::ops::function::FnOnce<(), Output = ()> + core[ba50336fd15f7b99]::marker::Send>, ()>::{closure#1} as core[ba50336fd15f7b99]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x7943a487e6ab - std::sys::pal::unix::thread::Thread::new::thread_start::h524c2fb54e75be43
  22:     0x79439ea9ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  23:     0x79439eb29c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  24:                0x0 - <unknown>


rustc version: 1.82.0-nightly (4074d4902 2024-08-23)
platform: x86_64-unknown-linux-gnu

@rogelx rogelx 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 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 25, 2024
@saethlin
Copy link
Member

saethlin commented Aug 25, 2024

@rogelx How did you run into this ICE? What were you compiling?

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 25, 2024
@rogelx
Copy link
Author

rogelx commented Aug 26, 2024

a kvm project using menflow @saethlin

@rogelx
Copy link
Author

rogelx commented Aug 26, 2024

Compiling bit-vec v0.6.3
thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/archive.rs:453:29:
range end index 56048152 out of range for slice of length 54914853
stack backtrace:
0: 0x70ca807e6d3d - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4178db4b62b6a7c8
1: 0x70ca81004c97 - core::fmt::write::hdebf67a64074cdfd
2: 0x70ca822c3511 - std::io::Write::write_fmt::h67b07a8971426909
3: 0x70ca807e941b - std::panicking::default_hook::{{closure}}::hb33c35cc1f4b50b3
4: 0x70ca807e908e - std::panicking::default_hook::h2c83543c651f3125
5: 0x70ca7f95fc79 - std[6e15924ca43b8509]::panicking::update_hook::<alloc[74339d1d9b201e21]::boxed::Box<rustc_driver_impl[d6b1c5b97f2d776c]::install_ice_hook::{closure#0}>>::{closure#0}
6: 0x70ca807e9d37 - std::panicking::rust_panic_with_hook::h48ec1454fab3e9d6
7: 0x70ca807e99f7 - std::panicking::begin_panic_handler::{{closure}}::hdfdc79a140009172
8: 0x70ca807e71f9 - std::sys::backtrace::__rust_end_short_backtrace::h5e9ef3624d34a08c
9: 0x70ca807e96c4 - rust_begin_unwind
10: 0x70ca7d99f263 - core::panicking::panic_fmt::h5c7dda2686e962d9
11: 0x70ca7ec02867 - core::slice::index::slice_end_index_len_fail::h2d5540bcb1f80daa
12: 0x70ca81c5373a - <rustc_codegen_ssa[360404bd41fe828f]::back::archive::ArArchiveBuilder>::build_inner
13: 0x70ca81c50db0 - <rustc_codegen_ssa[360404bd41fe828f]::back::archive::ArArchiveBuilder as rustc_codegen_ssa[360404bd41fe828f]::back::archive::ArchiveBuilder>::build
14: 0x70ca7ec0d3ec - rustc_codegen_ssa[360404bd41fe828f]::back::link::link_binary
15: 0x70ca81f8fcbe - <rustc_codegen_llvm[4ac59c4c50f2d586]::LlvmCodegenBackend as rustc_codegen_ssa[360404bd41fe828f]::traits::backend::CodegenBackend>::link
16: 0x70ca81f8f734 - <rustc_interface[eb6eb7ed9ab023cb]::queries::Linker>::link
17: 0x70ca81df4c23 - rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler::<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}
18: 0x70ca7f96a0bd - <rayon_core[b59a5ddc7c964e89]::job::StackJob<rayon_core[b59a5ddc7c964e89]::latch::LatchRef<rayon_core[b59a5ddc7c964e89]::latch::LockLatch>, <rayon_core[b59a5ddc7c964e89]::registry::Registry>::in_worker_cold<<rayon_core[b59a5ddc7c964e89]::thread_pool::ThreadPool>::install<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_pool_with_globals<rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>> as rayon_core[b59a5ddc7c964e89]::job::Job>::execute
19: 0x70ca7f48583e - <rayon_core[b59a5ddc7c964e89]::registry::WorkerThread>::wait_until_cold
20: 0x70ca7f4833c9 - <rayon_core[b59a5ddc7c964e89]::registry::ThreadBuilder>::run
21: 0x70ca7f9628f7 - <<crossbeam_utils[69f3e4e9922a2578]::thread::ScopedThreadBuilder>::spawn<<rayon_core[b59a5ddc7c964e89]::ThreadPoolBuilder>::build_scoped<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_pool_with_globals<rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_pool_with_globals<rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[f2f627d3c87d2691]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
22: 0x70ca7f95584e - std[6e15924ca43b8509]::sys::backtrace::_rust_begin_short_backtrace::<alloc[74339d1d9b201e21]::boxed::Box<dyn core[f2f627d3c87d2691]::ops::function::FnOnce<(), Output = ()> + core[f2f627d3c87d2691]::marker::Send>, ()>
23: 0x70ca7f9625ea - <<std[6e15924ca43b8509]::thread::Builder>::spawn_unchecked<alloc[74339d1d9b201e21]::boxed::Box<dyn core[f2f627d3c87d2691]::ops::function::FnOnce<(), Output = ()> + core[f2f627d3c87d2691]::marker::Send>, ()>::{closure#1} as core[f2f627d3c87d2691]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
24: 0x70ca81e6fd6b - std::sys::pal::unix::thread::Thread::new::thread_start::h5ac727470998e7f2
Compiling unicode-segmentation v1.11.0
25: 0x70ca7c09ca94 - start_thread
at ./nptl/pthread_create.c:447:8
26: 0x70ca7c129c3c - clone3
at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
27: 0x0 -

error: 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: please make sure that you have updated to the latest nightly

note: please attach the file at /home/jason/.cargo/registry/src/mirrors.aliyun.com-8754fae0eb2f08f1/v8-0.103.0/rustc-ice-2024-08-25T09_59_20-200180.txt to your bug report

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C linker=clang -C strip=debuginfo -C link-arg=-fuse-ld=lld -Z share-generics=y -Z threads=0 -Z macro-backtrace

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

query stack during panic:
end of query stack
Compiling tonic-build v0.12.1
Compiling overload v0.1.1
Compiling data-url v0.3.1
Compiling deno_media_type v0.1.4
Compiling nu-ansi-term v0.46.0
Compiling zvariant v4.2.0
Compiling include-flate-codegen v0.2.0
Compiling swc_ecma_transforms_typescript v0.195.0
Compiling oxc_minifier v0.24.3
Compiling parse-js v0.20.1
Compiling bit-set v0.5.3
Compiling reqwest v0.12.7
Compiling dprint-swc-ext v0.19.0
Compiling serde_v8 v0.213.0
Compiling clap v4.5.16
Compiling rand v0.3.23
Compiling async-stream v0.3.5
Compiling matchers v0.1.0
Compiling memflow-win32-defs v0.2.0
Compiling crossterm v0.28.1
Compiling swc_ecma_transforms_proposal v0.178.0
Compiling swc_ecma_loader v0.49.1
Compiling async-broadcast v0.7.1
Compiling zbus_macros v4.4.0
Compiling rand_isaac v0.1.1
Compiling rand_xorshift v0.1.1
Compiling rand_hc v0.1.0
Compiling deno_unsync v0.4.1
Compiling zbus_names v3.0.0
Compiling sourcemap v8.0.1
Compiling unicode-truncate v1.1.0
Compiling lru v0.12.4
Compiling xattr v1.3.1
Compiling skyapex-derive v0.1.0 (/home/jason/apex/apexsky/apex_dma/lib/skyapex/skyapex-derive)
Compiling pelite v0.10.0
Compiling scan_fmt v0.2.6
Compiling bincode v1.3.3
Compiling tracing-serde v0.1.3
Compiling swc_visit_macros v0.5.13
Compiling bytemuck v1.17.0
Compiling serde_repr v0.1.19
Compiling instability v0.3.2
Compiling swc_ecma_codegen v0.155.0
Compiling num-derive v0.4.2
error: could not compile v8 (lib)
warning: build failed, waiting for other jobs to finish...

@devsnek
Copy link
Contributor

devsnek commented Nov 6, 2024

I've just hit this on 1.82.0 stable. Interestingly also while building the v8 crate 😄

@saethlin saethlin changed the title rust compile error ICE: index out of bounds in cg_ssa/src/back/archive.rs Nov 6, 2024
@foxx
Copy link

foxx commented Jan 7, 2025

Just ran into this same issue while building v8 crate too. It was building fine a few days ago, there again I am on nightly.

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/archive.rs:472:29:
range end index 50665808 out of range for slice of length 50659328
stack backtrace:
   0:     0x7f3bc893aca5 - std::backtrace::Backtrace::create::h49cf04578963fdc5
   1:     0x7f3bc6ebce85 - std::backtrace::Backtrace::force_capture::hd4872c7bc65cde41
   2:     0x7f3bc605200e - std[fac44eaeb111bcc8]::panicking::update_hook::<alloc[66489a0f9c76ca63]::boxed::Box<rustc_driver_impl[1ee6f045412d773c]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x7f3bc6ed5253 - std::panicking::rust_panic_with_hook::h1cf1663d92a293a0
   4:     0x7f3bc6ed4f4a - std::panicking::begin_panic_handler::{{closure}}::had554dcf018971db
   5:     0x7f3bc6ed2ae9 - std::sys::backtrace::__rust_end_short_backtrace::hefbe23e83e53be67
   6:     0x7f3bc6ed4c0d - rust_begin_unwind
   7:     0x7f3bc3b9cb40 - core::panicking::panic_fmt::haccb7628e277b865
   8:     0x7f3bc5a872f7 - core::slice::index::slice_end_index_len_fail::do_panic::runtime::h464f069a5b86dbfe
   9:     0x7f3bc52782da - core::slice::index::slice_end_index_len_fail::h1fa0fb4a7587ffdc
  10:     0x7f3bc834da24 - <rustc_codegen_ssa[d8b4a3d99ad9c652]::back::archive::ArArchiveBuilder as rustc_codegen_ssa[d8b4a3d99ad9c652]::back::archive::ArchiveBuilder>::build
  11:     0x7f3bc86000a3 - rustc_codegen_ssa[d8b4a3d99ad9c652]::back::link::link_binary
  12:     0x7f3bc85ff41e - <rustc_interface[a5b8f6a3ca67129a]::queries::Linker>::link
  13:     0x7f3bc8511864 - rustc_interface[a5b8f6a3ca67129a]::interface::run_compiler::<(), rustc_driver_impl[1ee6f045412d773c]::run_compiler::{closure#0}>::{closure#1}
  14:     0x7f3bc8414c07 - std[fac44eaeb111bcc8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a5b8f6a3ca67129a]::util::run_in_thread_with_globals<rustc_interface[a5b8f6a3ca67129a]::util::run_in_thread_pool_with_globals<rustc_interface[a5b8f6a3ca67129a]::interface::run_compiler<(), rustc_driver_impl[1ee6f045412d773c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  15:     0x7f3bc84150a4 - <<std[fac44eaeb111bcc8]::thread::Builder>::spawn_unchecked_<rustc_interface[a5b8f6a3ca67129a]::util::run_in_thread_with_globals<rustc_interface[a5b8f6a3ca67129a]::util::run_in_thread_pool_with_globals<rustc_interface[a5b8f6a3ca67129a]::interface::run_compiler<(), rustc_driver_impl[1ee6f045412d773c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[249175d58a5edd5c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  16:     0x7f3bc8416681 - std::sys::pal::unix::thread::Thread::new::thread_start::h1f4f8d3a2ffc672f
  17:     0x7f3bc9bb51c4 - start_thread
                               at ./nptl/pthread_create.c:442:8
  18:     0x7f3bc9c3585c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0
  19:                0x0 - <unknown>


rustc version: 1.86.0-nightly (243d2ca4d 2025-01-06)
platform: x86_64-unknown-linux-gnu%                                                                                                                                                                                                                                                         
[package]
name = "sample"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = "4.5.23"
divan = "0.1.17"
serde = "1.0.217"
serde_json = "1.0.135"
v8 = "130.0.6"
wasm-bindgen = "0.2.99"
wasm-bindgen-test = "0.3.49"
web-sys = { version = "0.3.76", features = ["Window", "Performance"] }

[build-dependencies]
cargo = "0.84.0"

[features]
default = ["core"]
core = []  # Core functionality
test = ["core"]  # Testing infrastructure
bench = ["core"]  # Benchmarking infrastructure
v8 = []  # V8 WASM target support

@saethlin
Copy link
Member

saethlin commented Jan 7, 2025

I'm pretty sure that crash is caused by an archive file being overwritten or modified while the compiler is interacting with it. The reason the crash looks funny is that we're mmaping the file, parsing it, then trying to index into the map later. So we get "index out of bounds" instead of "unexpected EOF" or suchlike.

The fact that we are using mmap makes this extra-bad, but I'm pretty confident that using normal file reads would just make the compiler slower and no more correct. If the compiler is being fed a file that's being modified while the compiler is running, there's not a correct thing for the compiler to do.

I suspect that this is a subtle bug in v8's build script. I can see that it's writing output to an unusual path, which is already suspicious, but I'm no expert on V8 or build scripts.

@workingjubilee workingjubilee added C-gub Category: the reverse of a compiler bug is generally UB and removed C-bug Category: This is a bug. labels Jan 7, 2025
@workingjubilee
Copy link
Member

Closing as user bug caused by build script and thus not actionable here.

@devsnek Feel free to prove me wrong, if you like.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
@foxx
Copy link

foxx commented Jan 7, 2025

Yeah I have a feeling it's an obscure edge case. The v8 library is awesome, but the build scripts... there's all sorts of weirdness, including a Python script to download precompiled releases. I'll re-open this again in denoland/rusty_v8#1681 . Thanks both!

@devsnek
Copy link
Contributor

devsnek commented Jan 7, 2025

@saethlin or @workingjubilee could you expand a bit on the implications here? I'm happy to accept that this awful build script is causing issues, but based on what's been described I'm wondering if I have a misunderstanding of what's expected of build scripts at a high level. Does rustc+cargo attempt to interact with archive files while build scripts are still running?

@workingjubilee
Copy link
Member

@devsnek A lot of invocations of the compiler are concurrent. The compiler and cargo try to work out their own file-locking protocol which a build script isn't necessarily participating in. Many executions of the compiler are reading the output of previous executions, and this output is trusted to have remained in its original form.

@saethlin
Copy link
Member

saethlin commented Jan 7, 2025

I suspect that based on the kinds of descriptions here that this is related to colliding incremental builds.

What jumps out at me is that you are writing to target/debug/gn_out/obj/librusty_v8.a, not the build script's OUT_DIR:
https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script

Build scripts may save any output files or intermediate artifacts in the directory specified in the OUT_DIR environment variable. Scripts should not modify any files outside of that directory.

@workingjubilee
Copy link
Member

Hm. If it is incremental, then shouldn't we be validating the hashes...?

@devsnek Can you describe, at a higher-level, what that build script does?

there's uh,,,
there's a lot going on there, as I'm sure you agree.

@saethlin
Copy link
Member

saethlin commented Jan 7, 2025

Hm. If it is incremental, then shouldn't we be validating the hashes...?

The hash of what though. This build script is scribbling a file it's acquired from elsewhere into a directory that's shared between sessions.

@workingjubilee
Copy link
Member

...that is a very good question.

@workingjubilee
Copy link
Member

I am 100% certain that a build script that was dead-set on corrupting our build state can do so, I'm just wondering if there's a way to cheaply tell build scripts that do so without any malice aforethought "hey, I'm compiling here!"

@devsnek
Copy link
Contributor

devsnek commented Jan 7, 2025

Can you describe, at a higher-level, what that build script does?

very high level: v8's has a custom build system called GN which is like a trillion lines of python. so the build.rs script attempts to set up gn and its dependencies and then run a build. It does this above OUT_DIR because V8 builds are very slow and they don't (shouldn't?) vary across rust targets/incremental changes.

the script can also download a prebuilt binary instead of building one from scratch. it has to manually download it because they are too large for crates.io.

the script also uses its own lockfile, because we had observed that cargo can sometimes perform tasks on different targets in parallel (for example when running cargo test)

there is also a bindgen step to generate bindings from v8 headers, but this only generates a .rs file so i imagine its not the cause of any issues here.

so within a file lock, it will either:

  • download an archive(+bindgen rs file) from the internet, save it to a location above OUT_DIR, and print a cargo:link command for it
  • download gn and its various dependencies to some location above OUT_DIR, exec gn, wait for that to finish, and then print cargo:link command for the result (and generate the bindgen rs file)

So I guess with all this in mind, I guess if you had this scenario:

cargo task a: in some phase that is after running build scripts
cargo task b: running build scripts

cargo task a could fail. but i assumed that this wouldn't be possible because of cargo's own locks.

@workingjubilee
Copy link
Member

workingjubilee commented Jan 7, 2025

I uh, would not be surprised if cargo doesn't try to protect itself against a build script that is, in a formal sense, misbehaving (writing outside the prescribed output directories), and thus you managed to "bypass" the locks... because there wasn't a lock against the thing that shouldn't happen.

@foxx
Copy link

foxx commented Jan 8, 2025

@devsnek Could these problems be sidestepped if the prebuild was available via crates? It seems there's an established process to request custom crate limits as per rust-lang/crates.io#195, but I'm assuming it's not that simple. I should probably become more familiar with rusty_v8 build scripts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-gub Category: the reverse of a compiler bug is generally UB 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.
Projects
None yet
Development

No branches or pull requests

6 participants