Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Aug 11, 2023
1 parent 9417200 commit 69ec2d3
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 27 deletions.
3 changes: 3 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@
<!-- Enable serialization discovery. Ref: https://github.com/xamarin/xamarin-macios/issues/15676 -->
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --enable-serialization-discovery</_ExtraTrimmerArgs>

<!-- TODO: explanation -->
<_ExtraTrimmerArgs Condition="'$(_UseNativeAot)' == 'true'">$(_ExtraTrimmerArgs) --keep-dep-attributes</_ExtraTrimmerArgs>

<!-- We always want the linker to process debug symbols, even when building in Release mode, because the AOT compiler uses the managed debug symbols to output DWARF debugging symbols -->
<TrimmerRemoveSymbols Condition="'$(TrimmerRemoveSymbols)' == ''">false</TrimmerRemoveSymbols>

Expand Down
3 changes: 2 additions & 1 deletion tools/common/ErrorHelper.tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ static void ShowInner (Exception e)

if (Verbosity > 3) {
Console.Error.WriteLine ("--- inner exception");
Console.Error.WriteLine (ie);
Console.Error.WriteLine (ie.Message);
Console.Error.WriteLine (ie.StackTrace);
Console.Error.WriteLine ("---");
} else if (Verbosity > 0 || ie is ProductException) {
Console.Error.WriteLine ("\t{0}", ie.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>create_dotnet_linker_launch_json</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSBuild.StructuredLogger" Version="2.1.758" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.1.844" />
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
</ItemGroup>

Expand Down
59 changes: 59 additions & 0 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

using Mono.Cecil;
Expand Down Expand Up @@ -126,6 +127,10 @@ public MethodReference GetMethodReference (AssemblyDefinition assembly, TypeRefe
md.IsPublic = true;
SaveAssembly (md.Module.Assembly);
}

// Also mark it
// configuration.Context.Annotations.Mark (md);
// configuration.Context.Annotations.Mark (tuple.Item2);
}

method = tuple.Item1;
Expand Down Expand Up @@ -309,6 +314,12 @@ public TypeReference System_Diagnostics_CodeAnalysis_DynamicDependencyAttribute
}
}

public TypeReference System_Diagnostics_CodeAnalysis_DynamicallyAccessedMemberTypes {
get {
return GetTypeReference (CorlibAssembly, "System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes", out var _);
}
}

public TypeReference System_Reflection_MethodBase {
get {
return GetTypeReference (CorlibAssembly, "System.Reflection.MethodBase", out var _);
Expand Down Expand Up @@ -461,17 +472,41 @@ public MethodReference Dictionary2_Add {
}
}

public MethodReference DynamicDependencyAttribute_ctor__String {
get {
return GetMethodReference (CorlibAssembly,
System_Diagnostics_CodeAnalysis_DynamicDependencyAttribute,
".ctor",
".ctor(String)",
isStatic: false,
System_String);
}
}

public MethodReference DynamicDependencyAttribute_ctor__String_Type {
get {
return GetMethodReference (CorlibAssembly,
System_Diagnostics_CodeAnalysis_DynamicDependencyAttribute,
".ctor",
".ctor(String,Type)",
isStatic: false,
System_String,
System_Type);
}
}

public MethodReference DynamicDependencyAttribute_ctor__DynamicallyAccessedMemberTypes_Type {
get {
return GetMethodReference (CorlibAssembly,
System_Diagnostics_CodeAnalysis_DynamicDependencyAttribute,
".ctor",
".ctor(DynamicallyAccessedMemberTypes,Type)",
isStatic: false,
System_Diagnostics_CodeAnalysis_DynamicallyAccessedMemberTypes,
System_Type);
}
}

public MethodReference RuntimeTypeHandle_Equals {
get {
return GetMethodReference (CorlibAssembly, System_RuntimeTypeHandle, "Equals", isStatic: false, System_RuntimeTypeHandle);
Expand Down Expand Up @@ -1147,5 +1182,29 @@ public void ClearCurrentAssembly ()
method_map.Clear ();
field_map.Clear ();
}

public CustomAttribute CreateDynamicDependencyAttribute (string memberSignature)
{
var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__String);
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, memberSignature));
return attribute;
}

public CustomAttribute CreateDynamicDependencyAttribute (string memberSignature, TypeDefinition type)
{
var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__String_Type);
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, memberSignature));
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_Type, type));
return attribute;
}

public CustomAttribute CreateDynamicDependencyAttribute (DynamicallyAccessedMemberTypes memberTypes, TypeDefinition type)
{
var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__DynamicallyAccessedMemberTypes_Type);
// typed as 'int' because that's how the linker expects it: https://github.com/dotnet/runtime/blob/3c5ad6c677b4a3d12bc6a776d654558cca2c36a9/src/tools/illink/src/linker/Linker/DynamicDependency.cs#L97
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_Diagnostics_CodeAnalysis_DynamicallyAccessedMemberTypes, (int) memberTypes));
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_Type, type));
return attribute;
}
}
}
Loading

0 comments on commit 69ec2d3

Please sign in to comment.