Skip to content

Commit

Permalink
Add custom logic for reflection-emit to RemoveFeaturesStep. (dotnet#590)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Martin Baulig committed May 29, 2019
1 parent 4507ce9 commit a8630dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 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/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,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 a8630dc

Please sign in to comment.