xamarin-macios/tools/linker
Rolf Bjarne Kvinge 37c11cf0a1
[tools] Don't require a LinkWith attributes to find Objective-C classes in assemblies. (#20479)
Stop requiring a LinkWith attribute in an assembly in order to keep any Objective-C
types within. There are many ways to include a native library in a build nowadays,
and more and more often they don't need any LinkWith attributes to specify custom
linker behavior (in particular for frameworks, which can typically be included as-is).
The result of not searching such assemblies for Objective-C types would be that the
native linker would strip them away, and that would mean incorrect behavior at runtime.

However, this is a rather invasive change, especially for a minor release, so I'm
adding two things to make it better:

1. An opt-out MSBuild property: `RequireLinkWithAttributeForObjectiveCClassSearch`.
   Set to 'true' to opt-out (default is 'false').

2. Improve handling of native symbols with regards to the native linker.

    Add a new item group, ReferenceNativeSymbol, that contains native symbols
    we handle in some way - either to be ignored or we ask the native linker
    to keep it (by passing it as '-u ...' or in a symbol list file).

    There are two supported types of metadata:

    * SymbolType: either 'ObjectiveCClass', 'Function' or 'Field'. Used to
      compute the complete native name of a symbol (for instance, the native
      symbol for the Objective-C class "MyClass" is `_OBJC_CLASS_$_MyClass`,
      while for a function "MyFunction" it's just `_MyFunction`.
    * SymbolMode: either 'Ignore' or 'Default'. "Ignore" means to not pass the given
      symbol to the native linker, the default is to do so.

    SymbolType is required, while SymbolMode isn't.

    Example symbol to keep:

    ```xml
    <ItemGroup>
        <ReferenceNativeSymbol Include="MyClass" SymbolType="ObjectiveCClass" />
    </ItemGroup>
    ```

    Example symbol to ignore:

    ```xml
    <ItemGroup>
        <ReferenceNativeSymbol Include="MyClass" SymbolType="ObjectiveCClass" SymbolMode="Ignore" />
    </ItemGroup>
    ```

Finally use the latter solution to work around an issue that arouse with monotouch-test:
we reference an Objective-C class that doesn't exist in monotouch-test. This worked
because the referencing assembly didn't have a LinkWith attribute (and thus the reference
was ignored), but now that the reference isn't ignored anymore, we need to explicitly
ignore the Objective-C class.
2024-05-01 08:31:47 +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 Build mmp. 2016-04-24 14:47:26 -04:00
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 [Policheck] Fix all policheck issues that are not part of the apple APIs. (#18544) 2023-07-10 14:38:21 -04: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 Build mmp. 2016-04-24 14:47:26 -04:00
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