[linker] Fortify the BlacklistStep.
authorRadek Doulik <rodo@xamarin.com>
Thu, 28 May 2015 19:35:34 +0000 (21:35 +0200)
committerRadek Doulik <rodo@xamarin.com>
Sun, 19 Jul 2015 08:40:28 +0000 (10:40 +0200)
[merged from monodroid by rodo]

commit 3001f693c52be0da673446179daf498265024867
Author: Alex Rønne Petersen <alexrp@xamarin.com>
Date:   Tue Jul 30 20:06:21 2013 +0200

    1. Catch XmlExceptions in case of broken XML files.
    2. Only process files that actually end in ".xml".

mcs/tools/linker/Mono.Linker.Steps/BlacklistStep.cs
mcs/tools/linker/Mono.Linker/LinkContext.cs

index 47864f7917e973df65dbfe8d8c825e0a014d8895..670fa04c66194c1f4bdc447a1421c9640a34c8a6 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
 using System.Linq;
 using System.IO;
 using System.Reflection;
+using System.Xml;
 using System.Xml.XPath;
 
 using Mono.Cecil;
@@ -55,9 +57,19 @@ namespace Mono.Linker.Steps {
                                                                .SelectMany (asm => asm.Modules)
                                                                .SelectMany (mod => mod.Resources)
                                                                .Where (res => res.ResourceType == ResourceType.Embedded)
+                                                               .Where (res => Path.GetExtension (res.Name) == ".xml")
                                                                .Where (res => IsReferenced (GetAssemblyName (res.Name)))
                                                                .Cast<EmbeddedResource> ()) {
-                               Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc));
+                               try {
+                                       if (Context.LogInternalExceptions)
+                                               Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name);
+
+                                       Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc));
+                               } catch (XmlException ex) {
+                                       /* This could happen if some broken XML file is embedded. */
+                                       if (Context.LogInternalExceptions)
+                                               Console.WriteLine ("Error processing {0}: {1}", rsc.Name, ex);
+                               }
                        }
                }
 
index c4d71083cd531805cb93116ea521ac956623fff0..417206ce0798843fb35d1584fbb132cd8e74e21b 100644 (file)
@@ -93,6 +93,8 @@ namespace Mono.Linker {
                        set { _symbolWriterProvider = value; }
                }
 
+               public bool LogInternalExceptions { get; set; } = false;
+
                public LinkContext (Pipeline pipeline)
                        : this (pipeline, new AssemblyResolver ())
                {