Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers#31782

Merged
joperezr merged 3 commits intodotnet:masterfrom
joperezr:SRCSU
Aug 15, 2018
Merged

Conversation

@joperezr
Copy link
Member

Fixes: https://github.com/dotnet/corefx/issues/24012

The following PR needs to get merged and ingested in order for this to work: dotnet/buildtools#2123

Adding a target that will get a resource file with the file information headers, then it will transform the .res file into an obj (which is the format that ilasm takes) and then passes it down to the ilasm call so that System.Runtime.CompilerServices.Unsafe has the right version headers in them.

cc: @jkotas

</Exec>
<Error Condition="'$(_IldasmCommandExitCode)' != '0'" Text="ILDasm failed while running command: &quot;$(_IldasmCommand)&quot;" />

<!-- Calling cvtres.exe which should be on the path in order to transform the resource file to an obj -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is cvtres going to come from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question... Why do we even need it? Shouldn't ILDasm be emitting a format that roundtrips through ILAsm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a requirement right now saying that you have to be running on a developer command prompt in order to build corefx. That means that cvtres will be on the PATH. I know that this means we would add a dependency to VS (when we are trying to remove as much of them as possible) but we will only add this for Windows build and I will log an issue to ilasm so that they can provide another way of passing in version information without having to transform the .res file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even need it? Shouldn't ILDasm be emitting a format that roundtrips through ILAsm?

Talked to @jkotas about this offline, basically, ILDasm doesn't emit the format that ILAsm would be able to understand for now so we can submit a feature request for this.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look into driving

.custom instance void [CORE_ASSEMBLY]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 34 2E 30 2E 30 2E 30 00 00 ) // ...4.0.0.0..
.custom instance void [CORE_ASSEMBLY]System.Reflection.AssemblyInformationalVersionAttribute::.ctor(string) = ( 01 00 07 34 2E 30 2E 30 2E 30 00 00 ) // ...4.0.0.0..
off a header value? Might require adding the hex representation of ascii version string to the version header.

<_IldasmCommand>$(_IldasmCommand) $(ContractOutputPath)/$(MSBuildProjectName).dll</_IldasmCommand>
<_IldasmCommand>$(_IldasmCommand) /OUT=$(IntermediateOutputPath)Disassembly/$(MSBuildProjectName).il</_IldasmCommand>

<_CvtResCommand>cvtres.exe</_CvtResCommand>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can consider checking for this in the framework directory ($(SystemRoot)\Microsoft.NET\Framework\v4.0.30319\cvtres.exe) and falling back to assume on the path and warning if it is absent. That way you can support a case where someone ran outside a developer cmd prompt (even though its technically a requirement).

<Reference Include="System.Runtime" />
</ItemGroup>

<Target Name="AddResourcesFileToIlasm" BeforeTargets="CoreCompile" Condition="'$(OS)'=='Windows_NT'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to test what ILDasm did on linux? I'm curious if it does any better or this scenario (resource roundtripping) is completely broken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I tried running it on Linux and ildasm runs succesfully, except that it only proudces the .il file, it won't produce the .res as I believe it is expected.

</ItemGroup>

<Target Name="AddResourcesFileToIlasm" BeforeTargets="CoreCompile" Condition="'$(OS)'=='Windows_NT'">
<MakeDir Directories="$(IntermediateOutputPath)Disassembly" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than a directory i'd just give it a semi-unique name (to preserve path chars). Something like $(MSBuildProjectName).ref.il.

<Reference Include="System.Runtime" />
</ItemGroup>

<Target Name="AddResourcesFileToIlasm" BeforeTargets="CoreCompile" Condition="'$(OS)'=='Windows_NT'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add inputs / outputs so that you don't break incremental.


<!-- Getting the res file by disassemblying the contract assembly -->
<Exec Command="$(_IldasmCommand)" ConsoleToMSBuild="true" StandardOutputImportance="Low">
<Output TaskParameter="ExitCode" PropertyName="_IldasmCommandExitCode" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add file-writes so that clean works correctly.

BeforeTargets="CoreCompile"
Condition="'$(OS)'=='Windows_NT'"
Inputs="$(ContractOutputPath)/$(MSBuildProjectName).dll"
Outputs="$(IntermediateOutputPath)$(MSBuildProjectName).ref.obj">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I'd call this res.obj or ref.res.obj to indicate its a resource object. Add a comment about why its conditioned for only windows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

@joperezr
Copy link
Member Author

Merging now since OSX leg seems to have gone stale.

@joperezr joperezr merged commit e6506db into dotnet:master Aug 15, 2018
joperezr added a commit to joperezr/corefx that referenced this pull request Aug 16, 2018
…asm for S.R.CS.Unsafe so that it has the right version headers (dotnet#31782)

* Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers

* PR Feedback

* Updating buildtools and fixing obj name
@karelz karelz added this to the 3.0 milestone Aug 21, 2018
joperezr added a commit that referenced this pull request Sep 4, 2018
…asm for S.R.CS.Unsafe so that it has the right version headers (#31806)

* Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers (#31782)

* Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers

* PR Feedback

* Updating buildtools and fixing obj name

* Rev-up buildtools version to get required Fixes
@joperezr joperezr deleted the SRCSU branch November 2, 2018 20:10
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…asm for S.R.CS.Unsafe so that it has the right version headers (dotnet/corefx#31782)

* Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers

* PR Feedback

* Updating buildtools and fixing obj name


Commit migrated from dotnet/corefx@e6506db
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants