Repository: rust
Issue: rustc silently crashes with `STATUS_ILLEGAL_INSTRUCTION` when targeting thumbv7a-*-windows-msvc with `raw-dylib`
Labels: I-crash,A-LLVM,O-windows,C-external-bug

I tried this code inside a `cdylib` crate in `src/lib.rs`:

```rust
#[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`:
```pwsh
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)
```

<details>
<summary>Full output:</summary>
<code>
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)
</code>
</details>

### 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](https://github.com/rust-lang/rust/assets/5270106/c973e7c2-e5f0-4cf2-94a9-1169f7d5d1db)

Memory dump: https://1drv.ms/u/s!AvQksscT-2xElJJNe7C2yAEa9NV5BQ?e=dt93eH

<details>
<summary>rustc command line</summary>
</code>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</code>
</details>