fix(relinker): leave GS-prefixed LEA and NOP instructions unchanged #9719
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9719"
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 AasishDairelSahayaGrinspan on 2026-10-22T09:46:45Z.
What
HasMemoryOperandis set for every ModRM memory form, includingLEA(8D /r) and the multi-byteNOP(0F 1F /0). Neither accesses memory:LEAcomputes an effective address into a register and the multi-byte NOP does not issue a memory operation (Intel SDM Vol. 2A,LEA; Vol. 2B,NOP), so a GS prefix on either is ignored. The Windows TLS builder and the macOS image writer trap every GS-prefixed instruction whoseHasMemoryOperandis set, replacing it withUD2and NOP padding, so a converted binary faults on an instruction the console executes. This is a follow-up to #8063, which limited the trap to memory accesses.objdumpstill prints%gs:for both encodings (65 8D 05 ...isleal %gs:..., %eaxand65 0F 1F 05 ...isnopl %gs:...), so an audit that equates that text with a memory access counts these two forms as accesses. The instruction definitions above say otherwise: the prefix is decoded and ignored, and no memory is read or written.HasMemoryOperandforLEAand0F 1Fafter reading their ModRM byte. Length,HasModRm, RIP-relative displacement and branch metadata are unchanged.DecoderLengthTestsgains65 8D 05 11 11 11 11and65 0F 1F 05 11 11 11 11as non-memory forms.test_macos_gs_traps.pygains the same two forms as untouched cases, and the Windows TLS fixture gains ags_non_memorygroup with both. The group is separate so each CTest group stays under its 30 s timeout.Tested
macOS 15.7.7, x86_64, AppleClang 17, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON) on this branch based onmainb7d1d47a5f:ctest231/231 pass, includingdecoder_length,tls_function_coverage_gs_non_memoryandmacos_gs_traps.Wrong memory operand presence for 658d0511111111, the Windowsgs_non_memorygroup, andgs-nop-memory: a non-memory GS instruction was replacedon macOS. This covers the decoder and both output writers.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/pr_overlap.py --branch fix/relinker-gs-non-memory-operandsreports no overlap with open pull requests.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T10:26:14Z.
Review: COMMENTED
Apple silicon data point, since the macOS output now leaves these two forms in place and on Apple silicon they run under Rosetta 2.
Apple M2 Max, macOS 27.2, relinker-only Release build of head f9b2a49ab (base main
7e2ba73e4c), arm64 and x86_64 under Rosetta with/usr/bin/python33.9.6:X64InstructionDecoder.cppandX64OpcodeConstants.hpprestored to main and the new fixtures kept,decoder_length,tls_function_coverage_gs_non_memoryandmacos_gs_trapsfail on both architectures. With the PR they pass.Rosetta runs the untouched forms as the SDM says. I used a standalone x86_64 probe (
clang -arch x86_64) wheresysctl.proc_translatedreports 1 and the GS base is non-zero (%gs:0reads0x20506be00, the TSD self pointer):65 48 8D 04 25 10 00 00 00(lea rax, gs:[0x10]) gives0x10, the same as the unprefixed form. The GS base is not added.65 48 8D 07(lea rax, gs:[rdi]) givesrdiunchanged.65 48 8D 15 <disp32>right after48 8D 05 <disp32>gives a result exactly 8 bytes higher, which is the instruction length. That matches plain RIP-relative arithmetic.65 0F 1F 05 <disp32>,65 0F 1F 04 25 <disp32>and65 66 0F 1F 84 00 00 00 00 00execute without faulting.So on Apple silicon, a converted Mach-O that keeps these instructions computes the same values the console does.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:02:22Z.
Review: COMMENTED
Reviewed exact head f9b2a49ab676c813724b6c55d036b1d3d83426c6 against current upstream/main. I found no code-level blocker: the decoder change is restricted to legacy LEA and multi-byte NOP opcodes, preserves ModRM decoding/length metadata, and both Windows and macOS output fixtures verify the prefixed bytes remain untouched. Current conventions and diff checks pass; the branch merges cleanly. The described 231-test Linux/Windows/macOS relinker CI plus the Apple Silicon/Rosetta red/green report are directly relevant and detailed; I did not rerun them locally.
I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-22T14:40:13Z.
@oneandonlydean when you have a moment, could you review/merge this one? It is rebased onto current
main(8b3e39832a); the relinker matrix is green on Linux, Windows, macOS arm64, macOS x86_64 and ASan, conventions pass, and both reviews above are positive, including the independent Apple silicon/Rosetta red/green run.Manual overlap check for the bot note: #9408 edits a different region of
core/relinker/CMakeLists.txt(the trace-import test around line 542) from this PR's TLS group list around line 498; #5021, #6044 and #6879 already conflict withmainand touch other parts of the file. No same-line overlap, so noDepends onis needed.No code changes since the reviews; the new head is only the rebase.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T15:28:47Z.
Review: DISMISSED
I compared the rebased head
0e916c87efc3bb077d9fc20a2cfe65b2119efa3cwith the previously reviewed commit: the patch IDs are identical, so this is a rebase-only update. The current relinker matrix, ASan, conventions and eligibility checks are green, and the 11 commits now on upstream/main do not touch this PR’s six changed paths. The author and independent reviewer also report the 231-case red/green run and Apple Silicon/Rosetta probes; I did not rerun that suite locally. I found no code-level issue.Before merge, please rebase onto the live upstream/main (
b7d1d47a5f9f32c9c388ad8d47a0055a90ae6e33) and rerun the focused validation: CONTRIBUTING says to keep branches up to date. This head is 11 commits behind that main.