Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

How to run ILVerify? #6198

Closed
svick opened this issue Aug 9, 2018 · 6 comments
Closed

How to run ILVerify? #6198

svick opened this issue Aug 9, 2018 · 6 comments

Comments

@svick
Copy link
Contributor

svick commented Aug 9, 2018

I got a confusing error message when running PEVerify on an assembly, so I wanted to see if ILVerify fared better but I didn't actually manage to run it and my experience along the way was fairly bad. Here's what I did:

  1. Consult the readme. This doesn't help, there is no information about building or running ILVerify there.

  2. Find the right project. Should I use the one in src/ILVerify/src or the one in src/ILVerify/netcoreapp? The one in netcoreapp seems to be Hello World, so it must be the one in src. Why is the Hello World even there?

  3. Attempt to open the solution in VS. This failed with the cryptic "error : Project file is incomplete. Expected imports are missing.".

  4. Attempt to build the solution with dotnet build. Got an error that I should run init-tools.cmd.

  5. Run init-tools.cmd and then dotnet build again, both succeeded. Though dotnet build produced the following confusing warning:

    E:\Users\Svick\git\corert\Tools\packageresolve.targets(93,5): warning : Your project is not referencing the ".NETCoreApp,Version=v2.1" framework. Add a reference to ".NETCoreApp,Version=v2.1" in the "frameworks" section of your project.json, and then re-run NuGet restore.

  6. Try to run the project with dotnet run. Got:

    System.ComponentModel.Win32Exception (2): The system cannot find the file specified
    at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
    at System.Diagnostics.Process.Start()
    at Microsoft.DotNet.Cli.Utils.Command.Execute()
    at Microsoft.DotNet.Tools.Run.RunCommand.Start()
    at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
    at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
    at Microsoft.DotNet.Cli.Program.Main(String[] args)

  7. Try to directly run the built dll with dotnet. Got:

    A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'E:\Users\Svick\git\corert\bin\Windows_NT.x64.Debug\ILVerify'.
    Failed to run as a self-contained app. If this should be a framework-dependent app, specify the appropriate framework in E:\Users\Svick\git\corert\bin\Windows_NT.x64.Debug\ILVerify\ILVerify.runtimeconfig.json.

  8. Try to run the project in VS. Got:

  9. Try to rename the dll to exe and run it. Got:

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.Metadata, Version=1.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Things that I think should be done:

  1. The build should be fixed (assuming it's actually broken).
  2. Readme should be updated with build steps.
  3. The Hello World project should be deleted.
@jkotas
Copy link
Member

jkotas commented Aug 9, 2018

Run build.cmd in repo root first. ilverify.exe will be in \corert\bin\Windows_NT.x64.Debug\ILVerify\ILVerify.exe. You can verify that it works by running:

\corert\bin\Windows_NT.x64.Debug\ILVerify\ILVerify.exe %WINDIR%\Microsoft.NET\Framework\v4.0.30319\CasPol.exe -r:%WINDIR%\Microsoft.NET\Framework\v4.0.30319\*.dll

Once you have done build.cmd succesfuly once, you should be able to open the project src\ILVerify\src\ILVerify.csproj in VS and work with it as usual.

The Hello World project should be deleted.

This is glue between the buildtools build system and regular dotnet build system. This can be deleted once corert is converted to SDK projects (like what was done in dotnet/corefx#29831).

@svick
Copy link
Contributor Author

svick commented Aug 10, 2018

@jkotas Thanks, that does work. I still think this could be improved, but I understand if it doesn't make sense to work on that if the build system is going to change.

This is glue between the buildtools build system and regular dotnet build system.

The thing that confused me the most is that the code for that project is literally just Console.WriteLine("Hello world!");. Is that necessary for the glue to work?

@jkotas
Copy link
Member

jkotas commented Aug 10, 2018

Console.WriteLine("Hello world!") Is that necessary for the glue to work?

The glue just needs a dummy program with the right name to publish. The Console.WriteLine can be replaced by a comment that explains what it is for. https://github.com/dotnet/corert/tree/master/src/ILCompiler/netcoreapp is second place where we have the same pattern.

@ericsink
Copy link

(This issue is still open, and the difficulties I'm seeing are similar, so I hope it's okay to add to it.)

I'm trying to run ILVerify and just not having any luck getting things to build. I've tried Windows, Mac, and Linux/WSL.

On Windows, I'm using VS 2017. I've got the prereqs installed. But just trying to run build.cmd gives me:

The system cannot find the batch label specified - CheckMSBuild
Setting build variables failed.

This error is the same whether I am using a plain cmd.exe or a Visual Studio command prompt.

The init-tools.cmd does seem to work. Once I've done that, dotnet build in src/ILVerify/src seems to build something, but dotnet run does not work there. I do get bin\Windows_NT.x64.Debug\ILVerify\ILVerify.dll, but no .exe as described above, and trying to use dotnet to run the dll gives:

A fatal error was encountered. The library 'hostpolicy.dll' required ...

I decided to try Linux/WSL to see if I had more luck there. I got the prereqs installed without incident, But build.sh runs for a little bit and then gives:

/mnt/c/Users/eric/dev/corert/src/Native/Runtime/unix/unixasmmacrosamd64.inc:310:34: error: unexpected token
DEFAULT_FRAME_SAVE_FLAGS = 000000F1h + 00008000h
                             ^
<instantiation>:3:24: error: unknown token in expression
    lea rcx, [rsp + 10h]

So I switched to Mac. This one got the closest, as build.sh seems to be mostly successful. I do get output in bin/OSX.x64.Debug/ILVerify, but trying to run ILVerify.dll gives a dylib-flavored form of the hostpolicy error I saw on Windows.

Any tips would be appreciated. Thanks in advance.

@abelbraaksma
Copy link

@ericsink, I don't have answers for your build issues, but I just noticed (from here: dotnet/roslyn#22872) that there's a private build NuGet package available of the API: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.DotNet.ILVerification.

It has the (relatively new) public API described here: #3734

@jkotas
Copy link
Member

jkotas commented Jun 3, 2020

ILVerify was moved to dotnet/runtime repo. It is being published as a global tool. dotnet/runtime#35038 (comment) has an example how it works.

@jkotas jkotas closed this as completed Jun 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants