Repository navigation
Segfault while compiling rustc_codegen_spirv #29
Copy link
Copy link
Closed
Labels
Description
Expected Behaviour
cargo build should finish without error.
Example & Steps To Reproduce
Run cargo build after a clean clone of the repo.
System Info
- Rust: rustc 1.79.0-nightly (244da22fa 2024-04-23)
- OS: macOS 15.0 (24A335)
- GPU: integrated
Output
error: could not compile `rustc_codegen_spirv` (lib)
Caused by:
process didn't exit successfully: `/Users/schell/.rustup/toolchains/nightly-2024-04-24-aarch64-apple-darwin/bin/rustc --crate-name rustc_codegen_spirv --edition=2021 crates/rustc_codegen_spirv/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=320 --crate-type dylib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg 'feature="default"' --cfg 'feature="use-compiled-tools"' -C metadata=5d6b9f1085555723 --out-dir /Users/schell/code/rust-gpu/target/debug/deps -C incremental=/Users/schell/code/rust-gpu/target/debug/incremental -L dependency=/Users/schell/code/rust-gpu/target/debug/deps --extern ar=/Users/schell/code/rust-gpu/target/debug/deps/libar-e3ad7146ff683a59.rlib --extern either=/Users/schell/code/rust-gpu/target/debug/deps/libeither-b182a76c8248f318.rlib --extern hashbrown=/Users/schell/code/rust-gpu/target/debug/deps/libhashbrown-d177bbe31249a900.rlib --extern indexmap=/Users/schell/code/rust-gpu/target/debug/deps/libindexmap-5721173ffd4b737f.rlib --extern itertools=/Users/schell/code/rust-gpu/target/debug/deps/libitertools-91ee06ba4bd713a5.rlib --extern lazy_static=/Users/schell/code/rust-gpu/target/debug/deps/liblazy_static-4bc53d643ec30e40.rlib --extern libc=/Users/schell/code/rust-gpu/target/debug/deps/liblibc-71b3be213458ada3.rlib --extern num_traits=/Users/schell/code/rust-gpu/target/debug/deps/libnum_traits-893caca608ed540b.rlib --extern once_cell=/Users/schell/code/rust-gpu/target/debug/deps/libonce_cell-e9b1da7b0201a63a.rlib --extern regex=/Users/schell/code/rust-gpu/target/debug/deps/libregex-b32f0d5f03e3e84d.rlib --extern rspirv=/Users/schell/code/rust-gpu/target/debug/deps/librspirv-2abab5c81971212b.rlib --extern rustc_demangle=/Users/schell/code/rust-gpu/target/debug/deps/librustc_demangle-61ad1dd711dcb489.rlib --extern rustc_codegen_spirv_types=/Users/schell/code/rust-gpu/target/debug/deps/librustc_codegen_spirv_types-1b2da75106876b67.rlib --extern sanitize_filename=/Users/schell/code/rust-gpu/target/debug/deps/libsanitize_filename-86f3198c840fea75.rlib --extern smallvec=/Users/schell/code/rust-gpu/target/debug/deps/libsmallvec-814122e6d785094d.rlib --extern spirt=/Users/schell/code/rust-gpu/target/debug/deps/libspirt-3313c9c2493bc97b.rlib --extern spirv_tools=/Users/schell/code/rust-gpu/target/debug/deps/libspirv_tools-ffda6275029880c3.rlib -Dunsafe_code '-Wclippy::all' '-Wclippy::await_holding_lock' '-Wclippy::char_lit_as_u8' '-Wclippy::checked_conversions' '-Wclippy::dbg_macro' '-Wclippy::debug_assert_with_mut_call' '-Wclippy::doc_markdown' '-Wclippy::empty_enum' '-Wclippy::enum_glob_use' '-Wclippy::exit' '-Wclippy::expl_impl_clone_on_copy' '-Wclippy::explicit_deref_methods' '-Wclippy::explicit_into_iter_loop' '-Wclippy::fallible_impl_from' '-Wclippy::filter_map_next' '-Wclippy::flat_map_option' '-Wclippy::float_cmp_const' '-Wclippy::fn_params_excessive_bools' '-Wclippy::from_iter_instead_of_collect' '-Wclippy::if_let_mutex' '-Wclippy::implicit_clone' '-Wclippy::imprecise_flops' '-Wclippy::inefficient_to_string' '-Wclippy::invalid_upcast_comparisons' '-Wclippy::large_digit_groups' '-Wclippy::large_stack_arrays' '-Wclippy::large_types_passed_by_value' '-Wclippy::let_unit_value' '-Wclippy::linkedlist' '-Wclippy::lossy_float_literal' '-Wclippy::macro_use_imports' '-Wclippy::manual_ok_or' '-Wclippy::map_err_ignore' '-Wclippy::map_flatten' '-Wclippy::map_unwrap_or' '-Wclippy::match_on_vec_items' '-Wclippy::match_same_arms' '-Wclippy::match_wild_err_arm' '-Wclippy::match_wildcard_for_single_variants' '-Wclippy::mem_forget' '-Wclippy::mismatched_target_os' '-Wclippy::missing_enforced_import_renames' '-Wclippy::mut_mut' '-Wclippy::mutex_integer' '-Wclippy::needless_borrow' '-Wclippy::needless_continue' '-Wclippy::needless_for_each' '-Wclippy::option_option' '-Wclippy::path_buf_push_overwrite' '-Wclippy::ptr_as_ptr' '-Wclippy::rc_mutex' '-Wclippy::ref_option_ref' '-Wclippy::rest_pat_in_fully_bound_structs' '-Wclippy::same_functions_in_if_condition' '-Wclippy::semicolon_if_nothing_returned' '-Wclippy::single_match_else' '-Wclippy::string_add_assign' '-Wclippy::string_add' '-Wclippy::string_lit_as_bytes' '-Wclippy::string_to_string' '-Wclippy::todo' '-Wclippy::trait_duplication_in_bounds' '-Wclippy::unimplemented' '-Wclippy::unnested_or_patterns' '-Wclippy::unused_self' '-Wclippy::useless_transmute' '-Wclippy::verbose_file_reads' '-Wclippy::zero_sized_map_values' -Wfuture_incompatible -Wnonstandard_style -Wrust_2018_idioms -Aunsafe_code -L native=/Users/schell/code/rust-gpu/target/debug/build/spirv-tools-sys-a44f67dd6078deef/out` (signal: 11, SIGSEGV: invalid memory reference)
Reactions are currently unavailable
Activity
schell commentedon Oct 11, 2024
Here's how far I got with
lldbFirst I set up a command source file
lldb_env_setup.lldbto hold all the env vars and cli options:Then I invoke
lldband do:Which then shows:
schell commentedon Oct 11, 2024
It builds in
--release! But it won't otherwise.utensil commentedon Oct 11, 2024
I have the same issue,
cargo run --releaseworks for examplerunners/wgpu, but has the same error if not with--release.LegNeato commentedon Oct 11, 2024
Interesting, CI only appears to check x86_64 on Mac:
Though the docs say latest is arm? 🤔
https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
And it looks like CI only uses
--release😩LegNeato commentedon Oct 13, 2024
I was able to update rust-gpu to
nightly-2024-06-20and this crash went away. It was still there undernightly-2024-05-20.Many of the tests fail with hacks to get around the
allocachanges preventing us from updating (rust-lang/rust@f4426c1) but the compiling works at least which points to an old llvm or rustc issue unrelated to rust-gpu.LegNeato commentedon Oct 14, 2024
@eddyb found the cause:
nightly-2024-05-21has the fixeddyb commentedon Oct 14, 2024
Likely culprit: llvm/llvm-project@70579c9
This leaves Feb 14th - May 20th as the range with the bug, i.e. between:
Looking at the report (rust-lang/rust#125053), it is weirdly specific. I wonder if it's in code we control.
@schell if you have the time, it might be useful to try to add
-C save-tempsand hopefully get access to the4zue6wczm9w1glcocodegen-unit before it's optimized.schell commentedon Oct 14, 2024
Nice sleuthing @eddyb and @LegNeato. I'll try it out when I can 🙇 .
eddyb commentedon Oct 14, 2024
Found a relatively low-effort way to inject
lldb(doesn't even cause rebuilds!):Then:
(note the
4q5ivfep7qt5yoowI took from the crashing thread name!)Now, if it is that symbol, that's bad news because it's in
rustcitself, i.e.:Does this mean nobody on M1 could've contributed to
rustcinrust-lang/rust? Or is this "unoptimized" mode so unlikely to be applied torustcdevelopment? (Or am I looking at the wrong plausible cause)EDIT: the real culprit is a load from that global variable:
(not sure yet if we can avoid it, but optimizations simply replace it with
0...)eddyb commentedon Nov 27, 2024
We have two options to deal with this:
aarch64anddebugmode and error explicitlycfgs, (the bug happens while compilingrustc_codegen_spirv, but all the way down in LLVM, so e.g.compile_error!should still prevent it)Cargo.tomloverrides like the ones we userustc_codegen_ssa's MIRReturnterminator codegen under the assumption that it's the only root causePassMode::Indirect, we've just ignored it(worst case, the inliner has to inline calls passing "out" pointers illegally)
PassMode::Cast, when there's an obvious mapping to the [somewhat strangeCastTarget` system](https://github.com/rust-lang/rust/blob/244da22fabd9fa677bbd0ac601a88e5ca6917526/compiler/rustc_target/src/abi/call/mod.rs#L190-L301)Uniform(with integer/float elements) into vectors instead of structs, that might cover a lot of types, but we don't even get integer signednesscast_backend_type(cast_ty)return a special placeholder (ignoringcast_ty's contents), whichload+retspecial-case to give the original typestore_arg/store_fn_arg/fn_decl_backend_type, so the function signatures can remain whatever we want them to be, at the SPIR-V levelPassMode::Castinsanity, we could "just" always usePassMode::Indirect, and pretend the signature has an extra pointer at the start (which is, instead, a local variable, that we can load onret_void, to do the actual return)rustc_codegen_ssaand/or build one on the user's machine, from the source code provided by therustc-devrustup componentrustc_*crate should already have been supplied byrustc-dev, Cargo might not even be necessaryrustcinvocation might be superfluous: we can, in theory, copy all the source files, patch them, then include them fromrustc_codegen_spirv(if we add a new method, there's only 2 callsites to patch:
PlaceRef::allocaand some weird immediate-newtype-of-vector hack - also,PlaceRef::allocagets type information to this day)nightly-2024-11-22(~1.84). #170