rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.8k stars 12.22k forks source link

`"".split('.')` in build.rs with `-Cremark=all` causes compiler segfault on ARM #116729

Open aldanor opened 8 months ago

aldanor commented 8 months ago
cargo new --bin foo
cd foo
echo "fn main() { _ = \"\".split('.'); }" >build.rs
RUSTFLAGS="-Cremark=all -Cdebuginfo=1" cargo +nightly build --release
note: /rustc/.../library/core/src/str/pattern.rs:546:9 gisel-legalize (missed): unable to legalize instruction: G_STORE %26:_(<4 x s8>), %25:_(p0) :: (store (<4 x s8>) into %ir.18, align 8)

error: could not compile `foo` (build script)

Caused by:
  process didn't exit successfully: `rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=323 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C metadata=01a3112ac4ce4489 -C extra-filename=-01a3112ac4ce4489 --out-dir target/debug/build/foo-01a3112ac4ce4489 -C incremental=foo/target/debug/incremental -L dependency=target/debug/deps -Cremark=all -Cdebuginfo=1`

(signal: 11, SIGSEGV: invalid memory reference)
note: /rustc/.../library/core/src/str/pattern.rs:543:0 size-info (analysis): AArch64O0PreLegalizerCombiner: Function: _ZN52_$LT$char$u20$as$u20$core..str..pattern..Pattern$GT$13into_searcher17h670b9d7d5e22c8caE: MI Instruction count changed from 43 to 40; Delta: -3

note: /rustc/.../library/core/src/str/pattern.rs:546:9 gisel-legalize (missed): unable to legalize instruction: G_STORE %26:_(<4 x s8>), %25:_(p0) :: (store (<4 x s8>) into %ir.18, align 8)

error: rustc interrupted by SIGSEGV, printing backtrace

(was randomly discovered while trying out cargo-remark which makes use of LLVM remarks)

A few notes of interest:

Nilstrieb commented 8 months ago

cc @Kobzol

Kobzol commented 8 months ago

@aldanor could you please try with some nightly from June 2023 or sooner? I wonder if this might be related to the remark changes I made, although the error is there even without using the new remark output machinery.

I don't have an ARM machine at hand to debug this.

aldanor commented 8 months ago

Ok, there you go:

That should narrow it down pretty well.

https://github.com/rust-lang/rust/compare/e6d4725c7...b2b34bd83

Kobzol commented 8 months ago

Thanks! That narrows it down indeed, e.g. the LLVM upgrade looks suspicious.

If you still want to devote some time to helping bisecting this, could you please run this:

$ RUSTFLAGS="-Cremark=all -Cdebuginfo=1" cargo bisect-rustc --start=2023-06-04 --end=2023-06-07 -- build --release

using the cargo-bisect-rustc tool? That should help bisecting it down to a single PR/compiler build.

aldanor commented 8 months ago

using the cargo-bisect-rustc tool? That should help bisecting it down to a single PR/compiler build.

@Kobzol for whatever reason, cargo-bisect-rustc says there's no regressions even if I point it at today's end date - while running it from the command line clearly fails...

Kobzol commented 8 months ago

Hmm, maybe it does not respects RUSTFLAGS or something like that. You can put the build code into a script, and then use --script (https://rust-lang.github.io/cargo-bisect-rustc/usage.html#scripting) option to let the tool know if it crashes or not.

aldanor commented 8 months ago

You can put the build code into a script, and then use --script

That's what I thought too, already tried. 🤔

aldanor commented 8 months ago

... I could try with git-bisect but have zero experience building and using rustc from scratch in cases like this.

aldanor commented 8 months ago

Ok, wrote a little bisecting script, rebuilding rustc from source manually and rerunning the above; was a bit tedious but it worked (still no idea why cargo bisect-rustc --script doesn't work but that's a separate question).

Here's the commit that breaks it: https://github.com/rust-lang/rust/commit/fd9bf594366e73efb1a26a023e0b4de8eff82b94 (and here's the PR: https://github.com/rust-lang/rust/pull/111999).

Kobzol commented 8 months ago

Thanks a lot!

CC @scottmcm