From f8f41b883eccf0d3b099bbfa0f1773e98ac6a7e9 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sun, 18 Jan 2026 17:49:30 +0100 Subject: [PATCH 1/6] pnse --- docs/tools/illink/data-formats.md | 15 +++ .../TypeSystemProxy/WellKnownType.cs | 4 +- .../build/Microsoft.NET.ILLink.targets | 4 + .../Linker.Steps/BodySubstitutionParser.cs | 3 + .../Linker.Steps/CheckSuppressionsStep.cs | 3 +- .../linker/Linker.Steps/CodeRewriterStep.cs | 38 +++++++ .../src/linker/Linker.Steps/MarkStep.cs | 101 ++++++++++++++++++ src/tools/illink/src/linker/Linker/Driver.cs | 9 ++ .../illink/src/linker/Linker/KnownMembers.cs | 12 +++ .../illink/src/linker/Linker/LinkContext.cs | 2 + .../illink/src/linker/Linker/MethodAction.cs | 1 + .../SubstitutionsTests.g.cs | 6 ++ .../UnsupportedOSPlatformSubstitution.cs | 97 +++++++++++++++++ 13 files changed, 293 insertions(+), 2 deletions(-) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Substitutions/UnsupportedOSPlatformSubstitution.cs diff --git a/docs/tools/illink/data-formats.md b/docs/tools/illink/data-formats.md index 06490e3e3308d9..7756d91728c440 100644 --- a/docs/tools/illink/data-formats.md +++ b/docs/tools/illink/data-formats.md @@ -253,6 +253,21 @@ Entire method body is replaces with `throw` instruction when method is reference ``` +### Throw PlatformNotSupportedException + + +Entire method body is replaces with `throw new PlatformNotSupportedException()` instruction when method is referenced. + +```xml + + + + + + + +``` + ### Remove embedded resources ```xml diff --git a/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs b/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs index 9b4d435f9d5731..fe761179c4204e 100644 --- a/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs +++ b/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs @@ -19,6 +19,7 @@ public enum WellKnownType System_Object, System_Attribute, System_NotSupportedException, + System_PlatformNotSupportedException, System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, System_Void } @@ -37,6 +38,7 @@ public static (string Namespace, string Name) GetNamespaceAndName(this WellKnown WellKnownType.System_Object => ("System", "Object"), WellKnownType.System_Attribute => ("System", "Attribute"), WellKnownType.System_NotSupportedException => ("System", "NotSupportedException"), + WellKnownType.System_PlatformNotSupportedException => ("System", "PlatformNotSupportedException"), WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute => ("System.Runtime.CompilerServices", "DisablePrivateReflectionAttribute"), WellKnownType.System_Void => ("System", "Void"), _ => throw new System.ArgumentException(type.ToString()) @@ -56,7 +58,7 @@ public static (string Namespace, string Name) GetNamespaceAndName(this WellKnown "Array" => WellKnownType.System_Array, "Attribute" => WellKnownType.System_Attribute, "Object" => WellKnownType.System_Object, - "NotSupportedException" => WellKnownType.System_NotSupportedException, + "PlatformNotSupportedException" => WellKnownType.System_PlatformNotSupportedException, "Void" => WellKnownType.System_Void, _ => null }, diff --git a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index 16198390f88f7b..7c7bb02e9660ec 100644 --- a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -90,6 +90,10 @@ Copyright (c) .NET Foundation. All rights reserved. $(NoWarn);IL2121 + + <_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --target-os browser + + $(SharedFrameworkILLinkArgs) -b true $(SharedFrameworkILLinkArgs) --link-attributes "@(SharedFrameworkSuppressionsXml, '" --link-attributes "')" + $(SharedFrameworkILLinkArgs) --target-os browser From bf27e486b3c20b394b5e46d2913f16550c5bfc32 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sun, 18 Jan 2026 18:03:51 +0100 Subject: [PATCH 3/6] more --- src/libraries/System.Threading/src/System.Threading.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Threading/src/System.Threading.csproj b/src/libraries/System.Threading/src/System.Threading.csproj index e09ac58c61c410..613c3a16dace2a 100644 --- a/src/libraries/System.Threading/src/System.Threading.csproj +++ b/src/libraries/System.Threading/src/System.Threading.csproj @@ -8,6 +8,7 @@ false true $(DefineConstants);FEATURE_WASM_MANAGED_THREADS + <_ExtraTrimmerArgs Condition="'$(TargetsBrowser)' == 'true'">$(_ExtraTrimmerArgs) --target-os browser From 61c360922b14a043e87b9ee0ebaa72afdee187b6 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sun, 18 Jan 2026 18:48:01 +0100 Subject: [PATCH 4/6] fix --- src/tools/illink/src/linker/CompatibilitySuppressions.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/illink/src/linker/CompatibilitySuppressions.xml b/src/tools/illink/src/linker/CompatibilitySuppressions.xml index 1834d95fe9f446..c31a9fbee52c43 100644 --- a/src/tools/illink/src/linker/CompatibilitySuppressions.xml +++ b/src/tools/illink/src/linker/CompatibilitySuppressions.xml @@ -989,6 +989,10 @@ CP0002 M:Mono.Linker.LinkContext.get_IgnoreLinkAttributes + + CP0002 + M:Mono.Linker.LinkContext.get_TargetOS + CP0002 M:Mono.Linker.LinkContext.get_IgnoreSubstitutions @@ -1301,6 +1305,10 @@ CP0002 M:Mono.Linker.LinkContext.set_IgnoreLinkAttributes(System.Boolean) + + CP0002 + M:Mono.Linker.LinkContext.set_TargetOS(System.String) + CP0002 M:Mono.Linker.LinkContext.set_IgnoreSubstitutions(System.Boolean) From c1f22e1baddeb4c99517eed88dbfd4d7147e09c4 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 19 Jan 2026 11:59:05 +0100 Subject: [PATCH 5/6] fix --- src/tools/illink/src/linker/CompatibilitySuppressions.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/illink/src/linker/CompatibilitySuppressions.xml b/src/tools/illink/src/linker/CompatibilitySuppressions.xml index c31a9fbee52c43..b59f80794022ce 100644 --- a/src/tools/illink/src/linker/CompatibilitySuppressions.xml +++ b/src/tools/illink/src/linker/CompatibilitySuppressions.xml @@ -637,6 +637,10 @@ CP0002 F:Mono.Linker.LinkContext.PInvokesListFile + + CP0002 + F:Mono.Linker.MethodAction.ConvertToPNSE + CP0002 F:Mono.Linker.MessageCategory.WarningAsError From 423d3ad783c8b9d7d4c239ccc0bcbb854edbd2d2 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Tue, 20 Jan 2026 20:12:34 +0100 Subject: [PATCH 6/6] Update src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs b/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs index fe761179c4204e..ab8b19d3d74247 100644 --- a/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs +++ b/src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs @@ -58,6 +58,7 @@ public static (string Namespace, string Name) GetNamespaceAndName(this WellKnown "Array" => WellKnownType.System_Array, "Attribute" => WellKnownType.System_Attribute, "Object" => WellKnownType.System_Object, + "NotSupportedException" => WellKnownType.System_NotSupportedException, "PlatformNotSupportedException" => WellKnownType.System_PlatformNotSupportedException, "Void" => WellKnownType.System_Void, _ => null