diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index d4dfbe3ebe1e4..50f89bfef82a4 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -125,6 +125,7 @@ <_ApplePropertyNames Include="UseConsoleUITemplate" /> <_ApplePropertyNames Include="UseRuntimeComponents" /> <_ApplePropertyNames Include="IncludesTestRunner" /> + <_ApplePropertyNames Include="ShouldILStrip" /> <_ApplePropertiesToPass Include="$(%(_ApplePropertyNames.Identity))" 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 616045dd05cad..e11c3e32445a4 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs @@ -258,14 +258,17 @@ public void PinnedAndUnpinnedLocals() Assert.Equal("DoSomething", reader.GetString(methodDef.Name)); MethodBodyBlock body = peReader.GetMethodBody(methodDef.RelativeVirtualAddress); - StandaloneSignature localSignature = reader.GetStandaloneSignature(body.LocalSignature); - - ImmutableArray localTypes = localSignature.DecodeLocalSignature(provider, genericContext: null); - - // Compiler can generate temporaries or re-order so just check the ones we expect are there. - // (They could get optimized away too. If that happens in practice, change this test to use hard-coded signatures.) - Assert.Contains("uint8[] pinned", localTypes); - Assert.Contains("uint8[]", localTypes); + var il = body.GetILBytes(); + // ILStrip replaces method body with the 'ret' IL opcode i.e. 0x2a + if (!(il?.Length == 1 && il[0] == 0x2a)) { + StandaloneSignature localSignature = reader.GetStandaloneSignature(body.LocalSignature); + ImmutableArray localTypes = localSignature.DecodeLocalSignature(provider, genericContext: null); + + // Compiler can generate temporaries or re-order so just check the ones we expect are there. + // (They could get optimized away too. If that happens in practice, change this test to use hard-coded signatures.) + Assert.Contains("uint8[] pinned", localTypes); + Assert.Contains("uint8[]", localTypes); + } } } diff --git a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Constructor/ConstructorTests.cs b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Constructor/ConstructorTests.cs index 90e4595f9ac00..a87a1d0b001cf 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Constructor/ConstructorTests.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Constructor/ConstructorTests.cs @@ -31,7 +31,15 @@ private static void TestConstructors1Worker(Type t) Assert.False(c.IsConstructedGenericMethod()); Assert.False(c.IsGenericMethod); Assert.Equal(MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, c.Attributes); - Assert.Equal(MethodImplAttributes.IL, c.MethodImplementationFlags); + if (c.MethodImplementationFlags.HasFlag(MethodImplAttributes.NoInlining)) + { + // when the assembly was processed with ILStrip, the NoInlining flag is set + Assert.Equal(MethodImplAttributes.IL | MethodImplAttributes.NoInlining, c.MethodImplementationFlags); + } + else + { + Assert.Equal(MethodImplAttributes.IL, c.MethodImplementationFlags); + } Assert.Equal(CallingConventions.Standard | CallingConventions.HasThis, c.CallingConvention); ParameterInfo[] ps = c.GetParameters(); diff --git a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Method/MethodTests.cs b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Method/MethodTests.cs index 6f0f25ae95a63..de598a64e3c01 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Method/MethodTests.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Method/MethodTests.cs @@ -30,7 +30,15 @@ private static void TestMethods1Worker(Type t) Assert.False(m.IsConstructedGenericMethod()); Assert.False(m.IsGenericMethod); Assert.Equal(MethodAttributes.Public | MethodAttributes.HideBySig, m.Attributes); - Assert.Equal(MethodImplAttributes.IL, m.MethodImplementationFlags); + if (m.MethodImplementationFlags.HasFlag(MethodImplAttributes.NoInlining)) + { + // when the assembly was processed with ILStrip, the NoInlining flag is set + Assert.Equal(MethodImplAttributes.IL | MethodImplAttributes.NoInlining, m.MethodImplementationFlags); + } + else + { + Assert.Equal(MethodImplAttributes.IL, m.MethodImplementationFlags); + } Assert.Equal(CallingConventions.Standard | CallingConventions.HasThis, m.CallingConvention); Type theT = t.GetGenericArguments()[0]; diff --git a/src/libraries/System.Runtime/tests/System.Diagnostics.Debug.Tests/System.Diagnostics.Debug.Tests.csproj b/src/libraries/System.Runtime/tests/System.Diagnostics.Debug.Tests/System.Diagnostics.Debug.Tests.csproj index f6e9e497eca39..f27284e29a907 100644 --- a/src/libraries/System.Runtime/tests/System.Diagnostics.Debug.Tests/System.Diagnostics.Debug.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Diagnostics.Debug.Tests/System.Diagnostics.Debug.Tests.csproj @@ -5,6 +5,8 @@ true false + + false 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 f10dc27b86b80..eeda2341e251d 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 @@ -3,6 +3,7 @@ using System; using System.Reflection; +using Microsoft.DotNet.XUnitExtensions; using Xunit; #pragma warning disable 0219 // field is never used @@ -55,6 +56,9 @@ public static void TestMethodBody() { MethodBase mbase = typeof(MethodBaseTests).GetMethod("MyOtherMethod", BindingFlags.Static | BindingFlags.Public); MethodBody mb = mbase.GetMethodBody(); + var il = mb.GetILAsByteArray(); + if (il?.Length == 1 && il[0] == 0x2a) // ILStrip replaces method bodies with the 'ret' IL opcode i.e. 0x2a + throw new SkipTestException("The method body was processed using ILStrip."); var codeSize = mb.GetILAsByteArray().Length; Assert.True(mb.InitLocals); // local variables are initialized 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 7da93ac022aff..146baf023bbfe 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 @@ -3,6 +3,7 @@ using System; using System.Reflection; +using Microsoft.DotNet.XUnitExtensions; using Xunit; #pragma warning disable 0219 // field is never used @@ -17,6 +18,10 @@ public static void Test_MethodBody_ExceptionHandlingClause() MethodInfo mi = typeof(MethodBodyTests).GetMethod("MethodBodyExample", BindingFlags.NonPublic | BindingFlags.Static); MethodBody mb = mi.GetMethodBody(); + var il = mb.GetILAsByteArray(); + if (il?.Length == 1 && il[0] == 0x2a) // ILStrip replaces method bodies with the 'ret' IL opcode i.e. 0x2a + throw new SkipTestException("The method body was processed using ILStrip."); + Assert.True(mb.InitLocals); // local variables are initialized #if DEBUG Assert.Equal(2, mb.MaxStackSize); diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/MethodImplAttributeTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/MethodImplAttributeTests.cs index 9f3ecf21fe0cc..e5920b896e6f1 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/MethodImplAttributeTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/MethodImplAttributeTests.cs @@ -13,8 +13,17 @@ public static class MethodImplAttributeTests public static void AggressiveOptimizationTest() { MethodImplAttributes implAttributes = MethodBase.GetCurrentMethod().MethodImplementationFlags; - Assert.Equal(MethodImplAttributes.AggressiveOptimization, implAttributes); - Assert.Equal(MethodImplOptions.AggressiveOptimization, (MethodImplOptions)implAttributes); + if (implAttributes.HasFlag(MethodImplAttributes.NoInlining)) + { + // when the assembly was processed with ILStrip, the NoInlining flag is set + Assert.Equal(MethodImplAttributes.AggressiveOptimization | MethodImplAttributes.NoInlining, implAttributes); + Assert.Equal(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining, (MethodImplOptions)implAttributes); + } + else + { + Assert.Equal(MethodImplAttributes.AggressiveOptimization, implAttributes); + Assert.Equal(MethodImplOptions.AggressiveOptimization, (MethodImplOptions)implAttributes); + } } } } diff --git a/src/mono/msbuild/apple/build/AppleBuild.props b/src/mono/msbuild/apple/build/AppleBuild.props index b910c6c395728..22984e921c968 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.props +++ b/src/mono/msbuild/apple/build/AppleBuild.props @@ -16,11 +16,10 @@ true false - - <_IsLibraryMode Condition="('$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != '') or ('$(UseNativeAOTRuntime)' == 'true' and '$(NativeLib)' == 'Shared')">true + true <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' == 'true'">_AppleNativeAotCompile <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_AppleAotCompile