Imported Upstream version 5.14.0.78

Former-commit-id: 3494343bcc9ddb42b36b82dd9ae7b69e85e0229f
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-05-10 08:37:03 +00:00
parent 74b74abd9f
commit 19234507ba
1776 changed files with 67755 additions and 31107 deletions

View File

@@ -39,15 +39,10 @@ namespace Mono.Linker.Steps {
public class BlacklistStep : BaseStep {
protected override bool ConditionToProcess()
{
return Context.CoreAction == AssemblyAction.Link;
}
protected override void Process ()
{
foreach (string name in Assembly.GetExecutingAssembly ().GetManifestResourceNames ()) {
if (!name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase) || !IsReferenced (GetAssemblyName (name)))
if (!name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase) || !ShouldProcessAssemblyResource (GetAssemblyName (name)))
continue;
try {
@@ -64,7 +59,7 @@ namespace Mono.Linker.Steps {
.SelectMany (mod => mod.Resources)
.Where (res => res.ResourceType == ResourceType.Embedded)
.Where (res => res.Name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase))
.Where (res => IsReferenced (GetAssemblyName (res.Name)))
.Where (res => ShouldProcessAssemblyResource (GetAssemblyName (res.Name)))
.Cast<EmbeddedResource> ()) {
try {
Context.LogMessage ("Processing embedded resource linker descriptor: {0}", rsc.Name);
@@ -87,13 +82,30 @@ namespace Mono.Linker.Steps {
return descriptor.Substring (0, pos);
}
bool IsReferenced (string name)
bool ShouldProcessAssemblyResource (string name)
{
AssemblyDefinition assembly = GetAssemblyIfReferenced (name);
if (assembly == null)
return false;
switch (Annotations.GetAction (assembly)) {
case AssemblyAction.Link:
case AssemblyAction.AddBypassNGen:
case AssemblyAction.AddBypassNGenUsed:
return true;
default:
return false;
}
}
AssemblyDefinition GetAssemblyIfReferenced (string name)
{
foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
if (assembly.Name.Name == name)
return true;
return assembly;
return false;
return null;
}
protected virtual IStep GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)

View File

@@ -308,8 +308,18 @@ namespace Mono.Linker.Steps {
protected virtual bool ShouldMarkCustomAttribute (CustomAttribute ca)
{
if (_context.KeepUsedAttributeTypesOnly && !Annotations.IsMarked (ca.AttributeType.Resolve ()))
return false;
if (_context.KeepUsedAttributeTypesOnly) {
switch (ca.AttributeType.FullName) {
// [ThreadStatic] and [ContextStatic] are required by the runtime
case "System.ThreadStaticAttribute":
case "System.ContextStaticAttribute":
return true;
}
if (!Annotations.IsMarked (ca.AttributeType.Resolve ()))
return false;
}
return true;
}

View File

@@ -87,12 +87,6 @@ namespace Mono.Linker.Steps {
OutputAssembly (assembly);
}
static bool IsReadyToRun (ModuleDefinition module)
{
return (module.Attributes & ModuleAttributes.ILOnly) == 0 &&
(module.Attributes & (ModuleAttributes) 0x04) != 0;
}
protected void WriteAssembly (AssemblyDefinition assembly, string directory)
{
WriteAssembly (assembly, directory, SaveSymbols (assembly));
@@ -101,10 +95,10 @@ namespace Mono.Linker.Steps {
protected virtual void WriteAssembly (AssemblyDefinition assembly, string directory, WriterParameters writerParameters)
{
foreach (var module in assembly.Modules) {
// Write back pure IL even for R2R assemblies
if (IsReadyToRun (module)) {
// Write back pure IL even for crossgen-ed assemblies
if (module.IsCrossgened ()) {
module.Attributes |= ModuleAttributes.ILOnly;
module.Attributes ^= (ModuleAttributes) (uint) 0x04;
module.Attributes ^= ModuleAttributes.ILLibrary;
module.Architecture = CalculateArchitecture (module.Architecture);
}
}
@@ -168,11 +162,9 @@ namespace Mono.Linker.Steps {
if (!assembly.MainModule.HasSymbols)
return parameters;
#if NATIVE_READER_SUPPORT
// NativePdb's can't be written on non-windows platforms
if (Environment.OSVersion.Platform != PlatformID.Win32NT && assembly.MainModule.SymbolReader is Mono.Cecil.Pdb.NativePdbReader)
// Use a string check to avoid a hard dependency on Mono.Cecil.Pdb
if (Environment.OSVersion.Platform != PlatformID.Win32NT && assembly.MainModule.SymbolReader.GetType ().FullName == "Mono.Cecil.Pdb.NativePdbReader")
return parameters;
#endif
if (Context.SymbolWriterProvider != null)
parameters.SymbolWriterProvider = Context.SymbolWriterProvider;

View File

@@ -93,7 +93,7 @@ namespace Mono.Linker.Steps {
try {
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
if (!string.IsNullOrEmpty (_resourceName))
if (!string.IsNullOrEmpty (_resourceName) && Context.StripResources)
Context.Annotations.AddResourceToRemove (_resourceAssembly, _resourceName);
} catch (Exception ex) when (!(ex is XmlResolutionException)) {
throw new XmlResolutionException (string.Format ("Failed to process XML description: {0}", _xmlDocumentLocation), ex);

View File

@@ -0,0 +1,16 @@
using System;
using Mono.Cecil;
namespace Mono.Linker {
public static class AssemblyUtilities {
public static bool IsCrossgened (this ModuleDefinition module)
{
return (module.Attributes & ModuleAttributes.ILOnly) == 0 &&
(module.Attributes & ModuleAttributes.ILLibrary) != 0;
}
}
}

View File

@@ -143,6 +143,11 @@ namespace Mono.Linker {
continue;
}
if (token == "--strip-resources") {
context.StripResources = bool.Parse (GetParam ());
continue;
}
switch (token [2]) {
case 'v':
Version ();
@@ -316,6 +321,7 @@ namespace Mono.Linker {
return assemblies;
}
AssemblyAction ParseAssemblyAction (string s)
{
var assemblyAction = (AssemblyAction)Enum.Parse(typeof(AssemblyAction), s, true);
@@ -362,6 +368,7 @@ namespace Mono.Linker {
Console.WriteLine (" --reduced-tracing Reduces dependency output related to assemblies that will not be modified");
Console.WriteLine (" --used-attrs-only Attributes on types, methods, etc will be removed if the attribute type is not used");
Console.WriteLine (" --strip-security In linked assemblies, attributes on assemblies, types, and methods related to security will be removed");
Console.WriteLine (" --strip-resources Remove link xml resources that were processed (true or false), default to true");
Console.WriteLine (" -out Specify the output directory, default to `output'");
Console.WriteLine (" -c Action on the core assemblies, skip, copy, copyused, addbypassngen, addbypassngenused or link, default to skip");
Console.WriteLine (" -u Action on the user assemblies, skip, copy, copyused, addbypassngen, addbypassngenused or link, default to link");

View File

@@ -111,6 +111,8 @@ namespace Mono.Linker {
public bool KeepUsedAttributeTypesOnly { get; set; }
public bool StripResources { get; set; }
public System.Collections.IDictionary Actions {
get { return _actions; }
}
@@ -171,6 +173,7 @@ namespace Mono.Linker {
_annotations = factory.CreateAnnotationStore (this);
MarkingHelpers = factory.CreateMarkingHelpers (this);
Tracer = factory.CreateTracer (this);
StripResources = true;
}
public TypeDefinition GetType (string fullName)

View File

@@ -33,7 +33,7 @@
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NATIVE_READER_SUPPORT</DefineConstants>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -41,7 +41,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NATIVE_READER_SUPPORT</DefineConstants>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -81,6 +81,7 @@
<Compile Include="Linker\AssemblyAction.cs" />
<Compile Include="Linker\AssemblyInfo.cs" />
<Compile Include="Linker\AssemblyResolver.cs" />
<Compile Include="Linker\AssemblyUtilities.cs" />
<Compile Include="Linker\DirectoryAssemblyResolver.cs" />
<Compile Include="Linker\Driver.cs" />
<Compile Include="Linker\LinkContext.cs" />

View File

@@ -48,11 +48,16 @@ the info file.
You can specify what the linker should do exactly per assembly.
The linker can do 3 things:
The linker can do the following things:
- skip them, and do nothing with them,
- copy them to the output directory,
- link them, to reduce their size.
- Skip: skip them, and do nothing with them,
- Copy: copy them to the output directory,
- CopyUsed: copy used assemblies to the output directory,
- Link: link them, to reduce their size,
- Delete: remove them from the output,
- Save: save them in memory without linking
- AddBypassNGen: add BypassNGenAttribute to unmarked methods,
- AddBypassNgenUsed: add BypassNGenAttribute to unmarked methods in used assemblies.
You can specify an action per assembly like this: