Skip to content

Rust app crashes with segmentation fault #117334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kuzemchik opened this issue Oct 28, 2023 · 6 comments
Closed

Rust app crashes with segmentation fault #117334

kuzemchik opened this issue Oct 28, 2023 · 6 comments
Labels
A-stack-probe Area: Stack probing and guard pages C-bug Category: This is a bug. O-AArch64 Armv8-A or later processors in AArch64 mode O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kuzemchik
Copy link

kuzemchik commented Oct 28, 2023

Code compiled with Rust 1.70.0, 1.72.1, 1.73.0 yields code that is failing with segmentation fault in runtime.

I tried this code:

use std::convert::TryInto;
fn main() {
	let data:[f32; 1000*1000] = vec![1.0; 1000*1000]
        .try_into()
        .expect("Wrong matrix size!");
    print!("Result {}\n",data[0])	
}

I expected to see this happen:

  • "Result 1"
  • "Wrong matrix size!"
  • Compilation Error
  • Stack overflow

Instead, this happened:

  • segmentation fault (signal: 11, SIGSEGV: invalid memory reference)

Code below works (just dropping the size of vec/array)

use std::convert::TryInto;
fn main() {
	let data:[f32; 100*100] = vec![1.0; 100*100]
        .try_into()
        .expect("Wrong matrix size!");
    print!("Result {}\n",data[0])	
}

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: aarch64-apple-darwin
release: 1.70.0
LLVM version: 16.0.2
rustc 1.72.1 (d5c2e9c34 2023-09-13)
binary: rustc
commit-hash: d5c2e9c342b358556da91d61ed4133f6f50fc0c3
commit-date: 2023-09-13
host: aarch64-apple-darwin
release: 1.72.1
LLVM version: 16.0.5
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: aarch64-apple-darwin
release: 1.73.0
LLVM version: 17.0.2
Backtrace

➜  bug_report RUST_BACKTRACE=1 cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
➜  bug_report RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/bug_report`
[1]    39304 segmentation fault  RUST_BACKTRACE=1 cargo run

@kuzemchik kuzemchik added the C-bug Category: This is a bug. label Oct 28, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 28, 2023
@clubby789
Copy link
Contributor

This is a stack overflow as you're constructing two very large literal on the stack, one that's copied into the vec and one that is copied out. In release mode this is optimised out. Ideally you should see the message

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

rather than a segmention fault

@kuzemchik
Copy link
Author

@clubby789 makes sense, thanks.
And I would assume that there is no expectation that stack overflow should trigger panic.
Should I close the issue then?

@saethlin
Copy link
Member

A stack overflow, especially one written like this, is supposed to hit a stack protector. From the description, it sounds like that is not happening. On Linux, I see this:

    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/scratch`

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)

It's not clear to me if what you are observing is a bug in the stack protectors on aarch64-apple-darwin.

@saethlin saethlin added O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-AArch64 Armv8-A or later processors in AArch64 mode and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 29, 2023
@workingjubilee workingjubilee added the A-stack-probe Area: Stack probing and guard pages label Oct 29, 2023
@bjorn3
Copy link
Member

bjorn3 commented Oct 29, 2023

We don't enable stack probes on AArch64.

@iximeow
Copy link
Contributor

iximeow commented Sep 19, 2024

this looks like a dupe of #107814 and presumably is also fixed.

@saethlin
Copy link
Member

Sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stack-probe Area: Stack probing and guard pages C-bug Category: This is a bug. O-AArch64 Armv8-A or later processors in AArch64 mode O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants