Skip to content

zig run and zig reduce increase process stack limit #25460

@RetroDev256

Description

@RetroDev256

Zig Version

0.16.0-dev.577+c50aa2b95

Steps to Reproduce and Observed Behavior

  1. Put this into test_program.zig:
const std = @import("std");

pub fn main() void {
    var buffer: [19 * (1 << 20)]u8 = undefined;
    std.mem.doNotOptimizeAway(&buffer);
    std.debug.print("Last: {}\n", .{buffer[buffer.len - 1]});
}
  1. Now put this into check_segfault.sh:
#!/bin/bash

zig build-exe test_program.zig
./test_program &> /dev/null

if [ $? -eq 139 ]; then
  exit 0 
else
  exit 2
fi
  1. Mark the script as executable: chmod +x check_segfault.sh
  2. Set your process stack limit to 8 MiB: ulimit -s 8192
  3. Run ./check_segfault.sh, process returns 2 (interesting for zig reduce)
  4. Now run zig reduce ./check_segfault.sh test_program.zig, you observe the following:
smoke testing the interestingness check...
error: interestingness check returned boring for unmodified input

You can also run this, which segfaults:

zig build-exe test_program.zig
./test_program

Whereas this DOES NOT segfault:

zig run test_program.zig

Expected Behavior

Zig should run it's child processes with the same stack limits as Zig's parent process. This hid the very issue I was trying to zig reduce earlier today. A workaround is to put ulimit -s [stack size] into the interestingness script itself, but I don't consider that a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions