Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

413
mcs/tools/tuner/ChangeLog Normal file
View File

@@ -0,0 +1,413 @@
2009-11-03 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: detect a throw_on_visibility_error
linker parameter to decide whether or not throw when an error
have been encountered.
2009-11-02 Jb Evain <jbevain@novell.com>
* Mono.Tuner/MoonlightAssemblyStep.cs: adapt to the MT linker merge.
2009-10-14 Raja R Harinath <harinath@hurrynot.org>
* Makefile (CECIL, LINKER): Point to profile-specific assembly.
2009-09-16 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Sort the
descriptors wrt type name, to avoid false negatives at
MoonAtkBridge build time.
2009-09-16 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Speed up by
two orders of magnitude, thanks to caching XPathNavigator
objects and calling Directory.GetFiles() just once.
* Mono.Tuner/MoonlightA11yApiMarker.cs: Fix typo in comment.
2009-09-10 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yApiMarker.cs: Don't mark attributes
of non-a11y assemblies.
2009-09-09 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Rather use
the OutputDirectory provided on the command line, and
redirect some progress info or errors to the console.
* Mono.Tuner/MoonlightA11yUsageInspectionStep.cs: Remove
unnecessary step.
2009-09-09 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner.csproj:
* Mono.Tuner.dll.sources: Add new step MoonlightA11yApiMarker.
* Mono.Tuner/MoonlightA11yApiMarker.cs:
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Use a new
marker step to only mark API used, not mark recursively.
* Mono.Tuner/MoonlightA11yUsageInspectionStep.cs: Use the new
marker step.
* Makefile: Adding reference to System, as we need it for
System.Text.RegularExpressions.
2009-08-13 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yProcessor.cs: Don't whitelist SC
attribs for base methods that are on our assembly.
This finally makes a11y work without security disabled. The
summary of the troubles encountered:
- GetHashCode() -> base method not SC. (r139589+r139649)
- Dispose() -> interface method not SC. (r139796)
- get_Handle() -> interface method SC while impl not SC.
(r139852)
2009-08-12 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yProcessor.cs: Look for base methods
in interfaces as well.
2009-08-11 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Yet another
blacklisted element (SW.dll is not linked).
2009-08-11 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Blacklist
more stuff.
2009-08-11 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Blacklist
our bridge.
2009-08-10 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yProcessor.cs: Move FIXME to a better
place. Fix NRE.
2009-08-07 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yProcessor.cs: Don't use var.
Remove debug spew.
2009-08-07 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: Make an enum
and a method protected.
* Mono.Tuner/MoonlightA11yProcessor.cs: Prevent
Type*Exceptions because of badly placed SC attrib on
methods.
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Typo in
comment.
2009-07-02 Jb Evain <jbevain@novell.com>
* Makefile: fix cecil's location.
2009-06-16 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yProcessor.cs: GLibSharp uses
Activator.CreateInstance for *Adapter classes, so we need to
have an exception here for these ctors (to avoid
MissingMethodExceptions).
2009-06-10 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Cosmetic.
* Mono.Tuner/MoonlightA11yAssemblyStep.cs: Typo.
2009-06-09 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Cosmetic.
2009-06-09 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner.csproj:
* Mono.Tuner.dll.sources: Update.
* Mono.Tuner/MoonlightA11yProcessor.cs:
* Mono.Tuner/MoonlightA11yAssemblyStep.cs: Typo.
* Mono.Tuner/MoonlightA11yUsageInspectionStep.cs:
* Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: New steps
for prevention of API stripping.
2009-06-04 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner.dll.sources:
* Mono.Tuner.csproj: Update.
* Mono.Tuner/InjectSecurityAttributes.cs:
* Mono.Tuner/MoonlightAssemblyStep.cs: Change some accessibility
keywords, to be able to override and inherit.
* Mono.Tuner/MoonlightA11yProcessor.cs:
* Mono.Tuner/MoonlightA11yAssemblyStep.cs: New steps for a11y.
2009-06-02 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner.csproj: Update.
* Mono.Tuner/InjectSecurityAttributes.cs: Avoid NRE.
2009-05-28 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: show a warning if using
the MoonlightAssemblyStep but no secattr option is specified.
2009-05-15 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: fix retrieval
of generic methods.
2009-05-15 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: fix issues
with non unique MethodReference.ToString for generic method defs.
2009-04-24 Jb Evain <jbevain@novell.com>
* Mono.Tuner.dll.sources: adjusted
* Mono.Tuner/FilterAttributes.cs: new step to remove some known
undesirable custom attributes.
2009-04-23 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: check deep nested types.
2009-04-22 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: take InternalsVisibleTo into account.
2009-04-22 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: take FamAndAssem into account.
2009-04-22 Jb Evain <jbevain@novell.com>
* AdjustVisibility.cs: we're now turning non exposed fields and
methods (API wise) that are `protected` into `protected and internal`.
2009-04-08 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner.csproj: Update.
2009-04-03 Andrés G. Aragoneses <aaragoneses@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: Show a warning
when the secattr file is not found.
2009-03-10 Jb Evain <jbevain@novell.com>
* Mono.Tuner/MoonlightAssemblyStep.cs: don't remove
the LoadReferencesStep for specific Moonlight tuning.
2009-03-01 Jb Evain <jbevain@novell.com>
* Mono.Tuner.dll.sources
* Mono.Tuner/MoonlightAssemblyStep.cs: add new step specific
to moonlight to instrument Moonlight assemblies one by one.
2009-02-19 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: also remove existing
CAS security declarations before injecting CoreCLR security attributes.
2009-02-18 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectSecurityAttributes.cs: new tuner step
which is able to process the security attribute data files.
It replaces the previous InjectAttributes step.
2009-01-28 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: use the appropriate Resolve methods.
2008-12-01 Jb Evain <jbevain@novell.com>
* Makefile: move tuning logic inside ../moon. We now simply build
the tuner as a simple library.
2008-11-20 Jb Evain <jbevain@novell.com>
* Makefile: simplify Makefile and tune System.Xml.Linq.
2008-10-16 Jb Evain <jbevain@novell.com>
* masterinfos/silverlight/*.info: update to SL2.
2008-09-23 Jb Evain <jbevain@novell.com>
* masterinfos/silverlight/Mono.CompilerServices.SymbolWriter.info
* Makefile:
tune the SymbolWriter as well.
2008-09-23 Jb Evain <jbevain@novell.com>
* Makefile: only execute the check visibility step if
CHECK_VISIBILITY is defined.
2008-09-18 Jb Evain <jbevain@novell.com>
* Mono.Tuner/AdjustVisibility.cs: correctly process public nested types.
2008-09-12 Jb Evain <jbevain@novell.com>
* Makefile: tune System.ServiceModel.Web.
2008-09-12 Jb Evain <jbevain@novell.com>
* Makefile: tune System.ServiceModel.dll
2008-09-12 Jb Evain <jbevain@novell.com>
* Makefile: make the linker generate new guids for the tuned
assemblies.
2008-09-09 Jb Evain <jbevain@novell.com>
* Makefile: tune System.Runtime.Serialization as well.
2008-08-05 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibility.cs: properly verify famorassem.
2008-06-10 Jb Evain <jbevain@novell.com>
* masterinfos/silverlight/System.Net.info
* masterinfos/silverlight/mscorlib.info
* masterinfos/silverlight/System.Xml.info
* masterinfos/silverlight/System.info:
Update to SL2B2 API.
2008-04-13 Jb Evain <jbevain@novell.com>
* masterinfos/silverlight/*.info: 2.0 api.
* Makefile: update.
Merged from the Moonlight 2 branch.
Thu Mar 13 22:32:24 CET 2008 Paolo Molaro <lupus@ximian.com>
* Makefile: strong name the tuned assemblies.
2008-03-13 Jb Evain <jbevain@novell.com>
* Mono.Tuner/AdjustVisibility.cs: don't adjust enums.
2008-02-18 Raja R Harinath <harinath@hurrynot.org>
* Makefile (inst-%, gac-%): Fix dependencies.
2008-02-17 Raja R Harinath <harinath@hurrynot.org>
* Makefile: Improve. Update to new net_2_1 profiles. Specify
more dependencies. Do work only when necessary.
* Descriptors/smcs.xml: Add CompilerCallableEntryPoint.
2008-02-01 Jb Evain <jbevain@novell.com>
* Makefile: remove System.Core temporary hack.
2008-02-01 Jb Evain <jbevain@novell.com>
* Makefile, Descriptors/System.Core.xml:
protect some internals of System.Core as apparently
the masterinfos are somewhat wrong.
2007-10-26 Jb Evain <jbevain@novell.com>
* Makefile: disable the `always build the tuner` as per
Paolo's suggestion. Need to use the build mecanism from now.
2007-10-26 Jb Evain <jbevain@novell.com>
* Makefile: activate the InjectAttributes step.
2007-10-25 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectAttributes.cs: inject security attributes
defined in the public api.
2007-10-25 Jb Evain <jbevain@novell.com>
* Mono.Tuner/InjectAttributes.cs: infrastructure for
the attribute injector.
2007-10-25 Jb Evain <jbevain@novell.com>
* Mono.Tuner/PrintStatus.cs: print which items
have been internalized if the parameter `display_internalized`
is set to true.
* Makefile: define parameter `display_internalized` and set it
to false. Set it explicitely to true if you want a detailed log
about which metadata items have been internalized.
2007-10-25 Jb Evain <jbevain@novell.com>
* Mono.Tuner/TunerAnnotations.cs
* Mono.Tuner/AdjustVisibility.cs:
Annotate the items that have been internalized
for later use.
* Makefile: always rebuild Mono.Tuner.dll for now.
2007-09-04 Jb Evain <jbevain@novell.com>
* masterinfos/*.info added, so we don't have to download them.
* Makefile: use directly the .info files from the repo.
2007-08-28 Jb Evain <jbevain@novell.com>
* Makefile: mdb support.
2007-08-21 Jb Evain <jbevain@novell.com>
* Makefile: tune on `all`, and only re-installed the tuned
assemblies on `install`.
2007-08-16 Jb Evain <jbevain@novell.com>
* Makefile: re-install in the GAC the tuned assemblies.
2007-08-13 Jb Evain <jbevain@novell.com>
* Makefile: tune on net_2_1 install.
2007-08-11 Jb Evain <jbevain@novell.com>
* Descriptors/System.xml, Makefile: add a descriptor
to protect some classes in System.
2007-08-05 Jb Evain <jbevain@novell.com>
* Descriptors/smcs.xml, Makefile: add a descriptor
to protect some classes in smcs.
2007-08-03 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : a bit win32 friendly fix.
2007-08-01 Jb Evain <jbevain@novell.com>
* Mono.Tuner/CheckVisibilit.cs:
New debugging step to ensure that the even after
API tuning the visibility is correct.
2007-07-27 Jb Evain <jbevain@novell.com>
* Mono.Tuner/RemoveSerialization.cs:
Add a new linker step to remove automatically everything
serialization related.
2007-07-18 Jb Evain <jbevain@novell.com>
* tuner: new tool to tune the Mono assemblies from a full 2.1
profile to a stripped down silverlight compatible assembly set.

16
mcs/tools/tuner/Makefile Normal file
View File

@@ -0,0 +1,16 @@
thisdir = tools/tuner
SUBDIRS =
include ../../build/rules.make
CECIL = $(topdir)/class/lib/$(PROFILE)/Mono.Cecil.dll
LINKER = $(topdir)/class/lib/$(PROFILE)/monolinker.exe
LOCAL_MCS_FLAGS = -r:System.dll -r:System.Core.dll -r:System.Xml.dll -r:$(LINKER) -r:$(CECIL)
LIBRARY = Mono.Tuner.dll
NO_INSTALL = yes
NO_TEST = yes
NO_SIGN_ASSEMBLY = yes
include ../../build/library.make

View File

@@ -0,0 +1,13 @@
Mono.Tuner/TunerAnnotations.cs
Mono.Tuner/PrintStatus.cs
Mono.Tuner/RemoveSerialization.cs
Mono.Tuner/AdjustVisibility.cs
Mono.Tuner/CheckVisibility.cs
Mono.Tuner/InjectSecurityAttributes.cs
Mono.Tuner/MoonlightA11yApiMarker.cs
Mono.Tuner/MoonlightA11yAssemblyStep.cs
Mono.Tuner/MoonlightA11yDescriptorGenerator.cs
Mono.Tuner/MoonlightA11yProcessor.cs
Mono.Tuner/MoonlightA11yUsageInspectionStep.cs
Mono.Tuner/MoonlightAssemblyStep.cs
Mono.Tuner/FilterAttributes.cs

View File

@@ -0,0 +1,164 @@
//
// AdjustVisibilityStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class AdjustVisibility : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
ProcessTypes (assembly.MainModule.Types);
}
void ProcessTypes (ICollection types)
{
foreach (TypeDefinition type in types)
ProcessType (type);
}
void ProcessType (TypeDefinition type)
{
if (!IsPublic (type))
return;
if (!IsMarkedAsPublic (type)) {
SetInternalVisibility (type);
return;
}
if (type.IsEnum)
return;
ProcessFields (type.Fields);
ProcessMethods (type.Methods);
}
static bool IsPublic (TypeDefinition type)
{
return type.DeclaringType == null ? type.IsPublic : type.IsNestedPublic;
}
void SetInternalVisibility (TypeDefinition type)
{
type.Attributes &= ~TypeAttributes.VisibilityMask;
if (type.DeclaringType == null)
type.Attributes |= TypeAttributes.NotPublic;
else
type.Attributes |= TypeAttributes.NestedAssembly;
MarkInternalized (type);
}
void ProcessMethods (ICollection methods)
{
foreach (MethodDefinition method in methods)
ProcessMethod (method);
}
void ProcessMethod (MethodDefinition method)
{
if (IsMarkedAsPublic (method))
return;
if (method.IsPublic)
SetInternalVisibility (method);
else if (method.IsFamily || method.IsFamilyOrAssembly)
SetProtectedAndInternalVisibility (method);
}
void SetInternalVisibility (MethodDefinition method)
{
method.Attributes &= ~MethodAttributes.MemberAccessMask;
method.Attributes |= MethodAttributes.Assembly;
MarkInternalized (method);
}
void SetProtectedAndInternalVisibility (MethodDefinition method)
{
method.Attributes &= ~MethodAttributes.MemberAccessMask;
method.Attributes |= MethodAttributes.FamANDAssem;
MarkInternalized (method);
}
bool IsMarkedAsPublic (IMetadataTokenProvider provider)
{
return Annotations.IsPublic (provider);
}
void ProcessFields (IEnumerable<FieldDefinition> fields)
{
foreach (FieldDefinition field in fields)
ProcessField (field);
}
void ProcessField (FieldDefinition field)
{
if (IsMarkedAsPublic (field))
return;
if (field.IsPublic)
SetInternalVisibility (field);
else if (field.IsFamily || field.IsFamilyOrAssembly)
SetProtectedAndInternalVisibility (field);
}
void SetInternalVisibility (FieldDefinition field)
{
field.Attributes &= ~FieldAttributes.FieldAccessMask;
field.Attributes |= FieldAttributes.Assembly;
MarkInternalized (field);
}
void SetProtectedAndInternalVisibility (FieldDefinition field)
{
field.Attributes &= ~FieldAttributes.FieldAccessMask;
field.Attributes |= FieldAttributes.FamANDAssem;
MarkInternalized (field);
}
void MarkInternalized (IMetadataTokenProvider provider)
{
TunerAnnotations.Internalized (Context, provider);
}
}
}

View File

@@ -0,0 +1,375 @@
//
// CheckVisibility.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Text;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Mono.Tuner {
public class CheckVisibility : BaseStep {
bool throw_on_error;
protected override void Process ()
{
throw_on_error = GetThrowOnVisibilityErrorParameter ();
}
bool GetThrowOnVisibilityErrorParameter ()
{
try {
return bool.Parse (Context.GetParameter ("throw_on_visibility_error"));
} catch {
return false;
}
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (assembly.Name.Name == "mscorlib" || assembly.Name.Name == "smcs")
return;
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
Report ("in assembly {0}", assembly.Name);
foreach (ModuleDefinition module in assembly.Modules)
foreach (TypeDefinition type in module.Types)
CheckType (type);
}
void CheckType (TypeDefinition type)
{
if (!IsVisibleFrom (type, type.BaseType)) {
ReportError ("Base type `{0}` of type `{1}` is not visible",
type.BaseType, type);
}
CheckInterfaces (type);
CheckFields (type);
CheckMethods (type);
}
void CheckInterfaces (TypeDefinition type)
{
foreach (TypeReference iface in type.Interfaces) {
if (!IsVisibleFrom (type, iface)) {
ReportError ("Interface `{0}` implemented by `{1}` is not visible",
iface, type);
}
}
}
static bool IsPublic (TypeDefinition type)
{
return (type.DeclaringType == null && type.IsPublic) || type.IsNestedPublic;
}
static bool AreInDifferentAssemblies (TypeDefinition type, TypeDefinition target)
{
if (type.Module.Assembly.Name.FullName == target.Module.Assembly.Name.FullName)
return false;
return !IsInternalVisibleTo (target.Module.Assembly, type.Module.Assembly);
}
static bool IsInternalVisibleTo (AssemblyDefinition assembly, AssemblyDefinition candidate)
{
foreach (CustomAttribute attribute in assembly.CustomAttributes) {
if (!IsInternalsVisibleToAttribute (attribute))
continue;
if (attribute.ConstructorArguments.Count == 0)
continue;
string signature = (string) attribute.ConstructorArguments [0].Value;
if (InternalsVisibleToSignatureMatch (signature, candidate.Name))
return true;
}
return false;
}
static bool InternalsVisibleToSignatureMatch (string signature, AssemblyNameReference reference)
{
int pos = signature.IndexOf (",");
if (pos == -1)
return signature == reference.Name;
string assembly_name = signature.Substring (0, pos);
pos = signature.IndexOf ("=");
if (pos == -1)
throw new ArgumentException ();
string public_key = signature.Substring (pos + 1).ToLower ();
return assembly_name == reference.Name && public_key == ToPublicKeyString (reference.PublicKey);
}
static string ToPublicKeyString (byte [] public_key)
{
StringBuilder signature = new StringBuilder (public_key.Length);
for (int i = 0; i < public_key.Length; i++)
signature.Append (public_key [i].ToString ("x2"));
return signature.ToString ();
}
static bool IsInternalsVisibleToAttribute (CustomAttribute attribute)
{
return attribute.Constructor.DeclaringType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute";
}
bool IsVisibleFrom (TypeDefinition type, TypeReference reference)
{
if (reference == null)
return true;
if (reference is GenericParameter || reference.GetElementType () is GenericParameter)
return true;
TypeDefinition other = reference.Resolve ();
if (other == null)
return true;
if (!AreInDifferentAssemblies (type, other))
return true;
if (IsPublic (other))
return true;
return false;
}
bool IsVisibleFrom (TypeDefinition type, MethodReference reference)
{
if (reference == null)
return true;
MethodDefinition meth = reference.Resolve ();
if (meth == null)
return true;
TypeDefinition dec = (TypeDefinition) meth.DeclaringType;
if (!IsVisibleFrom (type, dec))
return false;
if (meth.IsPublic)
return true;
if (type == dec || IsNestedIn (type, dec))
return true;
if (meth.IsFamily && InHierarchy (type, dec))
return true;
if (meth.IsFamilyOrAssembly && (!AreInDifferentAssemblies (type, dec) || InHierarchy (type, dec)))
return true;
if (meth.IsFamilyAndAssembly && (!AreInDifferentAssemblies (type, dec) && InHierarchy (type, dec)))
return true;
if (!AreInDifferentAssemblies (type, dec) && meth.IsAssembly)
return true;
return false;
}
bool IsVisibleFrom (TypeDefinition type, FieldReference reference)
{
if (reference == null)
return true;
FieldDefinition field = reference.Resolve ();
if (field == null)
return true;
TypeDefinition dec = (TypeDefinition) field.DeclaringType;
if (!IsVisibleFrom (type, dec))
return false;
if (field.IsPublic)
return true;
if (type == dec || IsNestedIn (type, dec))
return true;
if (field.IsFamily && InHierarchy (type, dec))
return true;
if (field.IsFamilyOrAssembly && (!AreInDifferentAssemblies (type, dec) || InHierarchy (type, dec)))
return true;
if (field.IsFamilyAndAssembly && (!AreInDifferentAssemblies (type, dec) && InHierarchy (type, dec)))
return true;
if (!AreInDifferentAssemblies (type, dec) && field.IsAssembly)
return true;
return false;
}
static bool IsNestedIn (TypeDefinition type, TypeDefinition other)
{
TypeDefinition declaring = type.DeclaringType;
if (declaring == null)
return false;
if (declaring == other)
return true;
if (declaring.DeclaringType == null)
return false;
return IsNestedIn (declaring, other);
}
static bool InHierarchy (TypeDefinition type, TypeDefinition other)
{
if (type.BaseType == null)
return false;
TypeDefinition baseType = type.BaseType.Resolve ();
if (baseType == other)
return true;
return InHierarchy (baseType, other);
}
static void Report (string pattern, params object [] parameters)
{
Console.WriteLine ("[check] " + pattern, parameters);
}
void ReportError (string pattern, params object [] parameters)
{
Report (pattern, parameters);
if (throw_on_error)
throw new VisibilityErrorException (string.Format (pattern, parameters));
}
void CheckFields (TypeDefinition type)
{
foreach (FieldDefinition field in type.Fields) {
if (!IsVisibleFrom (type, field.FieldType)) {
ReportError ("Field `{0}` of type `{1}` is not visible from `{2}`",
field.Name, field.FieldType, type);
}
}
}
void CheckMethods (TypeDefinition type)
{
CheckMethods (type, type.Methods);
}
void CheckMethods (TypeDefinition type, ICollection methods)
{
foreach (MethodDefinition method in methods) {
if (!IsVisibleFrom (type, method.ReturnType)) {
ReportError ("Method return type `{0}` in method `{1}` is not visible",
method.ReturnType, method);
}
foreach (ParameterDefinition parameter in method.Parameters) {
if (!IsVisibleFrom (type, parameter.ParameterType)) {
ReportError ("Parameter `{0}` of type `{1}` in method `{2}` is not visible.",
parameter.Index, parameter.ParameterType, method);
}
}
if (method.HasBody)
CheckBody (method);
}
}
void CheckBody (MethodDefinition method)
{
TypeDefinition type = (TypeDefinition) method.DeclaringType;
foreach (VariableDefinition variable in method.Body.Variables) {
if (!IsVisibleFrom ((TypeDefinition) method.DeclaringType, variable.VariableType)) {
ReportError ("Variable `{0}` of type `{1}` from method `{2}` is not visible",
variable.Index, variable.VariableType, method);
}
}
foreach (Instruction instr in method.Body.Instructions) {
switch (instr.OpCode.OperandType) {
case OperandType.InlineType:
case OperandType.InlineMethod:
case OperandType.InlineField:
case OperandType.InlineTok:
bool error = false;
TypeReference type_ref = instr.Operand as TypeReference;
if (type_ref != null)
error = !IsVisibleFrom (type, type_ref);
MethodReference meth_ref = instr.Operand as MethodReference;
if (meth_ref != null)
error = !IsVisibleFrom (type, meth_ref);
FieldReference field_ref = instr.Operand as FieldReference;
if (field_ref != null)
error = !IsVisibleFrom (type, field_ref);
if (error) {
ReportError ("Operand `{0}` of type {1} at offset 0x{2} in method `{3}` is not visible",
instr.Operand, instr.OpCode.OperandType, instr.Offset.ToString ("x4"), method);
}
break;
default:
continue;
}
}
}
class VisibilityErrorException : Exception {
public VisibilityErrorException (string message)
: base (message)
{
}
}
}
}

View File

@@ -0,0 +1,157 @@
//
// FilterAttributes.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class FilterAttributes : BaseStep {
static Hashtable attributes = new Hashtable ();
static FilterAttributes ()
{
FilterAttribute ("System.Runtime.InteropServices.ComVisibleAttribute");
}
static void FilterAttribute (string fullname)
{
attributes.Add (fullname, null);
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
Filter (assembly);
foreach (ModuleDefinition module in assembly.Modules)
ProcessModule (module);
}
static void ProcessModule (ModuleDefinition module)
{
Filter (module);
foreach (TypeDefinition type in module.Types)
ProcessType (type);
}
static void ProcessType (TypeDefinition type)
{
if (type.HasFields)
ProcessFields (type.Fields);
if (type.HasMethods)
ProcessMethods (type.Methods);
if (type.HasEvents)
ProcessEvents (type.Events);
if (type.HasProperties)
ProcessProperties (type.Properties);
ProcessGenericParameters (type);
}
static void ProcessFields (ICollection fields)
{
foreach (FieldDefinition field in fields)
Filter (field);
}
static void ProcessMethods (ICollection methods)
{
foreach (MethodDefinition method in methods)
ProcessMethod (method);
}
static void ProcessMethod (MethodDefinition method)
{
ProcessGenericParameters (method);
Filter (method.MethodReturnType);
if (method.HasParameters)
ProcessParameters (method.Parameters);
}
static void ProcessParameters (ICollection parameters)
{
foreach (ParameterDefinition parameter in parameters)
Filter (parameter);
}
static void ProcessGenericParameters (IGenericParameterProvider provider)
{
if (!provider.HasGenericParameters)
return;
foreach (GenericParameter parameter in provider.GenericParameters)
Filter (parameter);
}
static void ProcessEvents (ICollection events)
{
foreach (EventDefinition @event in events)
Filter (@event);
}
static void ProcessProperties (ICollection properties)
{
foreach (PropertyDefinition property in properties)
Filter (property);
}
static void Filter (ICustomAttributeProvider provider)
{
if (!provider.HasCustomAttributes)
return;
for (int i = 0; i < provider.CustomAttributes.Count; i++) {
CustomAttribute attribute = provider.CustomAttributes [i];
if (!IsFilteredAttribute (attribute))
continue;
provider.CustomAttributes.RemoveAt (i--);
}
}
static bool IsFilteredAttribute (CustomAttribute attribute)
{
return attributes.Contains (attribute.Constructor.DeclaringType.FullName);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
//
// MoonlightA11yApiMarker.cs
//
// Author:
// Andrés G. Aragoneses (aaragoneses@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Xml;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class MoonlightA11yApiMarker : MarkStep {
bool IsA11yAssembly (AssemblyDefinition assembly)
{
return assembly.ToString ().Contains ("DummyEntry") || assembly.ToString ().Contains ("MoonAtkBridge");
}
protected override void InitializeAssembly (AssemblyDefinition assembly)
{
if (IsA11yAssembly (assembly))
base.InitializeAssembly (assembly);
}
protected override void EnqueueMethod (MethodDefinition method)
{
if (IsA11yAssembly (method.DeclaringType.Module.Assembly))
base.EnqueueMethod (method);
else
Annotations.Mark (method);
}
protected override bool IgnoreScope (IMetadataScope scope)
{
return false;
}
protected override TypeDefinition MarkType (TypeReference reference)
{
if (reference == null)
throw new ArgumentNullException ("reference");
reference = GetOriginalType (reference);
if (reference is GenericParameter)
return null;
TypeDefinition type = reference.Resolve ();
if (type == null)
throw new ResolutionException (reference);
if (CheckProcessed (type))
return type;
Annotations.Mark (type);
return type;
}
}
}

View File

@@ -0,0 +1,54 @@
//
// MoonlightA11yAssemblyStep.cs
//
// Author:
// Andrés G. Aragoneses (aaragoneses@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.IO;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class MoonlightA11yAssemblyStep : MoonlightAssemblyStep {
protected override void CustomizePipeline (Pipeline pipeline)
{
pipeline.RemoveStep (typeof (LoadI18nAssemblies));
pipeline.RemoveStep (typeof (BlacklistStep));
pipeline.RemoveStep (typeof (MarkStep));
pipeline.RemoveStep (typeof (SweepStep));
pipeline.RemoveStep (typeof (CleanStep));
pipeline.RemoveStep (typeof (RegenerateGuidStep));
pipeline.AddStepBefore (typeof (OutputStep), new MoonlightA11yProcessor ());
}
}
}

View File

@@ -0,0 +1,337 @@
//
// MoonlightA11yDescriptorGenerator.cs
//
// Author:
// Andrés G. Aragoneses (aaragoneses@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class MoonlightA11yDescriptorGenerator : BaseStep {
XmlTextWriter writer = null;
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (assembly.Name.Name == "MoonAtkBridge" || assembly.Name.Name == "System.Windows" ||
assembly.Name.Name.Contains ("Dummy"))
return;
if (writer == null) {
if (!Directory.Exists (Context.OutputDirectory))
Directory.CreateDirectory (Context.OutputDirectory);
string file_name = "descriptors.xml";
string file_path = Path.Combine (Context.OutputDirectory, file_name);
if (File.Exists (file_path))
File.Delete (file_path);
FileStream xml_file = new FileStream (file_path, FileMode.OpenOrCreate);
Console.WriteLine ("Created file {0}", file_name);
Console.Write ("Writing contents...");
writer = new XmlTextWriter (xml_file, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("linker");
}
SortedDictionary <TypeDefinition, IList> types = ScanAssembly (assembly);
if (types != null && types.Count > 0) {
writer.WriteStartElement("assembly");
writer.WriteAttributeString ("fullname", assembly.Name.Name);
foreach (TypeDefinition type in types.Keys) {
IList members = types [type];
if (members != null && members.Count > 0) {
writer.WriteStartElement("type");
writer.WriteAttributeString ("fullname", type.FullName);
foreach (IMetadataTokenProvider member in members) {
MethodDefinition method = member as MethodDefinition;
if (method != null) {
writer.WriteStartElement("method");
writer.WriteAttributeString ("signature",
method.ReturnType.FullName + " " +
method.Name + GetMethodParams (method));
writer.WriteEndElement ();
continue;
}
FieldDefinition field = member as FieldDefinition;
if (field != null) {
writer.WriteStartElement("field");
writer.WriteAttributeString ("signature", field.DeclaringType.FullName + " " + field.Name);
writer.WriteEndElement ();
}
}
writer.WriteEndElement ();
}
}
writer.WriteEndElement ();
Console.WriteLine ();
}
}
protected override void EndProcess ()
{
Console.WriteLine ();
foreach (FileStream stream in streams)
stream.Close ();
if (writer != null) {
writer.WriteEndElement ();
writer.Close ();
writer = null;
}
}
//this is almost the ToString method of MethodDefinition...
private string GetMethodParams (MethodDefinition method)
{
string @params = "(";
if (method.HasParameters) {
for (int i = 0; i < method.Parameters.Count; i++) {
if (i > 0)
@params += ",";
@params += method.Parameters [i].ParameterType.FullName;
}
}
@params += ")";
return @params;
}
SortedDictionary<TypeDefinition, IList> /*,List<IAnnotationProvider>>*/ ScanAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return null;
SortedDictionary<TypeDefinition, IList> members_used = new SortedDictionary<TypeDefinition, IList> (new TypeComparer ());
foreach (TypeDefinition type in assembly.MainModule.Types) {
IList used_providers = FilterPublicMembers (ScanType (type));
if (used_providers.Count > 0)
members_used [type] = used_providers;
else if (IsInternal (type, true) &&
Annotations.IsMarked (type))
throw new NotSupportedException (String.Format ("The type {0} is used while its API is not", type.ToString ()));
}
return members_used;
}
IList ScanType (TypeDefinition type)
{
return ExtractUsedProviders (type.Methods, type.Fields);
}
static IList FilterPublicMembers (IList members)
{
IList new_list = new ArrayList ();
foreach (MemberReference item in members)
if (IsInternal (item, true))
new_list.Add (item);
return new_list;
}
static string [] master_infos = Directory.GetFiles (Environment.CurrentDirectory, "*.info");
static string FindMasterInfoFile (string name)
{
if (master_infos.Length == 0)
throw new Exception ("No masterinfo files found in current directory");
foreach (string file in master_infos) {
if (file.EndsWith (name + ".info"))
return file;
}
return null;
}
const string xpath_init = "assemblies/assembly/namespaces/namespace[@name='{0}']/classes/class[@name='{1}']";
static string GetXPathSearchForType (TypeDefinition type)
{
TypeDefinition parent_type = type;
string xpath = String.Empty;
while (parent_type.DeclaringType != null) {
xpath = String.Format ("/classes/class[@name='{0}']", parent_type.Name) + xpath;
parent_type = parent_type.DeclaringType;
}
return String.Format (xpath_init, parent_type.Namespace, parent_type.Name) + xpath;
}
static bool IsInternal (MemberReference member, bool master_info)
{
TypeDefinition type = null;
string master_info_file = null;
if (member is TypeDefinition) {
type = member as TypeDefinition;
if (!master_info)
return (!type.IsNested && !type.IsPublic) ||
(type.IsNested && (!type.IsNestedPublic || IsInternal (type.DeclaringType, false)));
master_info_file = FindMasterInfoFile (type.Module.Assembly.Name.Name);
if (master_info_file == null)
return IsInternal (member, false);
return !NodeExists (master_info_file, GetXPathSearchForType (type));
}
type = member.DeclaringType.Resolve ();
if (IsInternal (type, master_info))
return true;
MethodDefinition method = member as MethodDefinition;
FieldDefinition field = member as FieldDefinition;
if (field == null && method == null)
throw new System.NotSupportedException ("Members to scan should be methods or fields");
if (!master_info) {
if (method != null)
return !method.IsPublic;
return !field.IsPublic;
}
master_info_file = FindMasterInfoFile (type.Module.Assembly.Name.Name);
if (master_info_file == null)
return IsInternal (member, false);
string xpath_type = GetXPathSearchForType (type);
string name;
if (field != null)
name = field.Name;
else {
name = method.ToString ();
//lame, I know...
name = WackyOutArgs (WackyCommas (name.Substring (name.IndexOf ("::") + 2)
.Replace ("/", "+") // nested classes
.Replace ('<', '[').Replace ('>', ']'))); //generic params
}
if (field != null || !IsPropertyMethod (method))
return !NodeExists (master_info_file, xpath_type + String.Format ("/*/*[@name='{0}']", name));
return !NodeExists (master_info_file, xpath_type + String.Format ("/properties/*/*/*[@name='{0}']", name));
}
//at some point I want to get rid of this method and ask cecil's maintainer to spew commas in a uniform way...
static string WackyCommas (string method)
{
string outstring = String.Empty;
bool square_bracket = false;
foreach (char c in method) {
if (c == '[')
square_bracket = true;
else if (c == ']')
square_bracket = false;
outstring = outstring + c;
if (c == ',' && !square_bracket)
outstring = outstring + " ";
}
return outstring;
}
//ToString() spews & but not 'out' keyword
static string WackyOutArgs (string method)
{
return Regex.Replace (method, @"\w+&", delegate (Match m) { return "out " + m.ToString (); });
}
//copied from MarkStep (violating DRY unless I can put this in a better place... Cecil?)
static bool IsPropertyMethod (MethodDefinition md)
{
return (md.SemanticsAttributes & MethodSemanticsAttributes.Getter) != 0 ||
(md.SemanticsAttributes & MethodSemanticsAttributes.Setter) != 0;
}
static Dictionary<string, XPathNavigator> navs = new Dictionary<string, XPathNavigator> ();
static List<FileStream> streams = new List<FileStream> ();
static bool NodeExists (string file, string xpath)
{
Console.Write (".");
//Console.WriteLine ("Looking for node {0} in file {1}", xpath, file.Substring (file.LastIndexOf ("/") + 1));
XPathNavigator nav = null;
if (!navs.TryGetValue (file, out nav)) {
FileStream stream = new FileStream (file, FileMode.Open);
XPathDocument document = new XPathDocument (stream);
nav = document.CreateNavigator ();
streams.Add (stream);
navs [file] = nav;
}
return nav.SelectSingleNode (xpath) != null;
}
IList /*List<IAnnotationProvider>*/ ExtractUsedProviders (params IList[] members)
{
IList used = new ArrayList ();
if (members == null || members.Length == 0)
return used;
foreach (IList members_list in members)
foreach (IMetadataTokenProvider provider in members_list)
if (Annotations.IsMarked (provider))
used.Add (provider);
return used;
}
class TypeComparer : IComparer <TypeDefinition> {
public int Compare (TypeDefinition x, TypeDefinition y)
{
return string.Compare (x.ToString (), y.ToString ());
}
}
}
}

View File

@@ -0,0 +1,179 @@
//
// MoonlightA11yProcessor.cs
//
// Author:
// Andrés G. Aragoneses (aaragoneses@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Linq;
using Mono.Cecil;
using Mono.Linker;
namespace Mono.Tuner {
public class MoonlightA11yProcessor : InjectSecurityAttributes {
protected override bool ConditionToProcess ()
{
return true;
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
_assembly = assembly;
// remove existing [SecurityCritical] and [SecuritySafeCritical]
RemoveSecurityAttributes ();
// add [SecurityCritical]
AddSecurityAttributes ();
// convert all public members into internal
MakeApiInternal ();
}
void MakeApiInternal ()
{
foreach (TypeDefinition type in _assembly.MainModule.Types) {
if (type.IsPublic)
type.IsPublic = false;
if (type.HasMethods && !type.Name.EndsWith ("Adapter"))
foreach (MethodDefinition ctor in type.Methods.Where (m => m.IsConstructor))
if (ctor.IsPublic)
ctor.IsAssembly = true;
if (type.HasMethods)
foreach (MethodDefinition method in type.Methods.Where (m => !m.IsConstructor))
if (method.IsPublic)
method.IsAssembly = true;
}
}
void AddSecurityAttributes ()
{
foreach (TypeDefinition type in _assembly.MainModule.Types) {
AddCriticalAttribute (type);
if (type.HasMethods)
foreach (MethodDefinition ctor in type.Methods.Where (m => m.IsConstructor))
AddCriticalAttribute (ctor);
if (type.HasMethods)
foreach (MethodDefinition method in type.Methods.Where (m => !m.IsConstructor)) {
MethodDefinition parent = null;
//TODO: take in account generic params
if (!method.HasGenericParameters) {
/*
* we need to scan base methods because the CoreCLR complains about SC attribs added
* to overriden methods whose base (virtual or interface) method is not marked as SC
* with TypeLoadExceptions
*/
parent = GetBaseMethod (type, method);
}
//if there's no base method
if (parent == null ||
//if it's our bridge assembly, we're sure it will (finally, at the end of the linking process) have the SC attrib
_assembly.MainModule.Types.Contains (parent.DeclaringType) ||
//if the type is in the moonlight assemblies, check if it has the SC attrib
HasSecurityAttribute (parent, AttributeType.Critical))
AddCriticalAttribute (method);
}
}
}
MethodDefinition GetBaseMethod (TypeDefinition finalType, MethodDefinition final)
{
// both GetOverridenMethod and GetInterfaceMethod return null if there is no base method
return GetOverridenMethod (finalType, final) ?? GetInterfaceMethod (finalType, final);
}
//note: will not return abstract methods
MethodDefinition GetOverridenMethod (TypeDefinition finalType, MethodDefinition final)
{
TypeReference baseType = finalType.BaseType;
while (baseType != null && baseType.Resolve () != null) {
foreach (MethodDefinition method in baseType.Resolve ().Methods) {
if (!method.IsVirtual || method.Name != final.Name)
continue;
//TODO: should we discard them?
if (method.IsAbstract)
continue;
if (HasSameSignature (method, final))
return method;
}
baseType = baseType.Resolve().BaseType;
}
return null;
}
MethodDefinition GetInterfaceMethod (TypeDefinition finalType, MethodDefinition final)
{
TypeDefinition baseType = finalType;
while (baseType != null) {
if (baseType.HasInterfaces)
foreach (TypeReference @interface in baseType.Interfaces)
foreach (MethodDefinition method in @interface.Resolve ().Methods)
if (method.Name == final.Name && HasSameSignature (method, final))
return method;
baseType = baseType.BaseType == null ? null : baseType.BaseType.Resolve ();
}
return null;
}
bool HasSameSignature (MethodDefinition method1, MethodDefinition method2)
{
if (method1.ReturnType.FullName != method2.ReturnType.FullName)
return false;
if (method1.Parameters.Count != method2.Parameters.Count)
return false;
for (int i = 0; i < method1.Parameters.Count; i++) {
if (method1.Parameters [i].ParameterType.FullName !=
method2.Parameters [i].ParameterType.FullName)
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,52 @@
//
// MoonlightA11yUsageInspectionStep.cs
//
// Author:
// Andrés G. Aragoneses (aaragoneses@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.IO;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class MoonlightA11yUsageInspectionStep : MoonlightAssemblyStep {
protected override void CustomizePipeline (Pipeline pipeline)
{
pipeline.ReplaceStep (typeof (MarkStep), new MoonlightA11yApiMarker ());
pipeline.ReplaceStep (typeof (SweepStep), new MoonlightA11yDescriptorGenerator ());
pipeline.RemoveStep (typeof (LoadI18nAssemblies));
pipeline.RemoveStep (typeof (CleanStep));
pipeline.RemoveStep (typeof (RegenerateGuidStep));
pipeline.RemoveStep (typeof (OutputStep));
}
}
}

View File

@@ -0,0 +1,66 @@
//
// MoonlightAssemblyStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.IO;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class MoonlightAssemblyStep : IStep {
public void Process (LinkContext context)
{
CustomizePipeline (context.Pipeline);
ProcessAssemblies (context);
}
static void ProcessAssemblies (LinkContext context)
{
foreach (AssemblyDefinition assembly in context.GetAssemblies ())
context.Annotations.SetAction (assembly, AssemblyAction.Link);
}
protected virtual void CustomizePipeline (Pipeline pipeline)
{
pipeline.RemoveStep (typeof (LoadI18nAssemblies));
pipeline.RemoveStep (typeof (BlacklistStep));
pipeline.RemoveStep (typeof (TypeMapStep));
pipeline.RemoveStep (typeof (MarkStep));
pipeline.RemoveStep (typeof (SweepStep));
pipeline.RemoveStep (typeof (CleanStep));
pipeline.RemoveStep (typeof (RegenerateGuidStep));
pipeline.AddStepBefore (typeof (OutputStep), new InjectSecurityAttributes ());
}
}
}

View File

@@ -0,0 +1,86 @@
//
// PrintStatus.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class PrintStatus : BaseStep {
static string display_internalized = "display_internalized";
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
Console.WriteLine ("Assembly `{0}' ({1}) tuned", assembly.Name, assembly.MainModule.FullyQualifiedName);
if (!DisplayInternalized ())
return;
foreach (TypeDefinition type in assembly.MainModule.Types)
ProcessType (type);
}
bool DisplayInternalized ()
{
try {
return bool.Parse (Context.GetParameter (display_internalized));
} catch {
return false;
}
}
void ProcessType (TypeDefinition type)
{
ProcessCollection (type.Fields);
ProcessCollection (type.Methods);
}
void ProcessCollection (ICollection collection)
{
foreach (IMetadataTokenProvider provider in collection)
ProcessProvider (provider);
}
void ProcessProvider (IMetadataTokenProvider provider)
{
if (!TunerAnnotations.IsInternalized (Context, provider))
return;
Console.WriteLine ("[internalized] {0}", provider);
}
}
}

View File

@@ -0,0 +1,149 @@
//
// RemoveSerialization.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace Mono.Tuner {
public class RemoveSerialization : BaseStep {
static readonly string _Serialization = "System.Runtime.Serialization";
static readonly string _ISerializable = Concat (_Serialization, "ISerializable");
static readonly string _IDeserializationCallback = Concat (_Serialization, "IDeserializationCallback");
static readonly string _SerializationInfo = Concat (_Serialization, "SerializationInfo");
static readonly string _StreamingContext = Concat (_Serialization, "StreamingContext");
static readonly string _GetObjectData = "GetObjectData";
static readonly string _OnDeserialization = "OnDeserialization";
static string Concat (string lhs, string rhs)
{
return string.Concat (lhs, ".", rhs);
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (assembly.Name.Name == "mscorlib")
return;
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
foreach (ModuleDefinition module in assembly.Modules)
foreach (TypeDefinition type in module.Types)
ProcessType (type);
}
static void RemoveInterface (TypeDefinition type, string name)
{
for (int i = 0; i < type.Interfaces.Count; i++) {
TypeReference iface = type.Interfaces [i];
if (iface.FullName == name) {
type.Interfaces.RemoveAt (i);
return;
}
}
}
static void RemoveSerializableFlag (TypeDefinition type)
{
type.Attributes &= ~TypeAttributes.Serializable;
}
static void ProcessType (TypeDefinition type)
{
RemoveSerializableFlag (type);
RemoveInterface (type, _ISerializable);
RemoveMethod (type, ".ctor", _SerializationInfo, _StreamingContext);
RemoveInterfaceMethod (type, _ISerializable, _GetObjectData, _SerializationInfo, _StreamingContext);
RemoveInterface (type, _IDeserializationCallback);
RemoveInterfaceMethod (type, _IDeserializationCallback, _OnDeserialization, "System.Object");
RemoveField (type);
}
static void RemoveField (TypeDefinition type)
{
for (int i = 0; i < type.Fields.Count; i++) {
FieldDefinition field = type.Fields [i];
if (field.FieldType.FullName == _SerializationInfo) {
type.Fields.RemoveAt (i);
break;
}
}
}
static bool ParametersMatch (IMethodSignature meth, string [] parameters)
{
for (int i = 0; i < parameters.Length; i++) {
ParameterDefinition param = meth.Parameters [i];
if (param.ParameterType.FullName != parameters [i])
return false;
}
return true;
}
static void RemoveInterfaceMethod (TypeDefinition type, string iface, string method, params string [] parameters)
{
RemoveMethod (type, method, parameters);
RemoveMethod (type, Concat (iface, method), parameters);
}
static void RemoveMethod (TypeDefinition type, string name, params string [] parameters)
{
RemoveMethod (type.Methods, name, parameters);
}
static void RemoveMethod (IList container, string name, params string [] parameters)
{
for (int i = 0; i < container.Count; i++) {
MethodDefinition method = (MethodDefinition) container [i];
if (method.Name != name)
continue;
if (method.Parameters.Count != parameters.Length)
continue;
if (!ParametersMatch (method, parameters))
continue;
container.RemoveAt (i);
return;
}
}
}
}

View File

@@ -0,0 +1,55 @@
//
// TunerAnnotations.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.Cecil;
using Mono.Linker;
namespace Mono.Tuner {
public class TunerAnnotations {
static readonly object _internalizedKey = new object ();
public static void Internalized (LinkContext context, IMetadataTokenProvider provider)
{
var annotations = context.Annotations.GetCustomAnnotations (_internalizedKey);
annotations [provider] = _internalizedKey;
}
public static bool IsInternalized (LinkContext context, IMetadataTokenProvider provider)
{
var annotations = context.Annotations.GetCustomAnnotations (_internalizedKey);
return annotations.ContainsKey (provider);
}
private TunerAnnotations ()
{
}
}
}