-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix crossgen2 sometimes emitting tokens from the wrong module #114172
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
Conversation
…ldWithToken to ensure that the tokens in question are from the same module. Prevents us from erroneously using another module's token in a way that will produce bad R2R modules.
/azp run runtime-coreclr crossgen2 outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this 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 aims to prevent crossgen2 from emitting tokens from the wrong module by adding a safety check during R2R generation and updating token comparers.
- Updated equality comparisons in RuntimeDeterminedTypeHelper to include module tokens.
- Added a safety check in SignatureBuilder to throw an error for tokens from modules outside the version bubble.
- Added a similar safety check in ModuleTokenResolver for validating module tokens.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs | Adds module token comparisons in equality checks for methods and fields. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/SignatureBuilder.cs | Introduces a safety check ensuring that tokens are only used from modules within the version bubble. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs | Adds a version-bubble check for module tokens and raises an error if the module is not valid. |
Comments suppressed due to low confidence (1)
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs:316
- Consider caching the result of _moduleIndexLookup(module) after the initial call to avoid duplicate lookups later in the method.
return _moduleIndexLookup(module);
The arm64 outerloop failure looks like it would be fixed by #106099. |
Under very specific circumstances, R2R can accidentally allow tokens from other modules into its output. These tokens are valid as long as none of the assemblies in use change, but if an assembly changes (i.e. due to a runtime update) tokens pointing into that assembly are no longer valid, and you'll get crashes at runtime from the tokens no longer being what the R2R module expects them to be.
This PR adds a safety check to detect this happening during R2R generation so that we won't quietly produce broken R2R modules, and it also fixes a couple comparers to detect the case where tokens are from different modules (previously, tokens from different modules would compare as equal if they were otherwise equivalent.)
Fixes #114183