Incorrect compilation / STATUS_ACCESS_VIOLATION when linking with lld with target-cpu set #72145
Closed
Description
The compilation of crates fails in various ways when a certain combination of rustflags is set.
[build]
rustflags = [
"-Clinker-flavor=lld-link",
"-Ctarget-cpu=sandybridge"
]
With this configuration I encountered the following issues:
- During installation of the
sd
crate (version 0.7.5), rustc crashes with aSTATUS_ACCESS_VIOLATION
. See the detailled error output below. - When installing
starship
, the resulting binary doesn't work correctly (see the issue here).
Using each rustflag individually does not result in this issue. I could reproduce this both on stable and the recent nightly, and with target-cpu
set to either sandybridge
, haswell
or znver2
(without trying more).
Meta
rustc --version --verbose
:
rustc 1.45.0-nightly (99cb9ccb9 2020-05-11)
binary: rustc
commit-hash: 99cb9ccb9ca2067ad6e60508e3d52da77396b2f1
commit-date: 2020-05-11
host: x86_64-pc-windows-msvc
release: 1.45.0-nightly
LLVM version: 9.0
Error during cargo install --force sd
❯ cargo install --force sd
Updating crates.io index
Installing sd v0.7.5
Compiling proc-macro2 v1.0.12
Compiling autocfg v1.0.0
Compiling unicode-xid v0.2.0
Compiling syn v1.0.20
Compiling cfg-if v0.1.10
Compiling lazy_static v1.4.0
Compiling version_check v0.9.1
Compiling winapi v0.3.8
Compiling getrandom v0.1.14
Compiling maybe-uninit v2.0.0
Compiling bitflags v1.2.1
Compiling unicode-width v0.1.7
Compiling libc v0.2.70
Compiling unicode-segmentation v1.6.0
Compiling scopeguard v1.1.0
Compiling memchr v2.3.3
Compiling vec_map v0.8.2
Compiling strsim v0.8.0
Compiling roff v0.1.0
Compiling rayon-core v1.7.0
Compiling ppv-lite86 v0.2.6
Compiling either v1.5.3
Compiling regex-syntax v0.6.17
Compiling unescape v0.1.0
Compiling thread_local v1.0.1
Compiling textwrap v0.11.0
Compiling man v0.3.0
Compiling heck v0.3.1
Compiling crossbeam-utils v0.7.2
Compiling memoffset v0.5.4
Compiling crossbeam-epoch v0.8.2
Compiling rand_core v0.5.1
Compiling proc-macro-error-attr v1.0.2
Compiling proc-macro-error v1.0.2
Compiling aho-corasick v0.7.10
Compiling num_cpus v1.13.0
Compiling rand_chacha v0.2.2
Compiling quote v1.0.4
Compiling rand v0.7.3
Compiling crossbeam-queue v0.2.1
Compiling crossbeam-deque v0.7.3
Compiling rayon v1.3.0
Compiling regex v1.3.7
Compiling syn-mid v0.5.0
Compiling atty v0.2.14
Compiling remove_dir_all v0.5.2
Compiling memmap v0.7.0
Compiling clap v2.33.1
Compiling tempfile v3.1.0
Compiling thiserror-impl v1.0.16
Compiling structopt-derive v0.4.7
Compiling thiserror v1.0.16
Compiling structopt v0.3.14
Compiling sd v0.7.5
error: failed to compile `sd v0.7.5`, intermediate artifacts can be found at `C:\Users\Chris\AppData\Local\Temp\cargo-installLldcG5`
Caused by:
could not compile `sd`.
Caused by:
process didn't exit successfully: `rustc --crate-name build_script_build --edition=2018 C:\Users\Chris\.cargo\registry\src\github.com-1ecc6299db9ec823\sd-0.7.5\build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C codegen-units=1 -C metadata=a9d539b504a5dcff -C extra-filename=-a9d539b504a5dcff --out-dir C:\Users\Chris\AppData\Local\Temp\cargo-installLldcG5\release\build\sd-a9d539b504a5dcff -L dependency=C:\Users\Chris\AppData\Local\Temp\cargo-installLldcG5\release\deps --extern man=C:\Users\Chris\AppData\Local\Temp\cargo-installLldcG5\release\deps\libman-415ee6d25251500d.rlib --extern structopt=C:\Users\Chris\AppData\Local\Temp\cargo-installLldcG5\release\deps\libstructopt-75fe88c87a7c5329.rlib --cap-lints allow -Clinker-flavor=lld-link -Ctarget-cpu=sandybridge` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
Also possibly relevant for #71520.
Metadata
Assignees
Labels
Area: linking into static, shared libraries and binariesCategory: This is a bug.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHelping to "clean up" bugs with minimal examples and bisectionsToolchain: MSVC, Operating system: WindowsHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.