Imported Upstream version 5.12.0.220

Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-04-24 09:31:23 +00:00
parent 8bd104cef2
commit 8fc30896db
1200 changed files with 29534 additions and 26161 deletions

View File

@@ -0,0 +1,37 @@
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace ILLink.Tasks
{
class AdapterLogger : Mono.Linker.ILogger
{
private TaskLoggingHelper log;
public AdapterLogger (TaskLoggingHelper log)
{
this.log = log;
}
public void LogMessage (Mono.Linker.MessageImportance importance, string message, params object[] values)
{
Microsoft.Build.Framework.MessageImportance msBuildImportance;
switch (importance)
{
case Mono.Linker.MessageImportance.High:
msBuildImportance = MessageImportance.High;
break;
case Mono.Linker.MessageImportance.Normal:
msBuildImportance = MessageImportance.Normal;
break;
case Mono.Linker.MessageImportance.Low:
msBuildImportance = MessageImportance.Low;
break;
default:
throw new ArgumentException ($"Unrecognized importance level {importance}", nameof(importance));
}
log.LogMessageFromText (String.Format (message, values), msBuildImportance);
}
}
}

View File

@@ -17,13 +17,13 @@ namespace ILLink.Tasks
/// dependencies.
/// </summary>
[Required]
public ITaskItem[] ManagedAssemblyPaths { get; set; }
public ITaskItem [] ManagedAssemblyPaths { get; set; }
/// <summary>
/// The set of native dependencies to keep even if they
/// aren't found to be referenced by a managed assembly..
/// aren't found to be referenced by a managed assembly.
/// </summary>
public ITaskItem[] NativeDepsToKeep { get; set; }
public ITaskItem [] NativeDepsToKeep { get; set; }
/// <summary>
/// The paths to the available native dependencies. We
@@ -31,7 +31,7 @@ namespace ILLink.Tasks
/// native files.
/// </summary>
[Required]
public ITaskItem[] NativeDepsPaths { get; set; }
public ITaskItem [] NativeDepsPaths { get; set; }
/// <summary>
/// The set of native dependencies to keep, including those
@@ -40,67 +40,51 @@ namespace ILLink.Tasks
/// input NativeDepsToKeep.
/// </summary>
[Output]
public ITaskItem[] KeptNativeDepsPaths { get; set; }
public ITaskItem [] KeptNativeDepsPaths { get; set; }
public override bool Execute()
public override bool Execute ()
{
var allNative = new Dictionary<string, ITaskItem> ();
foreach (var n in NativeDepsPaths)
{
var fileName = Path.GetFileName(n.ItemSpec);
if (!allNative.ContainsKey(fileName))
{
allNative.Add(fileName, n);
}
}
var keptNative = new List<ITaskItem> ();
var managedAssemblies = ManagedAssemblyPaths.Select (i => i.ItemSpec).ToArray();
foreach (string managedAssembly in managedAssemblies)
{
using (var peReader = new PEReader(new FileStream(managedAssembly, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
if (peReader.HasMetadata)
{
var reader = peReader.GetMetadataReader();
for (int i = 1, count = reader.GetTableRowCount(TableIndex.ModuleRef); i <= count; i++)
{
var moduleRef = reader.GetModuleReference(MetadataTokens.ModuleReferenceHandle(i));
var moduleName = reader.GetString(moduleRef.Name);
var allNativeNames = new HashSet<string> ();
foreach (var nativeDep in NativeDepsPaths)
allNativeNames.Add (Path.GetFileName (nativeDep.ItemSpec));
var keptNativeNames = new HashSet<string> ();
foreach (var nativeDep in NativeDepsToKeep)
keptNativeNames.Add (Path.GetFileName (nativeDep.ItemSpec));
var moduleRefCandidates = new[] { moduleName, moduleName + ".dll", moduleName + ".so", moduleName + ".dylib" };
var managedAssemblies = ManagedAssemblyPaths.Select (i => i.ItemSpec).ToArray ();
foreach (string managedAssembly in managedAssemblies) {
using (var peReader = new PEReader(new FileStream (managedAssembly, FileMode.Open, FileAccess.Read, FileShare.Read))) {
if (peReader.HasMetadata) {
var reader = peReader.GetMetadataReader ();
for (int i = 1, count = reader.GetTableRowCount (TableIndex.ModuleRef); i <= count; i++) {
var moduleRef = reader.GetModuleReference (MetadataTokens.ModuleReferenceHandle (i));
var moduleName = reader.GetString (moduleRef.Name);
ITaskItem referencedNativeFile = null;
foreach (string moduleRefCandidate in moduleRefCandidates)
{
if (allNative.TryGetValue (moduleRefCandidate, out referencedNativeFile))
{
break;
var moduleRefCandidates = new [] { moduleName, moduleName + ".dll", moduleName + ".so", moduleName + ".dylib" };
bool foundModuleRef = false;
foreach (string moduleRefCandidate in moduleRefCandidates) {
if (allNativeNames.Contains (moduleRefCandidate)) {
keptNativeNames.Add (moduleRefCandidate);
foundModuleRef = true;
}
}
if (referencedNativeFile != null)
{
keptNative.Add(referencedNativeFile);
}
else
{
// DLLImport that wasn't satisfied
Log.LogMessage(MessageImportance.High, "unsatisfied DLLImport: " + managedAssembly + " -> " + moduleName);
}
if (!foundModuleRef)
Log.LogMessage("unsatisfied DLLImport: " + managedAssembly + " -> " + moduleName);
}
}
}
}
foreach (var n in NativeDepsToKeep)
{
ITaskItem nativeFile = null;
if (allNative.TryGetValue (n.ItemSpec, out nativeFile))
{
keptNative.Add(nativeFile);
}
var keptNativeDeps = new List<ITaskItem> ();
foreach (var nativeDep in NativeDepsPaths) {
var fileName = Path.GetFileName (nativeDep.ItemSpec);
if (keptNativeNames.Contains (fileName))
keptNativeDeps.Add (nativeDep);
}
KeptNativeDepsPaths = keptNative.ToArray();
KeptNativeDepsPaths = keptNativeDeps.ToArray ();
return true;
}
}

View File

@@ -97,6 +97,7 @@
</Target>
<ItemGroup>
<Compile Include="AdapterLogger.cs" />
<Compile Include="LinkTask.cs" />
<Compile Include="CompareSizes.cs" />
<Compile Include="ComputeManagedAssemblies.cs" />
@@ -195,7 +196,7 @@
<Target Name="SetCecilConfiguration"
AfterTargets="AssignProjectConfiguration">
<ItemGroup>
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Mdb.csproj' ">
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_$(Configuration)</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">Configuration=netstandard_$(Configuration)</SetConfiguration>
</ProjectReferenceWithConfiguration>

View File

@@ -18,10 +18,15 @@
<LinkerDumpDependencies Condition=" '$(LinkerDumpDependencies)' == '' ">false</LinkerDumpDependencies>
<UsedApplicationAssemblyAction Condition=" '$(UsedApplicationAssemblyAction)' == '' ">Copy</UsedApplicationAssemblyAction>
<UnusedApplicationAssemblyAction Condition=" '$(UnusedApplicationAssemblyAction)' == '' ">Delete</UnusedApplicationAssemblyAction>
<UsedPlatformAssemblyAction Condition=" '$(UsedPlatformAssemblyAction)' == '' ">Link</UsedPlatformAssemblyAction>
<UnusedPlatformAssemblyAction Condition=" '$(UnusedPlatformAssemblyAction)' == '' ">Delete</UnusedPlatformAssemblyAction>
<UsedPlatformAssemblyAction Condition=" '$(UsedPlatformAssemblyAction)' == '' and '$(SelfContained)' == 'true' ">AddBypassNGen</UsedPlatformAssemblyAction>
<UsedPlatformAssemblyAction Condition=" '$(UsedPlatformAssemblyAction)' == '' ">Skip</UsedPlatformAssemblyAction>
<UnusedPlatformAssemblyAction Condition=" '$(UnusedPlatformAssemblyAction)' == '' and '$(SelfContained)' == 'true' ">Delete</UnusedPlatformAssemblyAction>
<UnusedPlatformAssemblyAction Condition=" '$(UnusedPlatformAssemblyAction)' == '' ">Skip</UnusedPlatformAssemblyAction>
<RootAllApplicationAssemblies Condition=" '$(RootAllApplicationAssemblies)' == '' ">true</RootAllApplicationAssemblies>
<RootAllApplicationAssemblies Condition=" '$(RootAllApplicationAssemblies)' != 'true' ">false</RootAllApplicationAssemblies>
<LinkerTrimNativeDeps Condition=" '$(LinkerTrimNativeDeps)' == '' ">true</LinkerTrimNativeDeps>
<LinkerTrimNativeDeps Condition=" '$(LinkerTrimNativeDeps)' != 'true' ">false</LinkerTrimNativeDeps>
<ClearInitLocals Condition=" '$(ClearInitLocals)' == '' ">false</ClearInitLocals>
</PropertyGroup>
<!-- This depends on LinkDuringPublish, so it needs to be imported
@@ -95,7 +100,7 @@
<ResolvedAssembliesToPublish Include="@(_NativeKeptDepsToPublish)" />
<ResolvedAssembliesToPublish Include="@(_LinkedResolvedAssemblies)" />
</ItemGroup>
<!-- Rewrite IntermediateAssembly, which is an input to
ComputeFilesToPublish. -->
<ItemGroup>
@@ -110,7 +115,7 @@
<_DebugSymbolsIntermediatePath Include="@(_LinkedDebugSymbols)" Condition=" '$(_DebugSymbolsProduced)' == 'true' " />
</ItemGroup>
</Target>
<!-- The SDK has a target called ComputeRefAssembliesToPublish that
runs after ComputeFilesToPublish and rewrites
ResolvedFileToPublish to include any reference assemblies that
@@ -203,7 +208,7 @@
<_ManagedAssembliesToLink Include="@(_ManagedAssembliesToLinkWithActions)" />
</ItemGroup>
</Target>
<!-- This calls the linker. Inputs are the managed assemblies to
link, and root specifications. The semaphore enables msbuild to
skip linking during an incremental build, when the semaphore is
@@ -218,13 +223,15 @@
the future we will want to generate these depending on the
scenario in which the linker is invoked. -->
<PropertyGroup>
<ExtraLinkerArgs Condition=" '$(ExtraLinkerArgs)' == '' ">-t -l none -b true</ExtraLinkerArgs>
<ExtraLinkerArgs Condition=" '$(ExtraLinkerArgs)' == '' ">-t -l none -b true --skip-unresolved true --verbose</ExtraLinkerArgs>
</PropertyGroup>
<ILLink AssemblyPaths="@(_ManagedAssembliesToLink)"
RootAssemblyNames="@(LinkerRootAssemblies)"
RootDescriptorFiles="@(LinkerRootDescriptors)"
OutputDirectory="$(IntermediateLinkDir)"
DumpDependencies="$(LinkerDumpDependencies)"
ClearInitLocals="$(ClearInitLocals)"
ClearInitLocalsAssemblies="$(ClearInitLocalsAssemblies)"
ExtraArgs="$(ExtraLinkerArgs)" />
<Touch Files="$(_LinkSemaphore)" AlwaysCreate="true">
@@ -241,6 +248,7 @@
<ItemGroup>
<_NativeResolvedDepsToPublish Include="@(ResolvedAssembliesToPublish)" />
<_NativeResolvedDepsToPublish Remove="@(_ManagedResolvedAssembliesToPublish)" />
<_NativeResolvedDepsToPublish Remove="@(_NativeResolvedDepsToPublish->WithMetadataValue('AssetType', 'resources'))" />
</ItemGroup>
<ItemGroup>
@@ -255,11 +263,15 @@
<_NativeDepsToAlwaysKeep Include="hostpolicy.dll;libhostpolicy.dylib;libhostpolicy.so" />
</ItemGroup>
<FindNativeDeps ManagedAssemblyPaths="@(_ManagedLinkedAssemblies)"
<FindNativeDeps Condition=" '$(LinkerTrimNativeDeps)' == 'true' "
ManagedAssemblyPaths="@(_ManagedLinkedAssemblies)"
NativeDepsPaths="@(_NativeResolvedDepsToPublish)"
NativeDepsToKeep="@(_NativeDepsToAlwaysKeep)">
<Output TaskParameter="KeptNativeDepsPaths" ItemName="_NativeKeptDepsToPublish" />
</FindNativeDeps>
<PropertyGroup>
<_NativeKeptDepsToPublish Condition=" '$(LinkerTrimNativeDeps)' != 'true' ">"@(_NativeResolvedDepsToPublish)"</_NativeKeptDepsToPublish>
</PropertyGroup>
</Target>
@@ -272,6 +284,26 @@
<_ManagedAssembliesToLink Include="@(IntermediateAssembly)" />
<_ManagedAssembliesToLink Include="@(_ManagedResolvedAssembliesToPublish)" />
</ItemGroup>
<!-- Portable publish: need to supply the linker with any needed
reference assemblies as well.
Sometimes assemblies have separate reference and
implementation assemblies. In these cases, prefer the
implementation assembly, and prevent inclusion of the ref
assembly by filtering on filename instead of the full
path. -->
<FilterByMetadata Items="@(ReferencePath->'%(ResolvedPath)')"
MetadataName="Filename"
MetadataValues="@(_ManagedAssembliesToLink->'%(Filename)')"
Condition=" '$(SelfContained)' != 'true' ">
<Output TaskParameter="FilteredItems" ItemName="_ReferencedLibrariesToExclude" />
</FilterByMetadata>
<ItemGroup Condition=" '$(SelfContained)' != 'true' ">
<_ReferencedLibraries Include="@(ReferencePath->'%(ResolvedPath)')" Exclude="@(_ReferencedLibrariesToExclude)" />
<_ManagedAssembliesToLink Include="@(_ReferencedLibraries)" />
</ItemGroup>
</Target>
@@ -298,7 +330,7 @@
output and the generated deps.json file. Excluding it from
_ManagedResolvedAssembliesToPublish will prevent it from
getting filtered out of the publish output later.
In the future we may want to detect ngen assemblies and
filter them more robustly. -->
<!-- TODO: Which .ni files do we expect to be in
@@ -330,12 +362,13 @@
to work on the publish output. -->
<Target Name="_ComputeLinkerRootAssemblies"
DependsOnTargets="_ComputeManagedResolvedAssembliesToPublish;_ComputePlatformLibraries;_CheckSystemPrivateCorelibEmbeddedRoots">
<!-- If RootAllApplicationAssemblies is true, roots are everything minus the framework
assemblies. This doesn't include the intermediate assembly,
because we root it separately using an xml file,
which lets us explicitly root everything.
<!-- If RootAllApplicationAssemblies is true, roots are everything
minus the framework assemblies. This doesn't include the
intermediate assembly, because we root it separately using an
xml file, which lets us explicitly root everything.
If RootAllApplicationAssemblies is false, only intermediate assembly's Main method is rooted.
If RootAllApplicationAssemblies is false, only intermediate
assembly's Main method is rooted.
System.Private.CoreLib is rooted unless it has an embedded
xml descriptor file. -->
@@ -354,7 +387,7 @@
</Target>
<UsingTask TaskName="CheckEmbeddedRootDescriptor" AssemblyFile="$(LinkTaskDllPath)" />
<Target Name="_CheckSystemPrivateCorelibEmbeddedRoots"
<Target Name="_CheckSystemPrivateCorelibEmbeddedRoots" Condition=" '$(SelfContained)' == 'true' "
DependsOnTargets="_ComputeManagedAssembliesToLink">
<CheckEmbeddedRootDescriptor AssemblyPath="@(_ManagedAssembliesToLink->WithMetadataValue('Filename', 'System.Private.CoreLib'))">
<Output TaskParameter="HasEmbeddedRootDescriptor" PropertyName="_SPCHasEmbeddedRootDescriptor" />
@@ -364,13 +397,19 @@
<!-- Platform libraries are the managed runtime assets needed by the
"platform", currently Microsoft.NETCore.App. -->
<UsingTask TaskName="GetRuntimeLibraries" AssemblyFile="$(LinkTaskDllPath)" />
<Target Name="_ComputePlatformLibraries">
<GetRuntimeLibraries AssetsFilePath="$(ProjectAssetsFile)"
<Target Name="_ComputePlatformLibraries"
DependsOnTargets="_ComputeManagedAssembliesToLink">
<GetRuntimeLibraries Condition=" '$(SelfContained)' == 'true' "
AssetsFilePath="$(ProjectAssetsFile)"
TargetFramework="$(TargetFrameworkMoniker)"
RuntimeIdentifier="$(RuntimeIdentifier)"
PackageNames="$(MicrosoftNETPlatformLibrary)">
<Output TaskParameter="RuntimeLibraries" ItemName="PlatformLibraries" />
</GetRuntimeLibraries>
<ItemGroup Condition=" '$(SelfContained)' != 'true' ">
<!-- Portable publish: computed referenced-not-published set in _ComputeManagedAssembliesToLink -->
<PlatformLibraries Include="@(_ReferencedLibraries)" />
</ItemGroup>
</Target>
@@ -416,7 +455,7 @@
<ItemGroup>
<_RemovedNativeDeps Include="@(_NativeResolvedDepsToPublish)" />
<_RemovedNativeDeps Remove="@(_NativeKeptDepsToPublish)" />
<_PublishConflictPackageFiles Include="@(_RemovedManagedAssemblies)" />
<_PublishConflictPackageFiles Include="@(_RemovedNativeDeps)" />
</ItemGroup>

View File

@@ -46,6 +46,17 @@ namespace ILLink.Tasks
/// </summary>
public ITaskItem [] RootDescriptorFiles { get; set; }
/// <summary>
/// Boolean specifying whether to clear initlocals flag on methods.
/// </summary>
public bool ClearInitLocals { get; set; }
/// <summary>
/// A comma-separated list of assemblies whose methods
/// should have initlocals flag cleared if ClearInitLocals is true.
/// </summary>
public string ClearInitLocalsAssemblies { get; set; }
/// <summary>
/// Extra arguments to pass to illink, delimited by spaces.
/// </summary>
@@ -61,7 +72,8 @@ namespace ILLink.Tasks
string [] args = GenerateCommandLineCommands ();
var argsString = String.Join (" ", args);
Log.LogMessageFromText ($"illink {argsString}", MessageImportance.Normal);
int ret = Mono.Linker.Driver.Main (args);
var logger = new AdapterLogger (Log);
int ret = Mono.Linker.Driver.Execute (args, logger);
return ret == 0;
}
@@ -104,6 +116,17 @@ namespace ILLink.Tasks
args.Add (OutputDirectory.ItemSpec);
}
if (ClearInitLocals) {
args.Add ("-s");
// Version of ILLink.CustomSteps is passed as a workaround for msbuild issue #3016
args.Add ("ILLink.CustomSteps.ClearInitLocalsStep,ILLink.CustomSteps,Version=0.0.0.0:OutputStep");
if ((ClearInitLocalsAssemblies != null) && (ClearInitLocalsAssemblies.Length > 0)) {
args.Add ("-m");
args.Add ("ClearInitLocalsAssemblies");
args.Add (ClearInitLocalsAssemblies);
}
}
if (ExtraArgs != null) {
args.AddRange (ExtraArgs.Split (' '));
}