Skip to content

Commit

Permalink
Use [SkipLocalsInit] & remove code for ILLink to strip locals init (#…
Browse files Browse the repository at this point in the history
…37541)

* Use [SkipLocalsInit] & remove code for ILLink to strip locals init

* Address review feedback

* Simply condition

* Clean up

* Fix condition
  • Loading branch information
layomia committed Jun 10, 2020
1 parent 584c9b5 commit e2ed363
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 8 deletions.
1 change: 0 additions & 1 deletion eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
<ILLink AssemblyPaths="$(ILLinkTrimInputAssembly)"
RootAssemblyNames=""
OutputDirectory="$(ILLinkTrimOutputPath)"
ClearInitLocals="$(ILLinkClearInitLocals)"
ExtraArgs="$(ILLinkArgs)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<Configurations>Debug;Release;Checked</Configurations>
<Platforms>x64;x86;arm;arm64</Platforms>

<ILLinkClearInitLocals>true</ILLinkClearInitLocals>
<ILLinkTrimAssembly>true</ILLinkTrimAssembly>
<ILLinkTrimXml>$(IntermediateOutputPath)System.Private.CoreLib.xml</ILLinkTrimXml>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/Common/src/SkipLocalsInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Used to indicate to the compiler that the .locals init flag should not be set in method headers.
[module: System.Runtime.CompilerServices.SkipLocalsInit]
3 changes: 0 additions & 3 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@

<PropertyGroup>
<EnableDefaultItems>false</EnableDefaultItems>

<!-- Clear the init locals flag on all src projects, except those in VB, where we can't use spans. -->
<ILLinkClearInitLocals Condition="'$(IsSourceProject)' == 'true' and '$(Language)' != 'VB'">true</ILLinkClearInitLocals>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildAllConfigurations)' != 'true'">
Expand Down
19 changes: 19 additions & 0 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,23 @@
<None Include="$(MSBuildProjectDirectory)\**\*.cs"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Compile)" />
</ItemGroup>

<PropertyGroup>
<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(IsSourceProject)' == 'true' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreApp)' == 'true' and '$(TargetFramework)' == '$(NetCoreAppCurrent)'">true</SkipLocalsInit>
</PropertyGroup>

<!--Instructs compiler not to emit .locals init, using SkipLocalsInitAttribute.-->
<Choose>
<When Condition="'$(SkipLocalsInit)' == 'true'">
<PropertyGroup >
<!-- This is needed to use the SkipLocalsInitAttribute. -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(CommonPath)SkipLocalsInit.cs" Link="Common\SkipLocalsInit.cs" />
</ItemGroup>
</When>
</Choose>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,9 @@
<Compile Include="$(CommonPath)Interop\Windows\Normaliz\Interop.Normalization.cs">
<Link>Common\Interop\Windows\Normaliz\Interop.Normalization.cs</Link>
</Compile>
<Compile Include="$(CommonPath)SkipLocalsInit.cs">
<Link>Common\SkipLocalsInit.cs</Link>
</Compile>
<Compile Include="$(CommonPath)System\HResults.cs">
<Link>Common\System\HResults.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Used to indicate to the compiler that the <c>.locals init</c> flag should
/// not be set in nested method headers when emitting to metadata.
/// Used to indicate to the compiler that the <c>.locals init</c>
/// flag should not be set in method headers.
/// </summary>
/// <remarks>
/// This attribute is unsafe because it may reveal uninitialized memory to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<Configurations>Debug;Release;Checked</Configurations>
<Platforms>x64;x86;arm;arm64;wasm</Platforms>

<ILLinkClearInitLocals>true</ILLinkClearInitLocals>
<ILLinkTrimAssembly>true</ILLinkTrimAssembly>
<ILLinkTrimXml>$(MSBuildThisFileDirectory)src\LinkerDescriptor\System.Private.CoreLib.xml</ILLinkTrimXml>
</PropertyGroup>
Expand Down

0 comments on commit e2ed363

Please sign in to comment.