Repository: rust
Issue: ICE in rustc_codegen_llvm when cross compiling to linux on OSX
Labels: A-LLVM,O-macos,I-ICE,A-cross,T-compiler,C-bug,S-needs-repro

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Env setup

```bash
rustup +nightly target add aarch64-unknown-linux-gnu
rustup +nightly target add aarch64-apple-darwin
rustup +nightly target add x86_64-unknown-linux-gnu
rustup +nightly target add x86_64-apple-darwin

brew tap messense/macos-cross-toolchains
brew install x86_64-unknown-linux-gnu
brew install aarch64-unknown-linux-gnu

export CC_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-gcc
export CXX_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-g++
export AR_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
export CC_aarch64_unknown_linux_gnu=aarch64-unknown-linux-gnu-gcc
export CXX_aarch64_unknown_linux_gnu=aarch64-unknown-linux-gnu-g++
export AR_aarch64_unknown_linux_gnu=aarch64-unknown-linux-gnu-ar
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-unknown-linux-gnu-gcc

cargo build --bin my_bin --release --target aarch64-unknown-linux-gnu
cargo build --bin my_bin --release --target x86_64-unknown-linux-gnu
cargo build --bin my_bin --release --target x86_64-apple-darwin
cargo build --bin my_bin --release --target aarch64-apple-darwin
```

### Code

```Rust
TBD
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc +nightly --version --verbose`:
```
rustc 1.70.0-nightly (2036fdd24 2023-03-27)
binary: rustc
commit-hash: 2036fdd24f77d607dcfaa24c48fbe85d3f785823
commit-date: 2023-03-27
host: aarch64-apple-darwin
release: 1.70.0-nightly
LLVM version: 16.0.0
```

### Error output

```
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_codegen_llvm/src/back/archive.rs:388:67
stack backtrace:
   0:        0x1055cd5bc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5fb738fb6b06a1d9
   1:        0x1056206d4 - core::fmt::write::h6a02464bebb2a88f
   2:        0x1055c306c - std::io::Write::write_fmt::h0365a706650ef7a0
   3:        0x1055cd3d0 - std::sys_common::backtrace::print::h2b2100bcc34ab976
   4:        0x1055cfde4 - std::panicking::default_hook::{{closure}}::hde9e5aa39a306a1c
   5:        0x1055cfba4 - std::panicking::default_hook::h3a7ed30f183fe740
   6:        0x10da3f554 - rustc_driver_impl[5332f8ff8b069570]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x1055d04a4 - std::panicking::rust_panic_with_hook::h3f818433f3792366
   8:        0x1055d025c - std::panicking::begin_panic_handler::{{closure}}::hba1d1542190b0a1d
   9:        0x1055cd9dc - std::sys_common::backtrace::__rust_end_short_backtrace::heb72c863cff1bc59
  10:        0x1055d0030 - _rust_begin_unwind
  11:        0x10564c0f0 - core::panicking::panic_fmt::h940abc2770676ab4
  12:        0x10564c160 - core::panicking::panic::hed9e6f165e9ca76a
  13:        0x10db6f750 - <rustc_codegen_llvm[fde183f7bc188e4d]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[c368d436ad072d1]::back::archive::ArchiveBuilder>::build
  14:        0x110ecfaa4 - rustc_codegen_ssa[c368d436ad072d1]::back::link::link_binary
  15:        0x10db636c8 - <rustc_codegen_llvm[fde183f7bc188e4d]::LlvmCodegenBackend as rustc_codegen_ssa[c368d436ad072d1]::traits::backend::CodegenBackend>::link
  16:        0x10dadd3cc - <rustc_interface[c04e01e9db0d2ec]::queries::Linker>::link
  17:        0x10d9d8aa4 - rustc_span[6c4d6989865837ed]::with_source_map::<core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>, rustc_interface[c04e01e9db0d2ec]::interface::run_compiler<core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>, rustc_driver_impl[5332f8ff8b069570]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  18:        0x10d9e6bc0 - std[6fbb0ec1f86da1b4]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c04e01e9db0d2ec]::util::run_in_thread_pool_with_globals<rustc_interface[c04e01e9db0d2ec]::interface::run_compiler<core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>, rustc_driver_impl[5332f8ff8b069570]::run_compiler::{closure#1}>::{closure#0}, core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>>
  19:        0x10d9dec04 - <<std[6fbb0ec1f86da1b4]::thread::Builder>::spawn_unchecked_<rustc_interface[c04e01e9db0d2ec]::util::run_in_thread_pool_with_globals<rustc_interface[c04e01e9db0d2ec]::interface::run_compiler<core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>, rustc_driver_impl[5332f8ff8b069570]::run_compiler::{closure#1}>::{closure#0}, core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[62096c4622bbf560]::result::Result<(), rustc_span[6c4d6989865837ed]::ErrorGuaranteed>>::{closure#1} as core[62096c4622bbf560]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  20:        0x1055d8b4c - std::sys::unix::thread::Thread::new::thread_start::ha951329ff3fcdc44
  21:        0x1a2dca06c - __pthread_deallocate

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: rustc 1.70.0-nightly (2036fdd24 2023-03-27) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C opt-level=s -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C debuginfo=0 -C linker=aarch64-unknown-linux-gnu-gcc -C strip=symbols

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `openssl-sys` (lib)
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_codegen_llvm/src/back/archive.rs:388:67
stack backtrace:
   Compiling libssh2-sys v0.2.23
   Compiling openssl v0.10.45
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <rustc_codegen_llvm::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa::back::archive::ArchiveBuilder>::build
   4: rustc_codegen_ssa::back::link::link_binary
   5: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::link
   6: <rustc_interface::queries::Linker>::link
   7: rustc_span::with_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: rustc 1.70.0-nightly (2036fdd24 2023-03-27) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C opt-level=s -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C debuginfo=0 -C linker=aarch64-unknown-linux-gnu-gcc -C strip=symbols

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `openssl-sys` (lib)
```

</p>
</details>