-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add IL verification with ILVerify in addition to PEVerify #37994
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
Changes from 1 commit
d1e402c
70d3ab8
3f8b70f
6e2efce
bf116d9
a993d0e
7af8ecc
0ee5f6a
1701dbb
260a40e
7b0263a
400d315
e7a7c3f
9cafb53
656d328
eea70d3
d328e27
ebbc74a
66aa35b
c34aa28
d23c09c
5a01e58
ae83e16
9b1260c
ec54177
99e0f0a
b2fc7c7
ebacf4f
d57946e
a345b1b
7abba2e
f3a3859
262ee1e
733ac37
c1f0f8d
f193504
fffe57a
4cf0b49
dceda42
115da8a
af67143
a7dc694
ca5027f
6d83957
c7d7ba6
cb27c93
a11ad37
e32bf0a
7e0ec94
f5387f8
f9cf399
c55a61d
fcc2dc2
3db3d54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,41 +233,29 @@ private class Resolver : ILVerify.ResolverBase | |
|
|
||
| internal Resolver(IList<ModuleData> allModuleData) | ||
| { | ||
|
|
||
| foreach (var module in allModuleData) | ||
| { | ||
| var image = module.Image; | ||
| imagesByName.Add(module.FullName, image); | ||
|
|
||
| // Note: although the signature in ResolverBase.ResolveCore calls the parameter "simpleName" | ||
| // ILVerify can also pass in full names. So we do allow resolving both. | ||
| if (module.SimpleName != module.FullName) | ||
| string name = module.SimpleName; | ||
| if (imagesByName.ContainsKey(module.SimpleName)) | ||
| { | ||
| if (imagesByName.ContainsKey(module.SimpleName)) | ||
| { | ||
| imagesByName.Remove(module.SimpleName); | ||
| imagesByName.Add(module.SimpleName, default); | ||
| } | ||
| else | ||
| { | ||
| imagesByName.Add(module.SimpleName, image); | ||
| } | ||
| throw new Exception($"Multiple modules named '{name}' were found"); | ||
|
||
| } | ||
| imagesByName.Add(name, module.Image); | ||
| } | ||
| } | ||
|
|
||
| protected override PEReader ResolveCore(string name) | ||
| protected override PEReader ResolveCore(string simpleName) | ||
| { | ||
| if (imagesByName.TryGetValue(name, out var image)) | ||
| if (imagesByName.TryGetValue(simpleName, out var image)) | ||
| { | ||
| if (image.IsDefault) | ||
|
||
| { | ||
| throw new Exception($"ILVerify was not able to resolve a module named '{name}' because multiple exist in this compilation"); | ||
| throw new Exception($"ILVerify was not able to resolve a module named '{simpleName}' because multiple exist in this compilation"); | ||
| } | ||
| return new PEReader(image); | ||
| } | ||
|
|
||
| throw new Exception($"ILVerify was not able to resolve a module named '{name}'"); | ||
| throw new Exception($"ILVerify was not able to resolve a module named '{simpleName}'"); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -285,15 +273,16 @@ private void ILVerify(Verification verification) | |
| var mscorlibModules = _allModuleData.Where(m => m.SimpleName == "mscorlib").ToArray(); | ||
| if (mscorlibModules.Length == 1) | ||
| { | ||
| verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].FullName)); | ||
| verifier.SetSystemModuleName(new AssemblyName(mscorlibModules[0].SimpleName)); | ||
| } | ||
| else | ||
| { | ||
| // ILVerify requires a "system" module to be identified (see ILVerify.Verifier.ThrowMissingSystemModule) | ||
| // So we auto-detect a candidate module | ||
| // This comes in handy in tests that use TestBase.AacorlibRef for instance. | ||
| foreach (var module in _allModuleData) | ||
| { | ||
| var name = module.FullName; | ||
| var name = module.SimpleName; | ||
| var metadataReader = resolver.Resolve(name).GetMetadataReader(); | ||
| if (metadataReader.AssemblyReferences.Count == 0) | ||
| { | ||
|
|
@@ -304,7 +293,7 @@ private void ILVerify(Verification verification) | |
| } | ||
|
|
||
| // Main module is the first one | ||
| var result = verifier.Verify(resolver.Resolve(_allModuleData[0].FullName)); | ||
| var result = verifier.Verify(resolver.Resolve(_allModuleData[0].SimpleName)); | ||
| if (result.Count() == 0) | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'd missed the fact that |
||
| if ((verification & Verification.FailsIlVerify) == 0) | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
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.
When running on .NET Framework it would be legal for multiple assemblies to have the same simple name, presuming they had different strong names. If we must maintain this invariant then tests which do that won't ever be able to run against
ILVerify. That isn't a blocker as there are very few of these but want to make sure this was understood. #ByDesignThere 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.
Right. The issue is that
ILVerify.ResolverBase.ResolveCore(string simpleName)gives a simple name.So tests that deal with duplicate simple names will need to skip ILVerify for the moment.
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.
FYI: dotnet/runtime#65573 is proposing passing the full assembly name to the resolver.