Repository: rust
Issue: Internal segfault when cross-compiling to arm32 --release
Labels: I-ICE,T-compiler,C-bug

<!--
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/
-->

Rustc segfaults on the following crate on 1.67.1, and nightly-2023-02-09 (and a good bit back - at least since 1.61) when cross-compiled to arm-unknown-linux-gnueabihf, but only if built on opt-level=3. `resolver = "1"` is just used to force build scripts to build openssl from source too; the segfault also occurs if that line is removed and OpenSSL is installed normally (see the provided Cross.toml).

### Code

Cargo.toml:

```toml
[package]
name = "test-segfault"
version = "0.1.0"
edition = "2021"
resolver = "1"

[dependencies]
ic-crypto-internal-threshold-sig-ecdsa = { git = "https://github.com/dfinity/ic", rev = "7bef7166811204c044c70939c33d3e705c8c3897" }
openssl = { version = "0.10", features = ["vendored"] }
```

([Source](https://github.com/dfinity/ic/tree/master/rs/crypto/internal/crypto_lib/threshold_sig/tecdsa))

<details><summary>Cross.toml (optional)</summary>

```toml
[build]
pre-build = ["apt-get update && apt-get install --assume-yes libssl-dev"]
```

</details>

Command:

```sh
cross build --target arm-unknown-linux-gnueabihf --release
```

### 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 --version --verbose`:
```
rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6
```
```
rustc 1.69.0-nightly (8996ea93b 2023-02-09)
binary: rustc
commit-hash: 8996ea93b6e554148c4286e62b613f12a3ee505c
commit-date: 2023-02-09
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7
```

### Error output

```
/rust/lib/librustc_driver-710574fabae712f8.so(+0x325f1a3)[0x7fa8bb7a81a3]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12980)[0x7fa8b7f30980]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(+0x63e9f2c)[0x7fa8b7201f2c]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(+0x59e8292)[0x7fa8b6800292]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0x11d9)[0x7fa8b658a659]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x1306)[0x7fa8b683ea48]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x410)[0x7fa8b6841890]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(+0x464bab1)[0x7fa8b5463ab1]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xb2c)[0x7fa8b679193c]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7fa8b6790def]
/rust/lib/libLLVM-15-rust-1.67.1-stable.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x21a)[0x7fa8b6517360]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x2749b22)[0x7fa8bac92b22]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x27494c5)[0x7fa8bac924c5]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x2747407)[0x7fa8bac90407]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x27445cd)[0x7fa8bac8d5cd]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x27434e7)[0x7fa8bac8c4e7]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x274233f)[0x7fa8bac8b33f]
/rust/lib/librustc_driver-710574fabae712f8.so(+0x26a8c36)[0x7fa8babf1c36]
/rust/lib/libstd-c6192dd4c4d410ac.so(rust_metadata_std_359ab902947f5f0b+0x10c803)[0x7fa8bc9c5803]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76db)[0x7fa8b7f256db]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fa8b7c4e61f]
error: could not compile `ic-crypto-internal-threshold-sig-ecdsa`

Caused by:
  process didn't exit successfully: `rustc --crate-name ic_crypto_internal_threshold_sig_ecdsa --edition=2021 /cargo/git/checkouts/ic-ca00ee28655ee32e/7bef716/rs/crypto/internal/crypto_lib/threshold_sig/tecdsa/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=5658081b45d03b8e -C extra-filename=-5658081b45d03b8e --out-dir /target/arm-unknown-linux-gnueabihf/release/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/release/deps -L dependency=/target/release/deps --extern fe_derive=/target/release/deps/libfe_derive-6145351e853bc244.so --extern hex=/target/arm-unknown-linux-gnueabihf/release/deps/libhex-1d2acbd050dcda70.rmeta --extern hex_literal=/target/release/deps/libhex_literal-aa1a8889e0d85c74.so --extern ic_crypto_internal_hmac=/target/arm-unknown-linux-gnueabihf/release/deps/libic_crypto_internal_hmac-0527c81bf33a2263.rmeta --extern ic_crypto_internal_seed=/target/arm-unknown-linux-gnueabihf/release/deps/libic_crypto_internal_seed-9651940a0c0a0b54.rmeta --extern ic_crypto_internal_types=/target/arm-unknown-linux-gnueabihf/release/deps/libic_crypto_internal_types-8cf76e7560b6af7c.rmeta --extern ic_crypto_sha=/target/arm-unknown-linux-gnueabihf/release/deps/libic_crypto_sha-4aca1db4bfeda5fd.rmeta --extern ic_types=/target/arm-unknown-linux-gnueabihf/release/deps/libic_types-9d799243aafdd578.rmeta --extern k256=/target/arm-unknown-linux-gnueabihf/release/deps/libk256-1dcf500b878e2bbd.rmeta --extern lazy_static=/target/arm-unknown-linux-gnueabihf/release/deps/liblazy_static-added3069e70bf89.rmeta --extern p256=/target/arm-unknown-linux-gnueabihf/release/deps/libp256-a0e7f3eb02a0768b.rmeta --extern paste=/target/release/deps/libpaste-2e6d8847b5aff82f.so --extern rand=/target/arm-unknown-linux-gnueabihf/release/deps/librand-2e052310e627cf80.rmeta --extern rand_chacha=/target/arm-unknown-linux-gnueabihf/release/deps/librand_chacha-ff08df3f680338be.rmeta --extern serde=/target/arm-unknown-linux-gnueabihf/release/deps/libserde-093279e46761f9bc.rmeta --extern serde_bytes=/target/arm-unknown-linux-gnueabihf/release/deps/libserde_bytes-e00731949f5f0e43.rmeta --extern serde_cbor=/target/arm-unknown-linux-gnueabihf/release/deps/libserde_cbor-73ce0baae4841a34.rmeta --extern subtle=/target/arm-unknown-linux-gnueabihf/release/deps/libsubtle-c5d00340592154ec.rmeta --extern zeroize=/target/arm-unknown-linux-gnueabihf/release/deps/libzeroize-afbe04cdd147be8e.rmeta --cap-lints allow -L native=/target/arm-unknown-linux-gnueabihf/release/build/openssl-sys-9b33cacbf7ef279f/out/openssl-build/install/lib` (signal: 11, SIGSEGV: invalid memory reference)
```

No backtrace was available as it was a segfault; the provided output was captured with `RUST_BACKTRACE=1`.