Skip to content

Commit

Permalink
Add custom logic for reflection-emit to RemoveFeaturesStep. (dotnet/l…
Browse files Browse the repository at this point in the history
…inker#590)

* Add custom logic for reflection-emit to RemoveFeaturesStep.

When `--exclude-feature sre` is provided, then we rewrite the
`System.RuntimeType.MakeTypeBuilderInstantiation` to throw.

* Address cosmetic feedback.


Commit migrated from dotnet/linker@a59f4b3
  • Loading branch information
Martin Baulig authored and akoeplinger committed May 29, 2019
1 parent 7007772 commit a463dab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tools/illink/src/linker/Linker.Steps/RemoveFeaturesStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class RemoveFeaturesStep : BaseStep

public bool FeatureCOM { get; set; }
public bool FeatureETW { get; set; }
public bool FeatureSRE { get; set; }

//
// Manually overrides System.Globalization.Invariant mode
Expand Down Expand Up @@ -57,6 +58,17 @@ void ProcessType (TypeDefinition type)
ExcludeEventSourceImplementation (type);
}

if (FeatureSRE) {
if (type.Namespace == "System" && type.Name == "RuntimeType") {
foreach (var method in type.Methods) {
if (method.Name == "MakeTypeBuilderInstantiation") {
Annotations.SetAction (method, MethodAction.ConvertToThrow);
break;
}
}
}
}

if (RemoveCustomAttributes (type)) {
if (FeatureCOM && type.IsImport) {
type.IsImport = false;
Expand Down
1 change: 1 addition & 0 deletions src/tools/illink/src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public void Run (ILogger customLogger = null)
p.AddStepBefore (typeof (MarkStep), new RemoveFeaturesStep () {
FeatureCOM = excluded_features.Contains ("com"),
FeatureETW = excluded_features.Contains ("etw"),
FeatureSRE = excluded_features.Contains ("sre"),
FeatureGlobalization = excluded_features.Contains ("globalization")
});

Expand Down

0 comments on commit a463dab

Please sign in to comment.