Skip to content

Enable feature stubprecode dynamic helpers again #115746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

davidwrighton
Copy link
Member

@davidwrighton davidwrighton commented May 19, 2025

Use the barrier approach to make this safe. Adding an address dependency got into lots of details around possibly needing an entire new stub type, and several paths through this code already depend on the concept of having a barrier here. To support modifying the stubs without inserting lots of magic number, rework how stubs are identified to just do a complete compare of the entire assembly stub in a way which will be easily to generalize to the cDAC.

Fixes #113810

… stream of assembly data instead of the current approach.
…e DAC. cDAC isn't done yet, but it should be simpler than the confusion that is today's implementation.
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@davidwrighton
Copy link
Member Author

/azp list

Copy link

CI/CD Pipelines for this repository:

@davidwrighton
Copy link
Member Author

/azp run runtime-diagnostics

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidwrighton davidwrighton marked this pull request as ready for review May 21, 2025 21:49
@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 21:49
Copy link
Contributor

@Copilot 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

This PR adds support for dynamic helper stub precodes (version 3) by switching to a full-byte-pattern comparison approach and integrates it into both the managed contracts and native runtime metadata.

  • Introduces PrecodeStubs_3_Impl with ReadBytesAndCompare for stub/fixup detection and updates the factory to return version 3.
  • Extends PrecodeMachineDescriptor (native) with full stub/fixup byte arrays and ignore masks, and initializes them in CDacPlatformMetadata.
  • Updates allocation and detection in precode.h/.cpp, VM startup, DAC tables, and ARM64 thunk templates to use the new patterns.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
PrecodeStubs_3.cs New v3 contract API using full-byte comparisons
PrecodeStubs_2.cs, PrecodeStubs_1.cs Ensure v2/v1 chaining still works
PrecodeStubsFactory.cs Register version 3 in factory switch
readytoruninfo.cpp, loaderallocator.hpp Switch dynamic helper allocation to AllocStub()
precode.h, precode.cpp Remove magic offsets, add Is*ByASM_DAC, use full-byte compare
cdacplatformmetadata.{hpp,cpp}, dacvars.h, datadescriptor.h Add new DAC fields & initialization for byte-pattern data
arm64 thunktemplates.* Insert memory-barrier (dmb ishld) for stubs
contracts.jsonc Bump PrecodeStubs contract version to 3
dactable.cpp, enummem.cpp Include new platform metadata header
clrfeatures.cmake Enable FEATURE_STUBPRECODE_DYNAMIC_HELPERS on AMD64/ARM64
PrecodeStubs.md Document v3 byte-pattern approach

#endif
}

void CDacPlatformMetadata::InitPrecodes()
{
PrecodeMachineDescriptor::Init(&(&g_cdacPlatformMetadata)->precode);
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

The expression &(&g_cdacPlatformMetadata)->precode is overly verbose. It can be simplified to &g_cdacPlatformMetadata.precode for clarity.

Suggested change
PrecodeMachineDescriptor::Init(&(&g_cdacPlatformMetadata)->precode);
PrecodeMachineDescriptor::Init(&g_cdacPlatformMetadata.precode);

Copilot uses AI. Check for mistakes.

davidwrighton and others added 4 commits May 21, 2025 15:19
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@max-charlamb
Copy link
Contributor

/azp run runtime-diagnostics

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas
Copy link
Member

jkotas commented May 21, 2025

Any numbers for the worst-case perf regressions that we expect to get from this change?

ldr x10, DATA_SLOT(StubPrecode, Target)
ldr x12, DATA_SLOT(StubPrecode, SecretParam)
br x10
brk 0xf000 // Stubs need to be 24-byte in size to allow for the data to be 3 pointers
brk 0xf000 // Stubs need to be 24-byte in size to allow for the data to be 3 pointers
LEAF_END_MARKED StubPrecodeCode\STUB_PAGE_SIZE

LEAF_ENTRY FixupPrecodeCode\STUB_PAGE_SIZE
Copy link
Member

@jkotas jkotas May 21, 2025

Choose a reason for hiding this comment

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

Why can we skip the barrier for FixupPrecode?

@@ -120,9 +120,12 @@ LEAF_END_MARKED CallCountingStubCodeTemplate, _TEXT
.irp STUB_PAGE_SIZE, 16384, 32768, 65536
Copy link
Member

Choose a reason for hiding this comment

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

Does FEATURE_MAP_THUNKS_FROM_IMAGE above need the same change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sigh, I missed that part of the merge. Yes.

@@ -120,9 +120,12 @@ LEAF_END_MARKED CallCountingStubCodeTemplate, _TEXT
.irp STUB_PAGE_SIZE, 16384, 32768, 65536

LEAF_ENTRY StubPrecodeCode\STUB_PAGE_SIZE
dmb ishld
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a counter-part barrier on the writer sides (e.g. in DynamicHelperFixup)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intermittent test crash on linux arm64 caused by FEATURE_STUBPRECODE_DYNAMIC_HELPERS
3 participants