Skip to content
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

Add step to run linker on entire runtime pack during libraries build #40172

Merged
merged 8 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<!-- Honor the generic RuntimeConfiguration property. -->
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
layomia marked this conversation as resolved.
Show resolved Hide resolved
<RuntimeConfiguration Condition="'$(RuntimeConfiguration)' == ''">$(Configuration)</RuntimeConfiguration>
<RuntimeConfiguration Condition="'$(RuntimeConfiguration)' == '' AND ('$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Release')">$(Configuration)</RuntimeConfiguration>
<RuntimeConfiguration Condition="'$(RuntimeConfiguration)' == ''">Debug</RuntimeConfiguration>
Expand Down
49 changes: 28 additions & 21 deletions eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,28 @@
<None Include="@(ILLinkSubstitutionsXmls)" />
</ItemGroup>

<!-- Custom binplacing for pre/post-trimming and reports that is useful for analysis
<!-- Custom binplacing for post-trimming and reports that is useful for analysis
Must be enabled by setting BinPlaceILLinkTrimAssembly=true
-->
<ItemGroup Condition="'$(BinPlaceILLinkTrimAssembly)' == 'true'">
<BinPlaceTargetFramework Include="$(BuildSettings)">
<RuntimePath>$(ArtifactsBinDir)ILLinkTrimAssembly/$(BuildSettings)/trimmed</RuntimePath>
<BinPlaceTargetFrameworks Include="$(BuildSettings)">
<RuntimePath>$([MSBuild]::NormalizePath('$(LibrariesTrimmingArtifactsRoot)', 'trimmed'))</RuntimePath>
<ItemName>TrimmedItem</ItemName>
</BinPlaceTargetFramework>
<BinPlaceTargetFramework Include="$(BuildSettings)">
<RuntimePath>$(ArtifactsBinDir)ILLinkTrimAssembly/$(BuildSettings)/reports</RuntimePath>
</BinPlaceTargetFrameworks>
<BinPlaceTargetFrameworks Include="$(BuildSettings)">
<RuntimePath>$([MSBuild]::NormalizePath('$(LibrariesTrimmingArtifactsRoot)', 'reports'))</RuntimePath>
<ItemName>TrimmingReport</ItemName>
</BinPlaceTargetFramework>
<BinPlaceTargetFramework Include="$(BuildSettings)">
<RuntimePath>$(ArtifactsBinDir)ILLinkTrimAssembly/$(BuildSettings)/pretrimmed</RuntimePath>
</BinPlaceTargetFrameworks>
</ItemGroup>

<!-- Binplacing for pre-trimming that is used when running the linker
layomia marked this conversation as resolved.
Show resolved Hide resolved
on the entire runtime pack to observe warnings from verbose output
-->
<ItemGroup>
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrent)">
layomia marked this conversation as resolved.
Show resolved Hide resolved
<RuntimePath>$(LibrariesPretrimmedArtifactsPath)</RuntimePath>
<ItemName>PreTrimmedItem</ItemName>
</BinPlaceTargetFramework>
</BinPlaceTargetFrameworks>
layomia marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<Target Name="_EmbedILLinkXmls"
Expand Down Expand Up @@ -217,17 +223,18 @@
<!-- keep DynamicDependencyAttribute unless a project explicitly disables it -->
<ILLinkArgs Condition="'$(ILLinkKeepDepAttributes)' != 'false'">$(ILLinkArgs) --keep-dep-attributes true</ILLinkArgs>
<!-- suppress warnings with the following codes:
IL2006: The generic parameter 'T' from A with dynamically accessed member kinds B is passed into the generic parameter
'T' from 'System.Lazy<T>' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'
IL2008: Could not find type A specified in resource B
IL2009: Could not find method A in type B specified in resource C
IL2012: Could not find field A in type B specified in resource C
IL2025: Duplicate preserve of A in B
IL2026: Calling A which has B can break functionality when trimming application code. The target method might be removed.
IL2035: Unresolved assembly A in DynamicDependencyAttribute on B
IL2041: The DynamicallyAccessedMembersAttribute is only allowed on method parameters, return value or generic parameters.
IL2006: The generic parameter 'T' from A with dynamically accessed member kinds B is passed into the generic parameter
'T' from 'System.Lazy<T>' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'
IL2008: Could not find type A specified in resource B
IL2009: Could not find method A in type B specified in resource C
IL2012: Could not find field A in type B specified in resource C
IL2025: Duplicate preserve of A in B
IL2026: Calling A which has B can break functionality when trimming application code. The target method might be removed.
IL2035: Unresolved assembly A in DynamicDependencyAttribute on B
IL2050: P/invoke method A declares a parameter with COM marshalling. Correctness of COM interop
cannot be guaranteed after trimming. Interfaces and interface members might be removed.
-->
<ILLinkArgs>$(ILLinkArgs) --nowarn IL2006;IL2008;IL2009;IL2012;IL2025;IL2026;IL2035;IL2041</ILLinkArgs>
<ILLinkArgs>$(ILLinkArgs) --nowarn IL2006;IL2008;IL2009;IL2012;IL2025;IL2026;IL2035;IL2050</ILLinkArgs>
Copy link
Member

Choose a reason for hiding this comment

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

Why the change from IL2041 to IL2050? Nothing in this change should have changed what warnings are produced for the individual library build. So I think both 2041 and 2050 can be removed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started getting 2050 after syncing with master at the beginning of this PR. Some new code since the initial suppressions check in must have been added which causes these errors:

ILLink : error IL2050: System.Runtime.InteropServices.Marshal.CreateBindCtx(UInt32,IBindCtx&): P/invoke method 'System.Runtime.InteropServices.Marshal.CreateBindCtx(UInt32,IBindCtx&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: System.Runtime.InteropServices.Marshal.CreateBindCtx(UInt32,IBindCtx&): P/invoke method 'System.Runtime.InteropServices.Marshal.CreateBindCtx(UInt32,IBindCtx&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: System.Runtime.InteropServices.Marshal.MkParseDisplayName(IBindCtx,String,UInt32&,IMoniker&): P/invoke method 'System.Runtime.InteropServices.Marshal.MkParseDisplayName(IBindCtx,String,UInt32&,IMoniker&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: System.Runtime.InteropServices.Marshal.MkParseDisplayName(IBindCtx,String,UInt32&,IMoniker&): P/invoke method 'System.Runtime.InteropServices.Marshal.MkParseDisplayName(IBindCtx,String,UInt32&,IMoniker&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: System.Runtime.InteropServices.Marshal.BindMoniker(IMoniker,UInt32,Guid&,Object&): P/invoke method 'System.Runtime.InteropServices.Marshal.BindMoniker(IMoniker,UInt32,Guid&,Object&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: System.Runtime.InteropServices.Marshal.BindMoniker(IMoniker,UInt32,Guid&,Object&): P/invoke method 'System.Runtime.InteropServices.Marshal.BindMoniker(IMoniker,UInt32,Guid&,Object&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
ILLink : error IL2050: Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VarNumFromParseNum(Byte[],Byte[],Int32): P/invoke method 'Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VarNumFromParseNum(Byte[],Byte[],Int32)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\libraries\Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj]
ILLink : error IL2050: Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VarNumFromParseNum(Byte[],Byte[],Int32): P/invoke method 'Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VarNumFromParseNum(Byte[],Byte[],Int32)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\libraries\Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj]
ILLink : error IL2050: Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16): P/invoke method 'Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\libraries\Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj]
ILLink : error IL2050: Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16): P/invoke method 'Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed. [D:\repos\dotnet_runtime_2\src\libraries\Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj]
    0 Warning(s)
    10 Error(s)

2041 doesn't show up anymore following the sync hence removed.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like that came in last week with dotnet/linker#1382.

cc @MichalStrehovsky

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we now detect COM usage and mark it as unsafe. Apps that end up referencing these methods after trimming will always warn.

</PropertyGroup>

<MakeDir Directories="$(ILLinkTrimInputPath)" />
Expand Down Expand Up @@ -312,7 +319,7 @@
<!-- Similar to _CheckForCompileOutputs and runs in the same places,
always set these even if compile didn't run. -->
<Target Name="_CheckForILLinkTrimAssemblyOutputs"
BeforeTargets="CopyFilesToOutputDirectory;_CleanGetCurrentAndPriorFileWrites"
BeforeTargets="BinPlace;CopyFilesToOutputDirectory;_CleanGetCurrentAndPriorFileWrites"
Condition="'$(ILLinkTrimAssembly)' == 'true'">
<ItemGroup>
<PreTrimmedItem Condition="Exists('$(ILLinkTrimInputAssembly)')" Include="$(ILLinkTrimInputAssembly)" />
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,11 @@
<CLSCompliant Condition="'$(CLSCompliant)' == '' and ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true')">false</CLSCompliant>
<CLSCompliant Condition="'$(CLSCompliant)' == ''">true</CLSCompliant>
</PropertyGroup>

<PropertyGroup>
<LibrariesTrimmingArtifactsRoot>$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'ILLinkTrimAssembly', '$(BuildSettings)'))</LibrariesTrimmingArtifactsRoot>
<LibrariesPretrimmedArtifactsPath>$([MSBuild]::NormalizePath('$(LibrariesTrimmingArtifactsRoot)', 'pretrimmed'))</LibrariesPretrimmedArtifactsPath>
<LibrariesTrimmedArtifactsPath>$([MSBuild]::NormalizePath('$(LibrariesTrimmingArtifactsRoot)', 'trimmed-runtimepack'))</LibrariesTrimmedArtifactsPath>
</PropertyGroup>

</Project>
82 changes: 82 additions & 0 deletions src/libraries/illink-sharedframework.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<Project Sdk="Microsoft.Build.Traversal">
layomia marked this conversation as resolved.
Show resolved Hide resolved

<Target Name="ILLinkTrimSharedFramework"
AfterTargets="Build">

<PropertyGroup>
<!-- default action for core assemblies -->
<ILLinkArgs>$(ILLinkArgs) -c link</ILLinkArgs>
<!-- keep type-forward assemblies (facades) -->
<ILLinkArgs>$(ILLinkArgs) -t</ILLinkArgs>
<!-- update debug symbols -->
<ILLinkArgs>$(ILLinkArgs) -b true</ILLinkArgs>
<!-- don't remove the embedded root xml resource since ILLink may run again on the assembly -->
<ILLinkArgs Condition="'$(ILLinkTrimXml)' != ''">$(ILLinkArgs) --strip-descriptors false</ILLinkArgs>
<!-- pass the non-embedded root xml file on the command line -->
<ILLinkArgs Condition="'$(ILLinkTrimXmlLibraryBuild)' != ''">$(ILLinkArgs) -x "$(ILLinkTrimXmlLibraryBuild)"</ILLinkArgs>
<!-- don't remove the embedded substitutions xml resource since ILLink may run again on the assembly -->
<ILLinkArgs Condition="'$(ILLinkSubstitutionsXml)' != ''">$(ILLinkArgs) --strip-substitutions false</ILLinkArgs>
<!-- don't remove the embedded link attributes xml resource since ILLink may run again on the assembly -->
<!-- and ignore the link attributes xml file during the library build, since we need the attributes preserved until the final app is linked -->
<ILLinkArgs>$(ILLinkArgs) --strip-link-attributes false --ignore-link-attributes true</ILLinkArgs>
<!-- ignore unresolved references -->
<ILLinkArgs>$(ILLinkArgs) --skip-unresolved true</ILLinkArgs>
<!-- keep interface implementations -->
<ILLinkArgs>$(ILLinkArgs) --disable-opt unusedinterfaces</ILLinkArgs>
<!-- keep DynamicDependencyAttribute -->
<ILLinkArgs>$(ILLinkArgs) --keep-dep-attributes true</ILLinkArgs>
<!-- suppress warnings with the following codes:
IL2006: The generic parameter 'T' from A with dynamically accessed member kinds B is passed into the generic parameter
'T' from 'System.Lazy<T>' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'
IL2009: Could not find method A in type B specified in resource C
IL2025: Duplicate preserve of A in B
IL2026: Calling A which has B can break functionality when trimming application code. The target method might be removed.
IL2035: Unresolved assembly A in DynamicDependencyAttribute on B
IL2050: P/invoke method A declares a parameter with COM marshalling. Correctness of COM interop
cannot be guaranteed after trimming. Interfaces and interface members might be removed.
-->
<ILLinkArgs>$(ILLinkArgs) --nowarn IL2006;IL2009;IL2025;IL2026;IL2035;IL2050</ILLinkArgs>
</PropertyGroup>
layomia marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<!-- add two directories to load references: the libraries directory and CoreLib's directory -->
<_DependencyDirectories Include="$(LibrariesPretrimmedArtifactsPath.TrimEnd('\'))" />
<_DependencyDirectories Include="$(CoreCLRArtifactsPath)IL" />
</ItemGroup>

<PropertyGroup>
<ILLinkArgs>$(ILLinkArgs) -d @(_DependencyDirectories->'"%(Identity)"', ' -d ')</ILLinkArgs>
</PropertyGroup>

<ItemGroup>
<_AssembliesToLink Include="System.Private.CoreLib" />

<_LibrariesToLink Include="$(LibrariesPretrimmedArtifactsPath)*.dll" />
<_AssembliesToLink Include="@(_LibrariesToLink->'%(FileName)')" />
</ItemGroup>

<PropertyGroup>
<ILLinkArgs>$(ILLinkArgs) -a @(_AssembliesToLink->'%(Identity)', ' -a ')</ILLinkArgs>

<!-- Not currently using the trimmed CoreLib because it has already been trimmed and crossgen'd. -->
<ILLinkArgs>$(ILLinkArgs) -p copy System.Private.CoreLib</ILLinkArgs>
</PropertyGroup>

<!-- When running from Desktop MSBuild, DOTNET_HOST_PATH is not set.
In this case, explicitly specify the path to the dotnet host. -->
<PropertyGroup Condition=" '$(DOTNET_HOST_PATH)' == '' ">
<_DotNetHostDirectory>$(RepoRoot).dotnet</_DotNetHostDirectory>
<_DotNetHostFileName>dotnet</_DotNetHostFileName>
<_DotNetHostFileName Condition=" '$(OS)' == 'Windows_NT' ">dotnet.exe</_DotNetHostFileName>
</PropertyGroup>

<ILLink AssemblyPaths="$(LibrariesPretrimmedArtifactsPath)"
RootAssemblyNames=""
OutputDirectory="$(LibrariesTrimmedArtifactsPath)"
ExtraArgs="$(ILLinkArgs)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)" />
</Target>

<Import Project="$(RepositoryEngineeringDir)illink.targets" />
</Project>
12 changes: 11 additions & 1 deletion src/libraries/src.proj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$(MSBuildThisFileDirectory)Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj;
$(MSBuildThisFileDirectory)System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj"
Exclude="@(NonNetCoreAppProject)" />
<ILLinkSharedFrameworkProject Include="illink-sharedframework.proj" />
<ManualShimProject Include="shims\manual\*.csproj" />
<ApiCompatProject Include="shims\ApiCompat.proj"
Condition="'$(DotNetBuildFromSource)' != 'true' and
Expand All @@ -25,7 +26,8 @@
<ProjectReference Include="@(NetCoreAppProject)" />

<!-- Restore only and build before/after. -->
<ProjectReference Include="@(NonNetCoreAppProject);
<ProjectReference Include="@(ILLinkSharedFrameworkProject);
@(NonNetCoreAppProject);
@(ManualShimProject);
@(ApiCompatProject)"
Condition="'$(MSBuildRestoreSessionId)' != ''" />
Expand All @@ -49,6 +51,14 @@
Properties="$(TraversalGlobalProperties)" />
</Target>

<Target Name="ILLinkSharedFramework"
AfterTargets="Build">
<MSBuild Targets="Build"
Projects="@(ILLinkSharedFrameworkProject)"
Properties="$(TraversalGlobalProperties)"
/>
</Target>

<Target Name="RunApiCompat"
Condition="'@(ApiCompatProject)' != ''"
AfterTargets="BuildManualShims">
Expand Down