Skip to content

rust program that allocates a large temporary segfaults on MacOS #107814

Description

@squell

While playing around with rustc 1.69.0-nightly (bd39bbb 2023-02-07) on MacOS, I ran into the following:

//const N: usize = 2_088_032; // largest size that works without abort
const N: usize = 2_092_349; // first segfault 

fn main () {
    let _ = Box::new([0; N]);
}

With N <= 2088032 this program works fine; above that the binary that rustc makes produces a runtime abort. Both are acceptable outcomes.

But with N >= 2092349 running the program results in a segmentation fault instead. It sounds like something has destroyed something that the stack unwinder relies on?

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (bd39bbb4b 2023-02-07)
binary: rustc
commit-hash: bd39bbb4bb92df439bf6d85470e296cc6a47ffbd
commit-date: 2023-02-07
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7
Backtrace

n/a (the compiled program segfaults)

Activity

  1. added
    O-AArch64Armv8-A or later processors in AArch64 mode
    A-stack-probeArea: Stack probing and guard pages
    on Feb 9, 2023
  2. workingjubilee commented on Feb 9, 2023

    @workingjubilee
    Member

    I believe this is a consequence of not properly probing the stack due to the lack of support for it on aarch64.

  3. luqmana commented on Sep 19, 2024

    @luqmana
    Contributor

    Looks like this has since been resolved (#118491 enabled inline stack probes for aarch64).

    $ rustc +1.68-aarch64-apple-darwin crash.rs
    $ ./crash
    [1]    57080 segmentation fault  ./crash
    
    $  rustc +nightly -vV
    rustc 1.83.0-nightly (f79a912d9 2024-09-18)
    binary: rustc
    commit-hash: f79a912d9edc3ad4db910c0e93672ed5c65133fa
    commit-date: 2024-09-18
    host: aarch64-apple-darwin
    release: 1.83.0-nightly
    LLVM version: 19.1.0
    
    $ rustc +nightly crash.rs
    $ ./crash
    
    thread 'main' has overflowed its stack
    fatal runtime error: stack overflow
    [1]    57097 abort      ./crash
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-stack-probeArea: Stack probing and guard pagesC-bugCategory: This is a bug.O-AArch64Armv8-A or later processors in AArch64 mode

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions