Open ralfbiedert opened 4 years ago
The issue does not seem to occur on Linux.
error: Stream Error: The stream is too short to perform the requested operation.
That's odd. Does this come from LLVM?
Oops, misread the Rust versions, doesn't look like a regression so far
Does not reproduce on Windows 10 with windows-gnu. Can you run it in debugger?
It's definitely crashing in LLVM so RUST_BACKTRACE
cannot help.
Also you have some flags in your ~/.cargo/config
(-C target-cpu=native
caused similar issues in the past).
I did some more testing:
~/.cargo
and running rustup-init.exe
again gives the same error (but for reference my original config
was:[target.aarch64-linux-android]
linker = "C:/Users/rb/.ndk/android-ndk-r21d/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android21-clang.cmd"
RUST_
or CARGO_
environment variables set stable
via cargo build
and playing with Cargo.toml
and setting only:Setting in [profile.dev] |
Result |
---|---|
opt-level=1 |
STATUS_ILLEGAL_INSTRUCTION |
opt-level=2 |
STATUS_ILLEGAL_INSTRUCTION |
opt-level=3 |
STATUS_ILLEGAL_INSTRUCTION |
debug=0 |
Compiles. |
debug=1 |
Compiles. |
debug=2 |
STATUS_ILLEGAL_INSTRUCTION |
debug-assertions=false |
STATUS_ILLEGAL_INSTRUCTION |
overflow-checks=false |
STATUS_ILLEGAL_INSTRUCTION |
lto=false |
STATUS_ILLEGAL_INSTRUCTION |
lto=true |
STATUS_ILLEGAL_INSTRUCTION |
lto="thin" |
STATUS_ILLEGAL_INSTRUCTION |
lto="off" |
STATUS_ILLEGAL_INSTRUCTION |
incremental=false |
STATUS_ILLEGAL_INSTRUCTION |
codegen-units=1 |
STATUS_ILLEGAL_INSTRUCTION |
codegen-units=256 |
STATUS_ILLEGAL_INSTRUCTION |
cargo build --release
Setting in [profile.release] |
Result |
---|---|
debug=0 |
Compiles. |
debug=1 |
Compiles. |
debug=2 |
STATUS_ILLEGAL_INSTRUCTION |
Can you run it in debugger?
I can try, but how would I best do that?
Ok, I honestly have no idea how to debug it:
* thread #11, stop reason = Exception 0xc0000005 encountered at address 0x000002: User-mode data execution prevention (D
EP) violation at location 0x00000002
* frame #0: 0x0000000000000002
frame #1: 0x000000001474f820
I was able to reproduce this under Linux with a stage1 rustc, using the following hack:
rustup target install x86_64-pc-windows-msvc
set -x
rm -r weird
cp -r build/x86_64-unknown-linux-gnu/stage1 weird
cp -r ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc weird/lib/rustlib
rustup toolchain link weird /path/to/weird
rust-cheatsheet
, run cargo +weird build --target x86_64-pc-windows-msvc
This allowed me to obtain the following backtrace (with LLVM debug assertions enabled):
#0 0x00007ffb5521a615 in raise () from /usr/lib/libc.so.6
#1 0x00007ffb55203862 in abort () from /usr/lib/libc.so.6
#2 0x00007ffb52ee49a1 in llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#3 0x00007ffb54920f56 in llvm::ArrayRef<unsigned char> llvm::codeview::SimpleTypeSerializer::serialize<llvm::codeview::ClassRecord>(llvm::codeview::ClassRecord&) ()
from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#4 0x00007ffb5392f190 in llvm::CodeViewDebug::lowerTypeClass(llvm::DICompositeType const*) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#5 0x00007ffb53924cec in llvm::CodeViewDebug::getTypeIndex(llvm::DIType const*, llvm::DIType const*) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#6 0x00007ffb5392e78c in llvm::CodeViewDebug::lowerTypeFunction(llvm::DISubroutineType const*) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#7 0x00007ffb53924cec in llvm::CodeViewDebug::getTypeIndex(llvm::DIType const*, llvm::DIType const*) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#8 0x00007ffb53924149 in llvm::CodeViewDebug::getFuncIdForSubprogram(llvm::DISubprogram const*) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#9 0x00007ffb53927c57 in llvm::CodeViewDebug::emitDebugInfoForFunction(llvm::Function const*, llvm::CodeViewDebug::FunctionInfo&) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#10 0x00007ffb5392627f in llvm::CodeViewDebug::endModule() () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#11 0x00007ffb538b942d in llvm::AsmPrinter::doFinalization(llvm::Module&) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#12 0x00007ffb53123765 in llvm::FPPassManager::doFinalization(llvm::Module&) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#13 0x00007ffb5311d4a6 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/aaron/repos/rust/weird/bin/../lib/../lib/libLLVM-11-rust-dev.so
#14 0x00007ffb56143635 in LLVMRustWriteOutputFile () from /home/aaron/repos/rust/weird/bin/../lib/librustc_driver-791e4e962741912d.so
#15 0x00007ffb55f7a3c8 in rustc_codegen_llvm::back::write::write_output_file () at compiler/rustc_codegen_llvm/src/back/write.rs:56
#16 0x00007ffb56099cf7 in rustc_codegen_llvm::back::write::codegen::{{closure}} () at compiler/rustc_codegen_llvm/src/back/write.rs:803
#17 rustc_codegen_llvm::back::write::codegen::with_codegen () at compiler/rustc_codegen_llvm/src/back/write.rs:691
#18 0x00007ffb55f8c88e in rustc_codegen_llvm::back::write::codegen () at compiler/rustc_codegen_llvm/src/back/write.rs:802
#19 <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::write::WriteBackendMethods>::codegen () at compiler/rustc_codegen_llvm/src/lib.rs:174
#20 0x00007ffb55f683bc in rustc_codegen_ssa::back::write::finish_intra_module_work () at /home/aaron/repos/rust/compiler/rustc_codegen_ssa/src/back/write.rs:887
#21 0x00007ffb55f624a7 in rustc_codegen_ssa::back::write::execute_optimize_work_item () at /home/aaron/repos/rust/compiler/rustc_codegen_ssa/src/back/write.rs:806
#22 rustc_codegen_ssa::back::write::execute_work_item () at /home/aaron/repos/rust/compiler/rustc_codegen_ssa/src/back/write.rs:722
#23 0x00007ffb560ca1de in rustc_codegen_ssa::back::write::spawn_work::{{closure}} () at /home/aaron/repos/rust/compiler/rustc_codegen_ssa/src/back/write.rs:1588
#24 std::sys_common::backtrace::__rust_begin_short_backtrace () at /home/aaron/repos/rust/library/std/src/sys_common/backtrace.rs:137
#25 0x00007ffb5609653d in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /home/aaron/repos/rust/library/std/src/thread/mod.rs:464
#26 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /home/aaron/repos/rust/library/std/src/panic.rs:308
#27 std::panicking::try::do_call () at /home/aaron/repos/rust/library/std/src/panicking.rs:381
#28 std::panicking::try () at /home/aaron/repos/rust/library/std/src/panicking.rs:345
#29 std::panic::catch_unwind () at /home/aaron/repos/rust/library/std/src/panic.rs:382
#30 std::thread::Builder::spawn_unchecked::{{closure}} () at /home/aaron/repos/rust/library/std/src/thread/mod.rs:463
#31 core::ops::function::FnOnce::call_once{{vtable-shim}} () at /home/aaron/repos/rust/library/core/src/ops/function.rs:227
#32 0x00007ffb55480e08 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /home/aaron/repos/rust/library/alloc/src/boxed.rs:1042
#33 <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /home/aaron/repos/rust/library/alloc/src/boxed.rs:1042
#34 0x00007ffb55489a9a in std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:87
#35 0x00007ffb515643e9 in start_thread () from /usr/lib/libpthread.so.0
#36 0x00007ffb552dd293 in clone () from /usr/lib/libc.so.6
The following LLVM code looks relevant: https://github.com/llvm/llvm-project/blob/f68d174c16217dd28858af2ce9ce5f33ac8af756/llvm/lib/DebugInfo/CodeView/SimpleTypeSerializer.cpp#L30
It looks like LLVM may be trying to serialize a very long Rust type, which ends up exceeding MaxRecordLength = 0xFF00
https://github.com/rust-lang/rust/pull/77948 rebases rustc onto the final LLVM 11.0 release. According to that MR's milestone, it is scheduled for Rust 1.49. It isn't clear to me how to verify whether the Rust 1.49 release will actually contain that fix though.
@ralfbiedert and others who are having this issue, could you update Rust Beta to the latest version (presumably, one very close to what will be released as Rust 1.49 final) and report back whether the latest Rust Beta fixes this issue for you?
FWIW, my team has encountered an issue very similar to this in 1.47, but not 1.46, and only when we're compiling for 64-bit Android targets. This would indicate to me that this isn't a Windows-specific bug.
@ralfbiedert and others who are having this issue, could you update Rust Beta to the latest version (presumably, one very close to what will be released as Rust 1.49 final) and report back whether the latest Rust Beta fixes this issue for you?
The beta channel is now already 1.50.0-beta. Instead you can follow the directions at https://blog.rust-lang.org/inside-rust/2020/12/29/1.49.0-prerelease.html to install the 1.49.0 pre-release.
I followed those instructions and built my projects with the 1.49.0 pre-release targeting Android and my build succeeded where previously the same configuration failed with 1.48.0 with (signal: 11, SIGSEGV: invalid memory reference)
.
Ok, I just updated stable via RUSTUP_DIST_SERVER
to
rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-pc-windows-msvc
release: 1.49.0
When I run cargo build
in the project now I get STATUS_STACK_BUFFER_OVERRUN
:
[...]
Compiling nom v4.2.3
Compiling buf-min v0.1.1
Compiling combine v4.2.1
Compiling quote v1.0.7
Compiling v_escape_derive v0.8.1
Compiling serde_yaml v0.8.13
Compiling cheatsheet-gen v0.1.0 (D:\Development\Source\_thirdparty\rust-cheatsheet)
error: Stream Error: The stream is too short to perform the requested operation.
error: could not compile `cheatsheet-gen`
Caused by:
process didn't exit successfully: `rustc --crate-name cheatsheet_gen --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=db2d8889f40e140f --out-dir D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps -C linker=C:/Users/rb/scoop/shims/lld-link.exe -C incremental=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\incremental -L dependency=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps --extern bitflags=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libbitflags-808ca99e95faa8ae.rlib --extern combine=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libcombine-2ff8681a4a840a07.rlib --extern either_n=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libeither_n-5cbdae01f5acc47f.rlib --extern lazy_static=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\liblazy_static-a5fdf74fcdafbee9.rlib --extern serde=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libserde-e4c3e65b940c2046.rlib --extern serde_yaml=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libserde_yaml-38d2deeae8d2037a.rlib --extern v_htmlescape=D:\Development\Source\_thirdparty\rust-cheatsheet\target\debug\deps\libv_htmlescape-3ce086faae9d8288.rlib` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
Update, rustc 1.51.0-nightly (158f8d034 2020-12-29)
fails with the same error.
I managed to hit this same issue with a different crate using rustc 1.52.0-nightly (1705a7d64 2021-03-18)
.
To reproduce, check out the data_holder
branch of git@github.com:bugadani/embedded-gui.git
(this commit) and try to build the calculator example.
Does not reproduce on WSL. Compiles fine on Windows with --release
error: Stream Error: The stream is too short to perform the requested operation.
error: could not compile `embedded-gui`
Caused by:
process didn't exit successfully: `rustc --crate-name calculator --edition=2018 examples\calculator.rs
--error-format=json
--json=diagnostic-rendered-ansi
--crate-type bin --emit=dep-info,link
-C embed-bitcode=no -C debuginfo=2
-C metadata=80352bbf14fdfebb
--out-dir C:\_Hobby\RustLibraries\embedded-gui\target\debug\examples
-C incremental=C:\_Hobby\RustLibraries\embedded-gui\target\debug\incremental
-L dependency=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps
--extern backend_embedded_graphics=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libbackend_embedded_graphics-8b6cd8529e0fc58d.rlib
--extern embedded_graphics=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libembedded_graphics-d313357ca9d438a0.rlib
--extern embedded_graphics_simulator=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libembedded_graphics_simulator-7dd88e0af16aed95.rlib
--extern embedded_gui=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libembedded_gui-f62f849b7c07d6c3.rlib
--extern heapless=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libheapless-50999711d995f99b.rlib
--extern object_chain=C:\_Hobby\RustLibraries\embedded-gui\target\debug\deps\libobject_chain-96ea005c3c1e7f60.rlib`
(exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
It's worth noting that I'm abusing the type system pretty bad.
I was trying to compile this 3rd party project with
cargo build
when I received anexit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION
.Depending on what Rust version I use I get slightly different errors, but I can reproduce the behavior as follows:
cargo build
STATUS_ILLEGAL_INSTRUCTION
cargo +beta build
STATUS_STACK_BUFFER_OVERRUN
cargo +nightly build
STATUS_STACK_BUFFER_OVERRUN
.cargo build --release
cargo +beta build --release
cargo +nightly build --release
cargo check
In other words
--release
builds are fine, while debug builds fail.A failing build that produces a
STATUS_STACK_BUFFER_OVERRUN
looks like this:A build that fails with
STATUS_ILLEGAL_INSTRUCTION
looks similar but outputs this instead at the end:Running
rustc --version --verbose
for my latest stable givesAdditional Info
RUST_BACKTRACE
does not really change anything about that behavior and provides no further insights.cargo clean
does not change anything either