Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ protected virtual bool ShouldMarkInterfaceImplementationList (TypeDefinition typ

// It's hard to know if a com or windows runtime interface will be needed from managed code alone,
// so as a precaution we will mark these interfaces once the type is instantiated
if (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime)
if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
return true;

return IsFullyPreserved (type);
Expand Down
8 changes: 8 additions & 0 deletions src/tools/illink/src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ protected int SetupContext (ILogger? customLogger = null)
context.SetCustomData (values[0], values[1]);
continue;

case "--keep-com-interfaces":
if (!GetBoolParam (token, l => context.KeepComInterfaces = l))
return -1;

continue;

case "--keep-compilers-resources":
if (!GetBoolParam (token, l => keepCompilersResources = l))
return -1;
Expand Down Expand Up @@ -1284,6 +1290,7 @@ protected virtual LinkContext GetDefaultContext (Pipeline pipeline, ILogger? log
return new LinkContext (pipeline, logger ?? new ConsoleLogger (), "output") {
TrimAction = AssemblyAction.Link,
DefaultAction = AssemblyAction.Link,
KeepComInterfaces = true,
};
}

Expand Down Expand Up @@ -1369,6 +1376,7 @@ static void Usage ()
Console.WriteLine (" sealer: Any method or type which does not have override is marked as sealed");
Console.WriteLine (" --explicit-reflection Adds to members never used through reflection DisablePrivateReflection attribute. Defaults to false");
Console.WriteLine (" --feature FEATURE VALUE Apply any optimizations defined when this feature setting is a constant known at link time");
Console.WriteLine (" --keep-com-interfaces Keep COM interfaces implemented by kept types. Defaults to true");
Console.WriteLine (" --keep-compilers-resources Keep assembly resources used for F# compilation resources. Defaults to false");
Console.WriteLine (" --keep-dep-attributes Keep attributes used for manual dependency tracking. Defaults to false");
Console.WriteLine (" --keep-metadata NAME Keep metadata which would otherwise be removed if not used");
Expand Down
2 changes: 2 additions & 0 deletions src/tools/illink/src/linker/Linker/LinkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public Pipeline Pipeline {

public bool LinkSymbols { get; set; }

public bool KeepComInterfaces { get; set; }

public bool KeepMembersForDebugger { get; set; } = true;

public bool IgnoreUnresolved { get; set; } = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Runtime.InteropServices;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType
{
/// <summary>
/// With --keep-com-interfaces false, we apply the unused interface rules also to com interfaces.
/// </summary>
[SetupLinkerArgument ("--keep-com-interfaces", "false")]
public class UnusedComInterfaceIsRemoved
{
public static void Main ()
{
var i = new A ();
i.Foo ();
}

interface IBar
{
void Bar ();
}

[Kept]
[KeptMember (".ctor()")]
class A : IBar
{
[Kept]
public void Foo ()
{
}

public void Bar ()
{
}
}
}
}