relinker: on Windows, a short AMD-only site can take an fs: access that WindowsTlsBuilder rewrites ("AMD-only site bytes changed before patching") #27643
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by GiannisG1 on 2026-11-26T21:09:49Z.
Problem
A Windows
--to-intelrelink fails withwhen a short AMD-only instruction, too short for the 5-byte jump to its stub, absorbs a following
fs:orgs:access. Found on PPSA38500 in #27564: @akkadbakkad89's dump (issuecomment-7202722298) shows a 13-byte site at RVA0xfe10fd. Its original bytes arec5 f8 53 e2 64 48 8b 04 25 00 00 00 00(vrcpps xmm4, xmm2, the optional RCPPS lowering, plusmov rax, fs:[0]), and the section heldc5 f8 53 e2 e9 8f bc 71 0e 90 90 90 90when the site was checked.Cause
Amd64OnlyConverter.cpprefuses an FS/GS-prefixed neighbour only when the converter keeps segment accesses:(_keepSegmentAccesses && info.SegmentPrefix != 0).WindowPlacer's segment fallback (#7309) depends on the same flag.Conversion.cpp(executable) andGuestModuleBuilder.cpp(guest modules) set it for macOS only (#25971: "Linux and Windows output … are unchanged").WindowsPePatcherandWindowsGuestModuleWriterrunWindowsTlsBuilder::Build, which rewrites guestfs:/gs:accesses in the section bytes, beforeWindowsTrampolineBuilder::Buildchecks each site'sOriginalBytes. Anfs:access absorbed into a site is therefore rewritten under the site, and the check fails. A segment access moved into a stub cannot work on Windows anyway: the stub would read the Windowsfs:, not the guest TLS. Linux runs guest FS accesses natively, so this does not apply there.Reproduction
An executable whose code is
vrcpps xmm4, xmm2; mov rax, fs:[0]; ret(with aPT_TLSheader), converted with--to-intelfor Windows, fails onmain7c5d920df6with the message above. The same conversion for Linux succeeds.Proposed fix
Create the converter with segment accesses kept on Windows as on macOS, so that
WindowsTlsBuilderalone owns those instructions. An optional lowering without room (RCPPS) is then kept, and a required one without room is refused at conversion time, as on macOS. A pull request with this change and a conversion test follows.