Repository navigation
fix(relinker): leave GS-prefixed LEA and NOP instructions unchanged - #9719
Conversation
jotitadev
left a comment
There was a problem hiding this comment.
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 f9b2a49 (base main 7e2ba73), arm64 and x86_64 under Rosetta with /usr/bin/python3 3.9.6:
- 231/231 on both.
- Red check: with
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) where sysctl.proc_translated reports 1 and the GS base is non-zero (%gs:0 reads 0x20506be00, 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.
There was a problem hiding this comment.
Reviewed exact head f9b2a49 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.
f9b2a49 to
0e916c8
Compare
|
@oneandonlydean when you have a moment, could you review/merge this one? It is rebased onto current Manual overlap check for the bot note: #9408 edits a different region of No code changes since the reviews; the new head is only the rebase. |
There was a problem hiding this comment.
I compared the rebased head 0e916c87efc3bb077d9fc20a2cfe65b2119efa3c with 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.
LEA computes an effective address and the multi-byte NOP ignores its operand, so neither accesses memory and a GS prefix on them is ignored. The Windows TLS builder and macOS image writer treated every ModRM memory form as an access and replaced these instructions with UD2 and NOP padding.
0e916c8 to
8b86ca3
Compare
|
@MarcZX10 rebased onto live Validation on the rebased head
Understood on the hold for title-agnostic PRs. I will leave this open and wait for the queue to decline; no further pings. |
|
I’ve noticed that asking you to hold this PR was unnecessary. It’s fine to keep submitting PRs; maintainers will handle them in due course. |
|
Thanks for the correction — noted. The separate current-main validation is already complete: head Could you re-review when convenient so the |
|
I have a small local follow-up for FS/GS prefixes on INS/STOS/SCAS: these instructions use fixed ES, so the decoder must ignore the segment override. This complements your LEA/NOP fix but touches the same insertion point. Would landing this PR first, then rebasing the follow-up while preserving both checks, work for you? I tested that resolution together with #9549 and our SDK-stub boundary fix on main |
|
Yes, landing #9719 first works for me. Rebase the INS/STOS/SCAS follow-up on the merged Thanks for testing the combined resolution with #9549 and the SDK-stub boundary fix. The 237 relinker CTests and the 96-case conversion matrix are good coverage, and it’s clear that this validates conversion and native tooling rather than execution of the converted x86-64 programs. No changes to this PR. |
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
|
Tested head 8b86ca3 merged onto main aeff26b (clean) on Windows 11, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release.
AI-assisted: yes (Claude Code); results above were run on this machine. |
|
Checked the decoder change (only |
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 onmainb7d1d47: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)