Skip to content

Remove PSEUDORANDOM_NOP_INSERTION and associated code including GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG, GT_EMITNOP#126282

Merged
EgorBo merged 4 commits intomainfrom
copilot/remove-pseudorandom-nop-insertion
Mar 30, 2026
Merged

Remove PSEUDORANDOM_NOP_INSERTION and associated code including GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG, GT_EMITNOP#126282
EgorBo merged 4 commits intomainfrom
copilot/remove-pseudorandom-nop-insertion

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Description

PSEUDORANDOM_NOP_INSERTION was a JIT spraying mitigation for partial trust scenarios. The define has been commented out for years and partial trust is not coming back. Remove it and all associated dead code, including the now-unused GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG, and GT_EMITNOP GenTree node types.

Removed across 18 files:

  • target.h: The commented-out #define
  • emit.h/emit.cpp: emitNextNop, emitRandomNops, emitInInstrumentation fields; emitEnableRandomNops()/emitDisableRandomNops()/emitNextRandomNop() methods; random NOP insertion logic in emitAllocAnyInstr
  • compiler.h/compiler.cpp: compChecksum, compRNG fields; adler32() and getMethodBodyChecksum() functions
  • gtlist.h: GT_EMITNOP, GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG GTNODE definitions
  • lower.cpp: GT_PINVOKE_PROLOG node creation in LowerNonvirtPinvokeCall; stale comment referencing the feature
  • codegenxarch.cpp, codegenarmarch.cpp, codegenloongarch64.cpp, codegenriscv64.cpp: GT_PINVOKE_PROLOG case handlers and emitDisableRandomNops() calls
  • codegenwasm.cpp: GT_PINVOKE_PROLOG case handler
  • lsraarm.cpp: GT_PINVOKE_PROLOG from BuildSimple case list
  • liveness.cpp: GT_PINVOKE_PROLOG and GT_PINVOKE_EPILOG from side-effecting node list
  • gentree.cpp: All three node types from TryGetUse, UseEdgeIterator, and gtDispLeaf switch statements
  • compiler.h/compiler.hpp: All three node types from switch case lists
  • instr.cpp: INS_lock NOP delay workaround
  • debug/di/module.cpp: NOP sled skipping logic and dead skipBytes variable

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Remove the disabled PSEUDORANDOM_NOP_INSERTION define and all code
guarded by it. This was a mitigation for JIT spraying in partial trust
scenarios which is no longer relevant.

Removed from:
- target.h: the commented-out define
- emit.h: emitInInstrumentation, emitNextNop, emitRandomNops,
  emitEnableRandomNops(), emitDisableRandomNops(), emitNextRandomNop()
- compiler.h: compChecksum, compRNG
- compiler.cpp: adler32(), getMethodBodyChecksum(), compChecksum usage
- emit.cpp: nop insertion init, emitNextRandomNop(), random nop logic
- instr.cpp: INS_lock nop delay workaround
- codegenxarch.cpp, codegenarmarch.cpp, codegenloongarch64.cpp,
  codegenriscv64.cpp: emitDisableRandomNops() calls in GT_PINVOKE_PROLOG
- debug/di/module.cpp: nop sled skipping logic
- lower.cpp: outdated comment about random NOPs

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/63c01eec-0aba-480d-82dd-9068f70068fc

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove pseudorandom nop insertion and associated code Remove PSEUDORANDOM_NOP_INSERTION and associated code Mar 29, 2026
Copilot AI requested a review from EgorBo March 29, 2026 20:45
@EgorBo EgorBo marked this pull request as ready for review March 29, 2026 21:13
Copilot AI review requested due to automatic review settings March 29, 2026 21:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes the long-disabled PSEUDORANDOM_NOP_INSERTION JIT-spraying mitigation and its associated dead code paths across the JIT emitter, compiler plumbing, codegen, and debugger-side workarounds.

Changes:

  • Deletes the dormant PSEUDORANDOM_NOP_INSERTION define and removes all remaining conditional code blocks tied to it.
  • Removes emitter/compiler state and helpers used for pseudorandom NOP insertion (RNG/checksum, scheduling, and insertion logic).
  • Cleans up downstream consumers/workarounds (PINVOKE prolog handling disable calls; debugger-side NOP-sled skip logic; stale comment).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/jit/target.h Removes the commented-out PSEUDORANDOM_NOP_INSERTION define block.
src/coreclr/jit/lower.cpp Removes stale comment that described the random-NOP mitigation behavior.
src/coreclr/jit/instr.cpp Removes xarch INS_lock workaround that depended on random-NOP insertion state.
src/coreclr/jit/emit.h Drops emitter fields/methods used exclusively for random NOP insertion.
src/coreclr/jit/emit.cpp Removes random-NOP initialization and insertion logic in the emitter.
src/coreclr/jit/compiler.h Removes compiler state (compChecksum, compRNG) used for NOP insertion seeding.
src/coreclr/jit/compiler.cpp Removes checksum/RNG seeding computation tied to the feature.
src/coreclr/jit/codegenxarch.cpp Removes emitDisableRandomNops() call for GT_PINVOKE_PROLOG.
src/coreclr/jit/codegenarmarch.cpp Removes emitDisableRandomNops() call for GT_PINVOKE_PROLOG.
src/coreclr/jit/codegenloongarch64.cpp Removes emitDisableRandomNops() call for GT_PINVOKE_PROLOG.
src/coreclr/jit/codegenriscv64.cpp Removes emitDisableRandomNops() call for GT_PINVOKE_PROLOG.
src/coreclr/debug/di/module.cpp Removes debugger-side skip logic for JIT-inserted NOP sleds tied to the feature.

Copy link
Copy Markdown
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

GT_EMITNOP and GT_PINVOKE_EPILOG should be deleted too.

@EgorBo
Copy link
Copy Markdown
Member

EgorBo commented Mar 29, 2026

@copilot please remove GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG and GT_EMITNOP.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 29, 2026

@copilot please remove GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG and GT_EMITNOP.

Removed all three node types in commit 6bb95d2 — deleted the GTNODE entries from gtlist.h, the GT_PINVOKE_PROLOG creation in lower.cpp, all codegen/LSRA/liveness/gentree case handlers, and the switch cases in compiler.h/compiler.hpp. JIT builds clean with 0 warnings, 0 errors.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/56d2c478-549a-4ec2-93a8-33402767111e

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI changed the title Remove PSEUDORANDOM_NOP_INSERTION and associated code Remove PSEUDORANDOM_NOP_INSERTION and associated code including GT_PINVOKE_PROLOG, GT_PINVOKE_EPILOG, GT_EMITNOP Mar 29, 2026
@EgorBo EgorBo enabled auto-merge (squash) March 30, 2026 01:16
@EgorBo EgorBo merged commit b6a7cd2 into main Mar 30, 2026
130 of 134 checks passed
@EgorBo EgorBo deleted the copilot/remove-pseudorandom-nop-insertion branch March 30, 2026 01:16
@EgorBo EgorBo restored the copilot/remove-pseudorandom-nop-insertion branch March 30, 2026 01:16
@EgorBo EgorBo deleted the copilot/remove-pseudorandom-nop-insertion branch March 30, 2026 01:16
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Mar 30, 2026
The leg didn't trigger on dotnet#126282 and now it's broken.
MichalStrehovsky added a commit that referenced this pull request Mar 30, 2026
The leg didn't trigger on #126282 and now it's broken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove PSEUDORANDOM_NOP_INSERTION and associated code

5 participants