[tuner] Properly preserve AesCryptoServiceProvider.
authorJonathan Pryor <jonp@xamarin.com>
Thu, 13 Jun 2013 20:56:18 +0000 (16:56 -0400)
committerRadek Doulik <rodo@xamarin.com>
Wed, 21 Oct 2015 08:27:38 +0000 (10:27 +0200)
[merged by rodo from monodroid - the mentioned test is not included here]

Fixes: https://xamarin.desk.com/agent/case/35534

Commit 5ca3cb4b wasn't propertly tested (doh!).

The problem with Aes and AesCryptoServiceProvider is that there's a
cross-assembly dependency: Aes is in mscorlib, while
AesCryptoServiceProvider is in System.Core. The
PreserveCrypto.ProcessSystemCore() method didn't properly handle this
setup.

Fix the linker, and add a test to Hello.

WARNING: The test sucks. In particular, to "test" this fix you need to
run the app and then grep the `adb logcat` output for:

# DownloadDataTaskAsync complete; status=RanToCompletion; exception=

If the status is anything else, or the exception is non-null, it's
busted.

FURTHERMORE, it's only useful in Release apps, not Debug apps.
(No linker in Debug apps.)

The reason for the need to grep is that there's no sane mechanism to
wait until the Task has completed before checking the status of the
Task, and throwing an exception from within the continuation wouldn't
do anything.

FIXME: The real problem is that Task.Wait() blocks forever and never
returns. This needs further investigation.

https://bugzilla.xamarin.com/show_bug.cgi?id=12681

mcs/tools/tuner/Mono.Tuner/PreserveCrypto.cs

index 35dda5cc407bbeacd75e7e1383ba22b6ac6040b1..18dbe7ff2514016cb92f5171a38e44d75383c15c 100644 (file)
@@ -60,6 +60,13 @@ namespace Mono.Tuner {
                        AddPreserveInfo (corlib, "HMACSHA512", "SHA512Managed");
 
                        TryAddPreserveInfo (corlib, "Aes", "AesManaged");
+
+                       var corlibAes = GetCryptoType (corlib, "Aes");
+                       Preserve (corlibAes, GetCryptoType (corlib, "AesManaged"));
+
+                       AssemblyDefinition syscore;
+                       if (context.TryGetLinkedAssembly ("System.Core", out syscore))
+                               Preserve (corlibAes, GetCryptoType (syscore, "AesCryptoServiceProvider"));
                }
 
                void ProcessSystemCore (LinkContext context)
@@ -101,6 +108,8 @@ namespace Mono.Tuner {
 
                void Preserve (TypeDefinition marker, TypeDefinition implementation)
                {
+                       if (marker == null || implementation == null)
+                               return;
                        foreach (var constructor in implementation.GetConstructors ())
                                annotations.AddPreservedMethod (marker, constructor);
                }