From 153a94b88d77cfe133682e05191bc41914af6b21 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 21 May 2024 08:15:28 -0700 Subject: [PATCH] Delete DebugSymbols=true setting for the repo build (#102392) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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ý --------- Co-authored-by: Michal Strehovský --- Directory.Build.props | 1 - eng/illink.targets | 4 ++-- src/coreclr/nativeaot/Directory.Build.props | 1 - .../Decoding/SignatureDecoderTests.cs | 4 ++++ .../System/Reflection/MethodBaseTests.cs | 6 ++++++ .../System/Reflection/MethodBodyTests.cs | 19 +++++++++++++------ .../InlineArray/InlineArrayInvalid.csproj | 2 ++ .../classloader/RefFields/Validate.csproj | 2 ++ .../InvalidOperations.csproj | 2 ++ 9 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b374f83f816ea2..4107aab1da0830 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -390,7 +390,6 @@ $(NoWarn),CS8969 portable - true true false diff --git a/eng/illink.targets b/eng/illink.targets index 0dca1cd421991a..962e6f49ceb786 100644 --- a/eng/illink.targets +++ b/eng/illink.targets @@ -33,8 +33,8 @@ false - - true + + true $(IntermediateOutputPath)ILLink.Resources.Substitutions.xml true diff --git a/src/coreclr/nativeaot/Directory.Build.props b/src/coreclr/nativeaot/Directory.Build.props index d3277aa58ece73..b06c29baeb43e6 100644 --- a/src/coreclr/nativeaot/Directory.Build.props +++ b/src/coreclr/nativeaot/Directory.Build.props @@ -13,7 +13,6 @@ $(NetCoreAppCurrent) Portable - true $(RuntimeBinDir)/aotsdk/ Debug;Release;Checked diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs index 7570404923a7ab..bcb6661e6ef2c5 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs @@ -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(ref T value) { }; } } diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs index eeda2341e251dd..9d69ce855c6a41 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs @@ -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(ref T value) { }; } #pragma warning restore xUnit1013 // Public method should be marked as test diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs index 146baf023bbfe0..eb6f4b36fab9d5 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs @@ -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; } } @@ -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; } } @@ -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 { @@ -94,6 +97,7 @@ private static void MethodBodyExample(object arg) } catch (Exception ex) { + Keep(ref ex); Console.WriteLine(ex.Message); } finally @@ -101,6 +105,9 @@ private static void MethodBodyExample(object arg) var1 = 3; var2 = "I am a new string!"; } + + // Reference local variables to prevent them from being optimized out by Roslyn + static void Keep(ref T value) { }; } } } diff --git a/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj b/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj index 8323d950dff730..098ebbb26a691a 100644 --- a/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj +++ b/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj @@ -3,6 +3,8 @@ true true + + false diff --git a/src/tests/Loader/classloader/RefFields/Validate.csproj b/src/tests/Loader/classloader/RefFields/Validate.csproj index f8e94ce317a33f..8d5547ca7cf099 100644 --- a/src/tests/Loader/classloader/RefFields/Validate.csproj +++ b/src/tests/Loader/classloader/RefFields/Validate.csproj @@ -4,6 +4,8 @@ true true true + + false diff --git a/src/tests/baseservices/invalid_operations/InvalidOperations.csproj b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj index 5f4c03e91ae11a..1c5f1bf8001393 100644 --- a/src/tests/baseservices/invalid_operations/InvalidOperations.csproj +++ b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj @@ -3,6 +3,8 @@ true true + + false