Skip to content

Skip BOLT optimization for HACL hash compressors - #1187

Merged
zanieb merged 1 commit into
mainfrom
zb/bolt-skip-hacl
Jul 22, 2026
Merged

Skip BOLT optimization for HACL hash compressors#1187
zanieb merged 1 commit into
mainfrom
zb/bolt-skip-hacl

Conversation

@zanieb

@zanieb zanieb commented Jul 22, 2026

Copy link
Copy Markdown
Member

Optimized x86-64 GNU/Linux builds can perform invalid stack writes in the HACL SHA-2 and BLAKE2 compressors because BOLT's allocation combiner removes their required stack allocation while retaining frame-pointer-relative accesses below the red zone. Extend -skip-funcs for the affected compressor symbols so BOLT leaves these functions intact while continuing to optimize the rest of the interpreter.

See #1186

# BOLT's allocation combiner can remove required stack allocations in
# the HACL hash compressors, leaving frame-pointer-relative accesses
# below the x86-64 red zone.
# https://github.com/astral-sh/uv/issues/20618

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
# https://github.com/astral-sh/uv/issues/20618
# https://github.com/astral-sh/python-build-standalone/issues/1186

@jjhelmus

Copy link
Copy Markdown
Contributor

Switching to -frame-opt=none is another option. It is safer but could have an effect on performance.

@zanieb

zanieb commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

I dunno why we'd turn that off broadly instead of skipping the relevant functions, I imagine it would affect performance?

@jjhelmus

Copy link
Copy Markdown
Contributor

I dunno why we'd turn that off broadly instead of skipping the relevant functions, I imagine it would affect performance?

The identified functions are those in which we know that the stack redline is being violated. There could be others. Disabling frame optimization would prevent cases in other, yet unknown, functions.

@zanieb
zanieb force-pushed the zb/bolt-skip-hacl branch from 9bbea27 to 83542cb Compare July 22, 2026 16:01
@jjhelmus

Copy link
Copy Markdown
Contributor

I imagine it would affect performance?

-frame-opt=none has a sizable effect on performance, from a quick fastmark benchmark, the score drops by ~1%.

@jjhelmus

jjhelmus commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Codex did not find any other functions with unsafe stack-frame removal resulting from BOLT outside the HACL related one. These function are implemented in assembly verified C so excluding them from additional optimization is reasonable.

@zanieb
zanieb marked this pull request as ready for review July 22, 2026 16:59
@zanieb
zanieb merged commit 59abeee into main Jul 22, 2026
17 checks passed
@zanieb
zanieb deleted the zb/bolt-skip-hacl branch July 22, 2026 17:08
@jjhelmus

Copy link
Copy Markdown
Contributor

FWIW this issue only occurs because frame pointer/leaf from pointer are included (-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer). Prior to this change the functions use stack pointer based access which is detected by BOLT's allocation combiner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants