Add IL verification with ILVerify in addition to PEVerify#37994
Add IL verification with ILVerify in addition to PEVerify#37994RikkiGibson merged 54 commits intodotnet:mainfrom
Conversation
387a56d to
f60966d
Compare
| // Main module is the first one | ||
| var result = verifier.Verify(resolver.Resolve(_allModuleData[0].SimpleName)); | ||
| if (result.Count() == 0) | ||
| { |
There was a problem hiding this comment.
It looks like the catch block is unnecessary. #Resolved
There was a problem hiding this comment.
Sorry, I'd missed the fact that Verify() can throw exceptions. In that case, consider having the try { } catch { } wrap the Verify() call only, and catch specific exceptions rather than all.
This reverts commit 7e0ec94.
| string message = printVerificationResult(result); | ||
| throw new Exception("IL Verify failed unexpectedly: \r\n" + message); | ||
| } | ||
| catch (Exception) |
There was a problem hiding this comment.
From previous discussion with Jared, we don't distinguish between the different failure modes of ILVerify. Either it succeeds or it fails. That's why I added a comment to the test:
' ILVerify null ref
' Tracked by https//github.com/dotnet/roslyn/issues/58652
| return; | ||
| } | ||
|
|
||
| throw new Exception("IL Verify succeeded unexpectedly"); |
There was a problem hiding this comment.
There was indeed a bug here. Thanks. Fixed by reducing usage of exceptions for failure scenarios.
| var resolver = new Resolver(_allModuleData); | ||
| var verifier = new ILVerify.Verifier(resolver); | ||
|
|
||
| var mscorlibModule = _allModuleData.Single(m => m.IsCorLib); |
There was a problem hiding this comment.
| string name = module.SimpleName; | ||
| if (_imagesByName.ContainsKey(name)) | ||
| { | ||
| throw new Exception($"Multiple modules named '{name}' were found"); |
There was a problem hiding this comment.
Consider constructing the Dictionary<,> in the caller, without throwing an exception. #Resolved
|
|
||
| private sealed class Resolver : ILVerify.ResolverBase | ||
| { | ||
| private readonly Dictionary<string, ImmutableArray<byte>> _imagesByName = new Dictionary<string, ImmutableArray<byte>>(StringComparer.OrdinalIgnoreCase); |
| // Main module is the first one | ||
| var mainModuleReader = resolver.Resolve(_allModuleData[0].SimpleName); | ||
|
|
||
| var (succeeded, errorMessage) = verify(verifier, mscorlibModule.SimpleName, mainModuleReader); |
| if (result.Count() != 0) | ||
| { | ||
| return (false, printVerificationResult(result)); | ||
| } |
There was a problem hiding this comment.
Consider moving this outside the try { } catch { }. #ByDesign
There was a problem hiding this comment.
The Count() must be inside.

Relates to #22872