Repository: rust
Issue: Segmentation fault when compiling `unicode-bidi` inside Docker
Labels: I-ICE,T-compiler,C-bug

Not sure if this is a useful bug report or not, but I'm building an `amd64` executable inside Docker on an `aarch64` host (Apple Silicon). `rustc` aborts with a `SIGSEGV` when compiling `unicode-bidi`. 

I don't have an `amd64` host to test on, so I don't know if this is caused by the oddity of my build environment. I can say I've successfully built project this way that _don't_ use `unicode-bidi`. But I figure any crash is useful to know about. It's easy to reproduce if you have an `aarch64` host.

### Code

#### Project Setup
```shell
cargo new amd-on-arm --lib
cd amd-on-arm
cargo add unicode-bidi 
# Create `Dockerfile` below
docker build .
```

#### Build Environment

```Dockerfile
FROM --platform=linux/amd64 rust:latest AS builder

RUN rustup target add x86_64-unknown-linux-musl
RUN apt update && apt install -y musl-tools musl-dev
RUN update-ca-certificates

COPY ./ .

RUN RUST_BACKTRACE=1 cargo build --target x86_64-unknown-linux-musl --release
```

### Meta

```shell
uname -a
Darwin MacBook-Pro.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64
```

`rustc --version --verbose`:

```
rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0
```

### Error output

<details><summary><strong>Backtrace</strong></summary>
<p>

```
[6/6] RUN cargo build --target x86_64-unknown-linux-musl --release:
#10 4.244     Updating crates.io index
#10 98.87  Downloading crates ...
#10 99.94   Downloaded unicode-bidi v0.3.7
#10 100.5    Compiling unicode-bidi v0.3.7
#10 102.8    Compiling amd-on-arm v0.1.0 (/)
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x51c173)[0x40021be173]
#10 104.2 /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x4005bf5140]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZNK4llvm13AttributeList12addAttributeERNS_11LLVMContextEjNS_9Attribute8AttrKindE+0x954)[0x400864f634]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x38feec9)[0x40096d3ec9]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x24e7931)[0x40082bc931]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x24e4d76)[0x40082b9d76]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm26PostOrderFunctionAttrsPass3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x590)[0x40082b89d0]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x24e342d)[0x40082b842d]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm11PassManagerINS_13LazyCallGraph3SCCENS_15AnalysisManagerIS2_JRS1_EEEJS4_RNS_17CGSCCUpdateResultEEE3runERS2_RS5_S4_S7_+0x3c6)[0x40089a39a6]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x2bce5cd)[0x40089a35cd]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm21DevirtSCCRepeatedPass3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x23a)[0x4008993ada]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x2bbe88d)[0x400899388d]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm33ModuleToPostOrderCGSCCPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x8af)[0x400874717f]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x29718bd)[0x40087468bd]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x144)[0x4008c75824]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm24ModuleInlinerWrapperPass3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x13d)[0x4008c7530d]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(+0x2ea01bd)[0x4008c751bd]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-stable.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x144)[0x4008c75824]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x242c191)[0x40040ce191]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2415b14)[0x40040b7b14]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2416056)[0x40040b8056]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x23bd42e)[0x400405f42e]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x23f3103)[0x4004095103]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2406ef7)[0x40040a8ef7]
#10 104.2 /usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-gnu/bin/../lib/libstd-a46a068050a12a4b.so(rust_metadata_std_c2a6a440a415d498+0xa7073)[0x400590d073]
#10 104.2 /lib/x86_64-linux-gnu/libpthread.so.0(+0x8ea7)[0x4005be9ea7]
#10 104.2 /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x4005d0bdef]
#10 104.2 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#10 104.2 error: could not compile `unicode-bidi`
#10 104.2
#10 104.2 Caused by:
#10 104.2   process didn't exit successfully: `rustc --crate-name unicode_bidi --edition=2018 /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/unicode-bidi-0.3.7/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 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=9385220479cd704e -C extra-filename=-9385220479cd704e --out-dir /target/x86_64-unknown-linux-musl/release/deps --target x86_64-unknown-linux-musl -L dependency=/target/x86_64-unknown-linux-musl/release/deps -L dependency=/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)

```

</p>
</details>