[mono/mono] c29ac46c: [linker]: Also reference all type-references for LinkAction.Link and Save.

"Martin Baulig ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141efc4a0b0-9cf29d4c-5200-4529-a369-9c33a9815491-000000@email.amazonses.com>
   Branch: refs/heads/mono-3.2.4-branch
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/f16333347399...c29ac46c408a

   Commit: c29ac46c408aa2ae588548fa36a0aa9bf0b01014
   Author: Martin Baulig <[email protected]> (baulig)
     Date: 2013-10-25 13:17:02 GMT
      URL: https://github.com/mono/mono/commit/c29ac46c408aa2ae588548fa36a0aa9bf0b01014

[linker]: Also reference all type-references for LinkAction.Link and Save.

Changed paths:
  M mcs/tools/linker/Mono.Linker.Steps/SweepStep.cs

Modified: mcs/tools/linker/Mono.Linker.Steps/SweepStep.cs
===================================================================
@@ -37,6 +37,7 @@ namespace Mono.Linker.Steps {
 	public class SweepStep : BaseStep {
 
 		AssemblyDefinition [] assemblies;
+		HashSet<AssemblyDefinition> resolvedTypeReferences;
 
 		protected override void Process ()
 		{
@@ -102,15 +103,38 @@ void SweepReferences (AssemblyDefinition assembly, AssemblyDefinition target)
 				references.RemoveAt (i);
 				// Removing the reference does not mean it will be saved back to disk!
 				// That depends on the AssemblyAction set for the `assembly`
-				if (Annotations.GetAction (assembly) == AssemblyAction.Copy) {
+				switch (Annotations.GetAction (assembly)) {
+				case AssemblyAction.Copy:
 					// Copy means even if "unlinked" we still want that assembly to be saved back 
 					// to disk (OutputStep) without the (removed) reference
 					Annotations.SetAction (assembly, AssemblyAction.Save);
+					ResolveAllTypeReferences (assembly);
+					break;
+
+				case AssemblyAction.Save:
+				case AssemblyAction.Link:
+					ResolveAllTypeReferences (assembly);
+					break;
 				}
 				return;
 			}
 		}
 
+		void ResolveAllTypeReferences (AssemblyDefinition assembly)
+		{
+			if (resolvedTypeReferences == null)
+				resolvedTypeReferences = new HashSet<AssemblyDefinition> ();
+			if (resolvedTypeReferences.Contains (assembly))
+				return;
+			resolvedTypeReferences.Add (assembly);
+
+			foreach (TypeReference tr in assembly.MainModule.GetTypeReferences ()) {
+				var td = tr.Resolve ();
+				// at this stage reference might include things that can't be resolved
+				tr.Scope = td == null ? null : assembly.MainModule.Import (td).Scope;
+			}
+		}
+
 		void SweepType (TypeDefinition type)
 		{
 			if (type.HasFields)


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.