xamarin-macios/tools/linker
Rolf Bjarne Kvinge ff707c145e
[dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012)
When we implemented support for using default interface members for binding protocols, we also unintentionally introduced a size regression. This happened because we now tell the linker to keep all methods in a protocol interface, thus all the corresponding types end up marked as well, etc.

This had an additional side effect: depending on the types that weren't linked away anymore, the App Store could flag an app, saying that additional entitlements is needed. This is what's happening in #21002: the App Store detects that the app references the `application:didRegisterForRemoteNotificationsWithDeviceToken:` selector [1] (from the method `RegisteredForRemoteNotifications` on `IUIApplicationDelegate`) and tells the developer they probably need the push notification entitlement.

The good news is that we don't need these protocol interface methods at runtime if the optimization to register protocols with the static registrar is enabled (which it is by default).

In this PR I teach the optimizer to remove the DynamicDependency attributes keeping these protocol interface methods from being trimmed out.

## Size improvements

* monotouch-test build for Release/ios-arm64 shrinks by [2.9mb (-2.6%)](https://gist.github.com/rolfbjarne/5e8ca6ea6854dc4a46f8e838dff11e6b)
* A very simple app (tests/dotnet/MySimpleApp) shrinks by [176kb (-0.3%)](https://gist.github.com/rolfbjarne/f0e062900528eb499fd96d124d18376f)

[1]: This is somewhat speculative, but it's probably not far from what the App Store actually does.

Fixes #21002.
2024-09-02 15:02:10 +02:00
..
MonoTouch.Tuner [tools] Don't require a LinkWith attributes to find Objective-C classes in assemblies. (#20479) 2024-05-01 08:31:47 +02:00
ApplyPreserveAttribute.cs [NativeAOT] Add support for [Preserve] attributes (#18666) 2023-08-18 16:49:47 +02:00
BaseProfile.cs [autoformat] Add mmp.csproj. (#16313) 2022-10-11 22:36:58 +02:00
ChangeLog
CoreHttpMessageHandler.cs [autoformat] Add mmp.csproj. (#16313) 2022-10-11 22:36:58 +02:00
CoreMarkStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
CoreOptimizeGeneratedCode.cs [dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012) 2024-09-02 15:02:10 +02:00
CorePreserveCode.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
CoreRemoveAttributes.cs [net8.0] Update dependencies from dotnet/installer (#17888) 2023-04-12 09:38:36 +02:00
CoreRemoveSecurity.cs [linker] Always create the CoreRemoveSecurity step, and instead detect if it should be active using the LinkContext field. 2020-05-07 15:51:38 +02:00
CoreSweepStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
CoreTypeMapStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
CustomSymbolWriter.cs Get Mono.Cecil from NuGet everywhere. (#19535) 2023-12-04 20:15:03 +01:00
ExceptionalSubStep.cs [autoformat] Add dotnet-linker to the projects to autoformat. (#16178) 2022-09-30 09:32:42 +02:00
MarkNSObjects.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
MobileApplyPreserveAttribute.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
MobileExtensions.cs [registrar] Add an HasCustomAttribute overload that returns the found attribute (if any) 2023-05-11 13:10:30 +02:00
MobileMarkStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
MobileProfile.cs [mtouch] Make 'MonoTouch.Dialog-1' and 'MonoTouch.NUnitLite' SDK assemblies, not product assemblies. Fixes #12862. (#12919) 2021-10-04 19:14:34 +02:00
MobileRemoveAttributes.cs [linker] Remove internal [NullablePublicOnly] attribute from apps (#8568) 2020-05-11 19:39:43 -04:00
MobileResolveMainAssemblyStep.cs [autoformat] Add mtouch.csproj. (#16316) 2022-10-13 10:42:41 +02:00
MobileSweepStep.cs [linker] Remove code to deal with ExportedTypes (#8632) 2020-05-21 08:44:48 -04:00
ObjCExtensions.cs [InputMethodKit] Remove existing code for InputMethodKit. (#19462) 2023-11-20 07:55:13 +01:00
README.linker
RegistrarRemovalTrackingStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
RemoveRejectedTypesStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
RemoveSelectors.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
RemoveUserResourcesSubStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
ScanTypeReferenceStep.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00

README.linker

README.linker

Q: Why some stuff is not linked out ?

A: In most case this is because:
	a) the BCL uses it internally
	b) the mono runtime depends on the type, methods, class layout


= mscorlib.dll =

System.Security.PermissionSet
	* Assembly has (3) fields of that type
	* mscorlib.xml preserve all fields from Assembly (object-internals.h)
	* code is "stubified" by the linker
System.Security.Policy.ApplicationTrust: 
	* Used as a field in AppDomainSetup;
	* Field also exists in unmanaged code (domain-internals.h);
	* mscorlib.xml preserve all fields from AppDomainSetup
	* only the default .ctor remains and is stubified by the linker
System.Security.Policy.Evidence
	* Used by AppDomain.Load[Assembly]
	* Used by Assembly.LoadWithPartialName overloads
	* code is "stubified" by the linker


= System.dll =

System.Text.RegularExpressions.*
	* Included because there is 2 regex in UriParser