Skip to content

fix(relinker): keep fs and gs accesses out of red-zone stubs - #295

Closed
Ryongen wants to merge 1 commit into
simnJS:AnyKytyfrom
Ryongen:fix/relinker-red-zone-tls
Closed

Ryongen wants to merge 1 commit into
simnJS:AnyKytyfrom
Ryongen:fix/relinker-red-zone-tls

Conversation

@Ryongen

@Ryongen Ryongen commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What

The red-zone framer could copy an fs:/gs: access into a stub, either as the instructions a short prologue was widened over or inside a relocated leaf. On Windows the TLS rewrite then patches the original bytes in place before the trampolines are written, so the conversion stopped with AMD-only site bytes changed before patching, and the stub copy would have kept the unrewritten access. The framer now never moves a segment-relative access: such a function is skipped and reported like the other unframed cases.

Tested

Windows 10 22H2, WinLibs GCC 15.2.0, LLVM 21.1.8.

  • red_zone_framer_tests gains leavesSegmentRelativeAccessesInPlace, a leaf without pushes that starts with mov rax, fs:0 and spills below rsp. It fails without the change and passes with it. red_zone_framer, red_zone_framer_execution and windows_red_zone_ranges pass.
  • python tools/check_conventions.py --base origin/AnyKyty and tools/check_kyty_settings.py: passed.
  • End to end: relinker --windows (red-zone framing on by default) converts Grand Theft Auto V (PPSA38500 01.002.001); before, it stopped at the function at 0x15c00d0, which starts with mov rax, fs:0 and stores at [rsp-0x4]. tools/audit_dump.py reports no stub or absent imports. The title then runs until kyty: bindless S#/T# loaded with s_buffer_load at a runtime offset stops resource tracking ("GetSamplerResource dword 0 is not a valid runtime value") #294.

Checklist

The Windows TLS rewrite patches fs: accesses in place before the trampolines are written, so a framed entry that moved one failed the byte check and its stub copy was never rewritten.
@simnJS

simnJS commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Merged into AnyKyty as 52e0a52e2d (authorship kept), in today's batch together with the sync of upstream main eba6750e46. CI green on Linux, sanitizers and Windows, and the in-game regression run was clean. Thank you!

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.

2 participants