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

[mono][tests] Enable ILStrip after AOT compilation for library tests #88167

Merged
merged 17 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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/testing/tests.ioslike.targets
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<_ApplePropertyNames Include="UseConsoleUITemplate" />
<_ApplePropertyNames Include="UseRuntimeComponents" />
<_ApplePropertyNames Include="IncludesTestRunner" />
<_ApplePropertyNames Include="ShouldILStrip" />

<_ApplePropertiesToPass
Include="$(%(_ApplePropertyNames.Identity))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> 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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<TestRuntime>true</TestRuntime>
<!-- Some tests need types like System.Diagnostics.DebugProvider which are only exposed from System.Private.CoreLib -->
<CompileUsingReferenceAssemblies>false</CompileUsingReferenceAssemblies>
<!-- Active issue: https://github.com/dotnet/runtime/issues/87740 -->
<ShouldILStrip>false</ShouldILStrip>
</PropertyGroup>
<ItemGroup>
<DefaultReferenceExclusion Include="System.Collections" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reflection;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

#pragma warning disable 0219 // field is never used
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reflection;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

#pragma warning disable 0219 // field is never used
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
3 changes: 1 addition & 2 deletions src/mono/msbuild/apple/build/AppleBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
<UseMonoJustInterp Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' == 'true'">true</UseMonoJustInterp>

<StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''" >false</StripDebugSymbols>
<!-- Tracking issue: https://github.com/dotnet/runtime/issues/87740 -->
<!-- <ShouldILStrip Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' != 'true'">true</ShouldILStrip> -->

<!-- TODO: We currently do not support bundling a static iOS-library with NativeAOT -->
<_IsLibraryMode Condition="('$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != '') or ('$(UseNativeAOTRuntime)' == 'true' and '$(NativeLib)' == 'Shared')">true</_IsLibraryMode>
<ShouldILStrip Condition="'$(ShouldILStrip)' == '' and '$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' != 'true' and '$(_IsLibraryMode)' != 'true'">true</ShouldILStrip>

<_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' == 'true'">_AppleNativeAotCompile</_AotCompileTargetName>
<_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_AppleAotCompile</_AotCompileTargetName>
Expand Down
Loading