Repository navigation
Document ILVerify.Verifier thread safety, PEReader lifetime and the rest of the public API - #135989
Merged
Merged
Conversation
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
I add XML doc comments to
ILVerify.VerifierandIResolverdescribing their existing behavior and requirements: whether aVerifiercan be used from several threads, when verification runs, how long itsPEReaders must stay usable, and why the resolver must return the samePEReaderinstance each time it is asked for the same assembly or module. TheIResolversummaries now say "must" rather than "should". Behavior does not change. I also add XML doc comments to the rest of the public API declared insrc/coreclr/tools/ILVerification:VerificationResult,ErrorArgument,VerifierOptions, theVerifierErrorenum, and theVerifierconstructors and methods. Following review, theVerifierErrorvalues other thanNonehave no summaries of their own, because each would repeat the message the library reports for it. The package README describes what the package is for and shows a short example; following review, I removed its detailed section on thread safety, reader lifetime and resolver requirements.ILVerification/README.mdnow points to that example and to the XML doc comments in the source, and says that the shared type system compiled into the library is not part of its API, apart fromExceptionStringID.What the implementation does:
ILVerifyTypeSystemContextcaches oneEcmaModuleperPEReaderin aDictionary(ILVerifyTypeSystemContext.cs:24). It adds entries without a lock and never removes them (:101-112).Verifymethods return sequences produced by iterators (Verifier.cs:145,:214,:267), so verification and the resolver calls it needs run during enumeration.SetSystemModuleNameresolves the system module immediately (Verifier.cs:84-92).EcmaModulekeeps itsPEReaderand aMetadataReaderobtained from it (EcmaModule.cs:189-221). System.Reflection.Metadata requires thePEReaderto stay undisposed for the lifetime of thatMetadataReader(PEReaderExtensions.cs:73). Nothing in ILVerification disposes aPEReader.PEReaderinstance, so a resolver that returns a second instance for an assembly creates a second module with distinct types. This also applies when the assembly being verified is resolved by name. For example,System.Private.CoreLibis resolved by name when it is both the system module and the assembly being verified.Validation
I ran these probes against ILVerification built from
mainat 11ce222 (linux-x64, Release), verifying System.Collections.Specialized, System.Text.Json and System.Private.CoreLib from Microsoft.NETCore.App 10.0.12. For each method, I compared the results' diagnostic codes, exception IDs and IL offsets.Verifier, each call with its ownPEReader; 10 runs of 2400 callsInvalidOperationException("Operations that change non-concurrent collections must have exclusive access…") orArgumentException("An item with the same key has already been added")PEReaderon every call, against one that caches themStackUnexpectedVerify, 1000 of 1000 methods matched their reference results.Verify(peReader, method)PEReaderwhose module the verifier has cached, then verify more of its methodsObjectDisposedException; file-backed reader:AccessViolationException, and the process abortsILVerification.Tests, Release, on this branch: 501/501.Note
This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.