From a2d3ab7701bf523a1f9618169504879e1e16c0d6 Mon Sep 17 00:00:00 2001 From: Michael Voorhees Date: Wed, 19 Mar 2025 14:27:22 -0400 Subject: [PATCH 1/3] ILLink: Stop giving special treatment to icalls As discussed https://github.com/dotnet/runtime/pull/113437#issuecomment-2722824229 --- .../src/linker/Linker.Steps/MarkStep.cs | 2 +- .../InternalCalls/InternalCallsTests.cs | 6 ++++ ...aultConstructorOfReturnTypeIsNotRemoved.cs | 25 ------------- .../Interop/InternalCalls/NoSpecialMarking.cs | 36 +++++++++++++++++++ .../UnusedDefaultConstructorIsRemoved.cs | 30 ---------------- ...onstructorOfTypePassedByRefIsNotRemoved.cs | 31 ---------------- .../UnusedFieldsOfTypesAreNotRemoved.cs | 26 -------------- ...edFieldsOfTypesPassedByRefAreNotRemoved.cs | 26 -------------- ...edFieldsOfTypesWhenHasThisAreNotRemoved.cs | 24 ------------- 9 files changed, 43 insertions(+), 163 deletions(-) delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/NoSpecialMarking.cs delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs delete mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 885f0039928ec7..ec147a7805142f 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -3149,7 +3149,7 @@ protected virtual void ProcessMethod (MethodDefinition method, in DependencyInfo MarkCustomAttributes (method.MethodReturnType, new DependencyInfo (DependencyKind.ReturnTypeAttribute, method), methodOrigin); MarkMarshalSpec (method.MethodReturnType, new DependencyInfo (DependencyKind.ReturnTypeMarshalSpec, method), methodOrigin); - if (method.IsPInvokeImpl || method.IsInternalCall) { + if (method.IsPInvokeImpl) { ProcessInteropMethod (method, methodOrigin); } diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/Interop/InternalCalls/InternalCallsTests.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/Interop/InternalCalls/InternalCallsTests.cs index 5f00820c525c16..069ec9217b3dc0 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/Interop/InternalCalls/InternalCallsTests.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/Interop/InternalCalls/InternalCallsTests.cs @@ -45,5 +45,11 @@ public Task UnusedFieldsOfTypesPassedByRefAreNotRemoved () { return RunTest (); } + + [Fact] + public Task NoSpecialMarking () + { + return RunTest (); + } } } \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs deleted file mode 100644 index fdf91dd9392b63..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class DefaultConstructorOfReturnTypeIsNotRemoved - { - public static void Main () - { - var a = SomeMethod (); - } - - class A - { - [Kept] - public A () - { - } - } - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - static extern A SomeMethod (); - } -} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/NoSpecialMarking.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/NoSpecialMarking.cs new file mode 100644 index 00000000000000..5a794f1e2ce35c --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/NoSpecialMarking.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls; + +public class NoSpecialMarking +{ + public static void Main () + { + A a = null; + SomeMethod (ref a, null, null); + } + + [Kept] + class A; + + [Kept] + class B; + + [Kept] + class C; + + [Kept] + class D + { + int field1; + int field2; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern C SomeMethod (ref A a, B b, D d); +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs deleted file mode 100644 index 089e594fa88f18..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class UnusedDefaultConstructorIsRemoved - { - public static void Main () - { - var a = new A (1); - SomeMethod (a); - } - - class A - { - public A () - { - } - - [Kept] - public A (int other) - { - } - } - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - static extern void SomeMethod (A a); - } -} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs deleted file mode 100644 index e4a5e66fffd278..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved - { - public static void Main () - { - var a = new A (1); - SomeMethod (ref a); - } - - class A - { - [Kept] - public A () - { - } - - [Kept] - public A (int other) - { - } - } - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - static extern void SomeMethod (ref A a); - } -} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs deleted file mode 100644 index eefdd22affbbfd..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class UnusedFieldsOfTypesAreNotRemoved - { - public static void Main () - { - var a = new A (); - SomeMethod (a); - } - - [KeptMember (".ctor()")] - class A - { - [Kept] private int field1; - - [Kept] private int field2; - } - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - static extern void SomeMethod (A a); - } -} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs deleted file mode 100644 index 7659a6486d624d..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class UnusedFieldsOfTypesPassedByRefAreNotRemoved - { - public static void Main () - { - var a = new A (); - SomeMethod (ref a); - } - - [KeptMember (".ctor()")] - class A - { - [Kept] private int field1; - - [Kept] private int field2; - } - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - static extern void SomeMethod (ref A a); - } -} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs deleted file mode 100644 index 78bf3a9da9c34a..00000000000000 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Runtime.CompilerServices; -using Mono.Linker.Tests.Cases.Expectations.Assertions; - -namespace Mono.Linker.Tests.Cases.Interop.InternalCalls -{ - class UnusedFieldsOfTypesWhenHasThisAreNotRemoved - { - public static void Main () - { - A a = new A (); - a.SomeMethod (); - } - - [KeptMember (".ctor()")] - class A - { - [Kept] private int field1; - - [Kept] - [MethodImpl (MethodImplOptions.InternalCall)] - public extern void SomeMethod (); - } - } -} \ No newline at end of file From e09d7663b921f80999716fe177b61d471681f56e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 20 Mar 2025 00:15:54 -0700 Subject: [PATCH 2/3] Add missing dependencies in corelib binder --- .../tools/aot/ILCompiler/ILCompiler_inbuild.csproj | 3 ++- src/coreclr/tools/aot/crossgen2/crossgen2_inbuild.csproj | 3 ++- src/coreclr/vm/corelib.h | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler_inbuild.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler_inbuild.csproj index d22aff2a1dea53..7884fc416bf93d 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler_inbuild.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler_inbuild.csproj @@ -5,7 +5,8 @@ $(NETCoreSdkRuntimeIdentifier) $(RuntimeBinDir)$(BuildArchitecture)/ilc/ true - true + + +