Skip to content

Commit

Permalink
Delete DebugSymbols=true setting for the repo build (dotnet#102392)
Browse files Browse the repository at this point in the history
* Delete DebugSymbols

This property does not do what its name says. The symbols are generated regardless of whether this property is true or false. What this property actually does is that it disables C# peephole IL optimizations.

This change results in ~0.5% IL binary size improvement thanks to the Roslyn IL peephole optimizations that it enables.

* Update eng/illink.targets

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>

---------

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
  • Loading branch information
2 people authored and Ruihan-Yin committed May 30, 2024
1 parent b1b6da8 commit 6cfb742
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@
<NoWarn>$(NoWarn),CS8969</NoWarn>
<!-- Always pass portable to override arcade sdk which uses embedded for local builds -->
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<KeepNativeSymbols Condition="'$(KeepNativeSymbols)' == '' and '$(DotNetBuildSourceOnly)' == 'true'">true</KeepNativeSymbols>
<KeepNativeSymbols Condition="'$(KeepNativeSymbols)' == ''">false</KeepNativeSymbols>
<!-- Used for launchSettings.json and runtime config files. -->
Expand Down
4 changes: 2 additions & 2 deletions eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<!-- Only run the trim analyzer on libraries which have been annotated. -->
<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' And (Exists('$(ILLinkSuppressionsXml)') Or Exists('$(ILLinkSuppressionsConfigurationSpecificXml)'))">false</EnableTrimAnalyzer>

<!-- if building a PDB, tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' and '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
<!-- tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == ''">true</ILLinkRewritePDBs>

<ILLinkResourcesSubstitutionIntermediatePath>$(IntermediateOutputPath)ILLink.Resources.Substitutions.xml</ILLinkResourcesSubstitutionIntermediatePath>
<GenerateResourcesSubstitutions Condition="'$(GenerateResourcesSubstitutions)' == '' and '$(StringResourcesPath)' != ''">true</GenerateResourcesSubstitutions>
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>

<DebugType>Portable</DebugType>
<DebugSymbols>true</DebugSymbols>

<OutputPath Condition="$(MSBuildProjectName.StartsWith('System.Private.'))">$(RuntimeBinDir)/aotsdk/</OutputPath>
<Configurations>Debug;Release;Checked</Configurations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ public static class PinnedAndUnpinnedLocalsToDecode
public static unsafe int DoSomething()
{
byte[] bytes = new byte[] { 1, 2, 3 };
Keep(ref bytes);
fixed (byte* bytePtr = bytes)
{
return *bytePtr;
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,18 @@ private static int MyOtherMethod(int x)
public static void MyOtherMethod(object arg)
{
int var1 = 2;
Keep(ref var1);

string var2 = "I am a string";
Keep(ref var2);

if (arg == null)
{
throw new ArgumentNullException("Input arg cannot be null.");
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
#pragma warning restore xUnit1013 // Public method should be marked as test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
{
Assert.Equal(typeof(Exception), ehc.CatchType);
Assert.Equal(19, ehc.HandlerLength);
Assert.Equal(70, ehc.HandlerOffset);
Assert.Equal(27, ehc.HandlerLength);
Assert.Equal(86, ehc.HandlerOffset);
Assert.Equal(61, ehc.TryLength);
Assert.Equal(9, ehc.TryOffset);
Assert.Equal(25, ehc.TryOffset);
return;
}
}
Expand All @@ -64,10 +64,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
{
Assert.Equal(typeof(Exception), ehc.CatchType);
Assert.Equal(14, ehc.HandlerLength);
Assert.Equal(58, ehc.HandlerOffset);
Assert.Equal(21, ehc.HandlerLength);
Assert.Equal(72, ehc.HandlerOffset);
Assert.Equal(50, ehc.TryLength);
Assert.Equal(8, ehc.TryOffset);
Assert.Equal(22, ehc.TryOffset);
return;
}
}
Expand All @@ -79,7 +79,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
private static void MethodBodyExample(object arg)
{
int var1 = 2;
Keep(ref var1);

string var2 = "I am a string";
Keep(ref var2);

try
{
Expand All @@ -94,13 +97,17 @@ private static void MethodBodyExample(object arg)
}
catch (Exception ex)
{
Keep(ref ex);
Console.WriteLine(ex.Message);
}
finally
{
var1 = 3;
var2 = "I am a new string!";
}

// Reference local variables to prevent them from being optimized out by Roslyn
static void Keep<T>(ref T value) { };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="InlineArrayInvalid.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Loader/classloader/RefFields/Validate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MonoAotIncompatible>true</MonoAotIncompatible>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="Validate.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="ManagedPointers.cs" />
Expand Down

0 comments on commit 6cfb742

Please sign in to comment.