-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Make ilverify respect IgnoresAccessChecksToAttribute #130978
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
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/fix-ilverify-ignore-access-checks-to
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/coreclr/tools/ILVerification.Tests/ILTests/AccessTestsIgnoreChecks.il
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| .assembly extern System.Runtime | ||
| { | ||
| } | ||
|
|
||
| .assembly extern AccessTests | ||
| { | ||
| } | ||
|
|
||
| .assembly AccessTestsIgnoreChecks | ||
| { | ||
| // IgnoresAccessChecksTo("AccessTests") | ||
| .custom instance void System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute::.ctor(string) = ( | ||
| 01 00 0b 41 63 63 65 73 73 54 65 73 74 73 00 00 | ||
| ) | ||
| } | ||
|
|
||
| // The IgnoresAccessChecksToAttribute is not part of the BCL surface area; consumers of the | ||
| // feature (e.g. the IgnoresAccessChecksToGenerator) declare it in their own assembly. The | ||
| // runtime and ilverify recognize it purely by its namespace and name. | ||
| .class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute | ||
| extends [System.Runtime]System.Attribute | ||
| { | ||
| .method public hidebysig specialname rtspecialname instance void .ctor(string assemblyName) cil managed | ||
| { | ||
| ldarg.0 | ||
| call instance void [System.Runtime]System.Attribute::.ctor() | ||
| ret | ||
| } | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit AccessTestsIgnoreChecksType | ||
| extends [System.Runtime]System.Object | ||
| { | ||
| .method public hidebysig instance void Instantiate.PrivateClass_Valid() cil managed | ||
| { | ||
| newobj instance void [AccessTests]PrivateClass::.ctor() | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Instantiate.PrivateNested_Valid() cil managed | ||
| { | ||
| newobj instance void [AccessTests]SimpleClass/PrivateNestedClass::.ctor() | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Instantiate.AssemblyNested_Valid() cil managed | ||
| { | ||
| newobj instance void [AccessTests]SimpleClass/AssemblyNestedClass::.ctor() | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Instantiate.FamilyNested_Valid() cil managed | ||
| { | ||
| newobj instance void [AccessTests]SimpleClass/FamilyNestedClass::.ctor() | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Call.PrivateMethod_Valid() cil managed | ||
| { | ||
| call void [AccessTests]SimpleClass::PrivateMethod() | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Call.FamilyMethod_Valid() cil managed | ||
| { | ||
| call void [AccessTests]SimpleClass::FamilyMethod() | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Call.AssemblyMethod_Valid() cil managed | ||
| { | ||
| call void [AccessTests]SimpleClass::AssemblyMethod() | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Call.FamAndAssemMethod_Valid() cil managed | ||
| { | ||
| call void [AccessTests]SimpleClass::FamilyAndAssemblyMethod() | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Load.PrivateField_Valid() cil managed | ||
| { | ||
| ldsfld int32 [AccessTests]SimpleClass::privateField | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Load.AssemblyField_Valid() cil managed | ||
| { | ||
| ldsfld int32 [AccessTests]SimpleClass::assemblyField | ||
| pop | ||
| ret | ||
| } | ||
|
|
||
| .method public hidebysig instance void Load.PublicFieldOfPrivateClass_Valid() cil managed | ||
| { | ||
| ldsfld int32 [AccessTests]SimpleClass/PrivateNestedClass::publicField | ||
| pop | ||
| ret | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/coreclr/tools/ILVerification.Tests/ILTests/AccessTestsIgnoreChecks.ilproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.IL"> | ||
| <PropertyGroup> | ||
| <AssemblyName>$(MSBuildProjectName)</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).il" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is very rare case - check of last resort, and it is somewhat expensive due to custom attribute lookup and parsing. It should be done last when all other ways to prove accessibility failed.
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.
Does ILVerify performance matter to this extent? I'd have assumed the overhead to be fine enough for it.
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.
It is also about matching the runtime behavior. Runtime checks both
IgnoresAccessChecksToandInternalsVisibleToattributes last. It is not obvious that checking this attribute first is going to match the runtime behavior in all cases.