Skip to content

YJIT: ZJIT: Use opt-level=1 on dev builds to avoid SystemStackError - #16647

Merged
XrXr merged 4 commits into
ruby:masterfrom
Shopify:zjit-opt-1-to-save-stack-space
Apr 3, 2026
Merged

YJIT: ZJIT: Use opt-level=1 on dev builds to avoid SystemStackError#16647
XrXr merged 4 commits into
ruby:masterfrom
Shopify:zjit-opt-1-to-save-stack-space

Conversation

@XrXr

@XrXr XrXr commented Apr 2, 2026

Copy link
Copy Markdown
Member

@XrXr

XrXr commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

(the way I figured this out was by commenting out the check in SEGV/SIGBUS handlers for stackoverflow to get a crash with a stack trace instead of a nondescript SystemStackError 8f64228)

@XrXr XrXr linked an issue Apr 2, 2026 that may be closed by this pull request
@XrXr
XrXr force-pushed the zjit-opt-1-to-save-stack-space branch from 4cdb64f to a34f7e9 Compare April 2, 2026 21:08
@XrXr
XrXr requested a review from a team April 2, 2026 21:09
Comment thread zjit/src/cruby.rs Outdated
Comment thread Cargo.toml

@k0kubun k0kubun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for figuring this out 🙏

@XrXr
XrXr force-pushed the zjit-opt-1-to-save-stack-space branch 2 times, most recently from d401926 to c3e5830 Compare April 2, 2026 22:00
@XrXr
XrXr enabled auto-merge (rebase) April 2, 2026 22:23
XrXr added 4 commits April 2, 2026 18:27
The transmute triggered a miscompilation on Rust 1.85.0, where the
callback was "optimized" to unconditional go to a `SIGTRAP`ping
instruction.

While later Rust versions don't have the same miscompilation, it seems
that this is also partly our fault for being funky with the pointer provenance
in this code. It's possible rust will make some changes that break the
transmute.

Use the Exposed Provenance API here and steer clear of transmute.

See: rust-lang/rust#121282
See: rust-lang/rust#147265
See: rust-lang/rust#128409 (comment)
Despite adding rb_ec_stack_check() to Rust code entry points, we've seen
SystemStackError causing test failures due to debug builds consume too
much native stack space. Let's use opt-level=1 so rustc/LLVM are more
efficient with stack space usage, hopefully enough to fit in the margin
in rb_ec_stack_check(). Continue to use opt-level=0 in the test profile.
@XrXr
XrXr force-pushed the zjit-opt-1-to-save-stack-space branch from c3e5830 to 2c63fcd Compare April 2, 2026 22:28
@XrXr
XrXr merged commit 2317564 into ruby:master Apr 3, 2026
105 of 109 checks passed
@XrXr
XrXr deleted the zjit-opt-1-to-save-stack-space branch April 3, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZJIT: SystemStackError in TestOpenURI and TestOpenURISSL

2 participants