Skip to content

rustc silently crashes with STATUS_ILLEGAL_INSTRUCTION when targeting thumbv7a-*-windows-msvc with raw-dylib #120921

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
bdbai opened this issue Feb 11, 2024 · 2 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-external-bug Category: issue that is caused by bugs in software beyond our control I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-windows Operating system: Windows

Comments

@bdbai
Copy link
Contributor

bdbai commented Feb 11, 2024

I tried this code inside a cdylib crate in src/lib.rs:

#[no_mangle]
pub fn foo1() {
    #[link(name = "Kernel32.dll", kind = "raw-dylib", modifiers = "+verbatim")]
    extern "system" {
        #[link_name = "GetLastError"]
        pub fn get_last_error() -> i32;
    }
    unsafe { get_last_error() };
}

and then built the package targeting thumbv7a-uwp-windows-msvc:

cargo +nightly build -Z build-std=std,panic_abort --target thumbv7a-uwp-windows-msvc

A DLL is expected to be produced without any errors.

Instead, I was getting errors from cargo output:

error: could not compile `testlib` (lib)

Caused by:
  process didn't exit successfully: `rustc --crate-name testlib --edition=2021 src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=ef61da8a61eafeee --out-dir D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps --target thumbv7a-uwp-windows-msvc -C incremental=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\incremental -L dependency=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps -L dependency=D:\proj\testrs\testlib\target\debug\deps --extern noprelude:alloc=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\liballoc-d258b9239a7ba282.rlib --extern noprelude:compiler_builtins=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcompiler_builtins-f04b6bba69e7d7d9.rlib --extern noprelude:core=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcore-ce81669056b9279b.rlib --extern noprelude:panic_abort=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_abort-004c9cbe9edf74e5.rlib --extern noprelude:panic_unwind=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_unwind-36a0313086dccb8e.rlib --extern noprelude:proc_macro=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libproc_macro-47df777a82030abd.rlib --extern noprelude:std=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libstd-2dafaaca0018a6d9.rlib -Z unstable-options` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
Full output: PS D:\proj\testrs\testlib> cargo +nightly build -Z build-std=std,panic_abort --target thumbv7a-uwp-windows-msvc Compiling core v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core) Compiling rustc-std-workspace-core v1.99.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc-std-workspace-core) Compiling compiler_builtins v0.1.105 Compiling libc v0.2.153 Compiling alloc v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc) Compiling cfg-if v1.0.0 Compiling adler v1.0.2 Compiling memchr v2.5.0 Compiling rustc-demangle v0.1.23 Compiling unwind v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\unwind) Compiling rustc-std-workspace-alloc v1.99.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc-std-workspace-alloc) Compiling panic_abort v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\panic_abort) Compiling panic_unwind v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\panic_unwind) Compiling gimli v0.28.0 Compiling miniz_oxide v0.7.1 Compiling object v0.32.2 Compiling std_detect v0.1.5 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\stdarch\crates\std_detect) Compiling hashbrown v0.14.3 Compiling addr2line v0.21.0 Compiling std v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std) Compiling proc_macro v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\proc_macro) Compiling testlib v0.1.0 (D:\proj\testrs\testlib) error: could not compile `testlib` (lib)

Caused by:
process didn't exit successfully: rustc --crate-name testlib --edition=2021 src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=ef61da8a61eafeee --out-dir D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps --target thumbv7a-uwp-windows-msvc -C incremental=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\incremental -L dependency=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps -L dependency=D:\proj\testrs\testlib\target\debug\deps --extern noprelude:alloc=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\liballoc-d258b9239a7ba282.rlib --extern noprelude:compiler_builtins=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcompiler_builtins-f04b6bba69e7d7d9.rlib --extern noprelude:core=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcore-ce81669056b9279b.rlib --extern noprelude:panic_abort=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_abort-004c9cbe9edf74e5.rlib --extern noprelude:panic_unwind=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_unwind-36a0313086dccb8e.rlib --extern noprelude:proc_macro=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libproc_macro-47df777a82030abd.rlib --extern noprelude:std=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libstd-2dafaaca0018a6d9.rlib -Z unstable-options (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

Meta

rustc +nightly --version --verbose:

rustc 1.78.0-nightly (6cc484351 2024-02-10)
binary: rustc
commit-hash: 6cc4843512d613f51ec81aba689180c31b0b28b6
commit-date: 2024-02-10
host: x86_64-pc-windows-msvc
release: 1.78.0-nightly
LLVM version: 17.0.6

I did not see any ICE, panic messages or stack traces, hence attached Visual Studio debugger to capture the exception:
image

Memory dump: https://1drv.ms/u/s!AvQksscT-2xElJJNe7C2yAEa9NV5BQ?e=dt93eH

rustc command line rustc --crate-name testlib --edition=2021 src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=ef61da8a61eafeee --out-dir D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps --target thumbv7a-uwp-windows-msvc -C incremental=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\incremental -L dependency=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps -L dependency=D:\proj\testrs\testlib\target\debug\deps --extern noprelude:alloc=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\liballoc-d258b9239a7ba282.rlib --extern noprelude:compiler_builtins=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcompiler_builtins-f04b6bba69e7d7d9.rlib --extern noprelude:core=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libcore-ce81669056b9279b.rlib --extern noprelude:panic_abort=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_abort-004c9cbe9edf74e5.rlib --extern noprelude:panic_unwind=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libpanic_unwind-36a0313086dccb8e.rlib --extern noprelude:proc_macro=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libproc_macro-47df777a82030abd.rlib --extern noprelude:std=D:\proj\testrs\testlib\target\thumbv7a-uwp-windows-msvc\debug\deps\libstd-2dafaaca0018a6d9.rlib -Z unstable-options
@bdbai bdbai added the C-bug Category: This is a bug. label Feb 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@bjorn3 bjorn3 added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-windows Operating system: Windows labels Feb 11, 2024
@bjorn3
Copy link
Member

bjorn3 commented Feb 11, 2024

Based on the crash location and https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/invalid-parameter-functions?view=msvc-170 it seems like LLVM passed an invalid argument to a libc function.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@jieyouxu jieyouxu added C-external-bug Category: issue that is caused by bugs in software beyond our control and removed C-bug Category: This is a bug. labels Dec 25, 2024
@bdbai
Copy link
Contributor Author

bdbai commented Apr 20, 2025

Closing as no longer reproducible using latest nightly toolchain.

@bdbai bdbai closed this as completed Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-external-bug Category: issue that is caused by bugs in software beyond our control I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

5 participants