Bug 56312 - watchOS App installs but doesn't launch when compiling with LLVM
Summary: watchOS App installs but doesn't launch when compiling with LLVM
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: Mono runtime / AOT compiler ()
Version: XI 10.10 (d15-2)
Hardware: PC Windows
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Zoltan Varga
URL: https://forums.xamarin.com/discussion...
Depends on:
Blocks:
 
Reported: 2017-05-12 18:21 UTC by brandon.rader
Modified: 2017-08-02 08:42 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Watch App and Extension Build Output (1.21 MB, text/plain)
2017-05-12 21:27 UTC, brandon.rader
Details
Watch App Install messages from device log (5.18 KB, text/plain)
2017-05-17 17:43 UTC, brandon.rader
Details
Symbolicated Crash Log (56.22 KB, text/plain)
2017-05-18 17:08 UTC, brandon.rader
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description brandon.rader 2017-05-12 18:21:38 UTC
I'm developing an app that targets watchOS 3.2. The app ran fine on a physical device when compiled for debug mode, but not for ad-hoc / TestFlight compiles, so through a process of elimination, I wanted to see what the difference between the builds was (other than debugging enabled) that caused the app not to launch. Any 

LAUNCHED - LLVM disabled, linking disabled, Thumb-2 disabled
LAUNCHED - LLVM disabled, Link SDK enabled, Thumb-2 disabled
CRASHED - LLVM enabled, linking disabled (*), Thumb-2 disabled
CRASHED - LLVM enabled, linking disabled (*), Thumb-2 enabled
CRASHED - LLVM enabled, Link SDK enabled, Thumb-2 disabled
CRASHED - LLVM enabled, Link SDK enabled, Thumb-2 enabled

Didn't try (my understanding of the checkboxes is that LLVM must be enabled for Thumb-2 to be enabled):
LLVM disabled, linking disabled, Thumb-2 enabled
LLVM disabled, Link SDK enabled, Thumb-2 enabled

You can see that as soon as I enabled LLVM, the app crashes before launch completes. I also noticed that with linking disabled, I still get linking warnings (see below), so I believe that at least some linking may be enabled automatically if LLVM is enabled. In the event that the crashes are caused by overly aggressive linking, the warnings below are not helpful in that they don't give me any guidance on what I can do to preserve the missing code. I did however test one build that had linking enabled, but not LLVM and it worked.

Warning		Native linking warning: warning: overriding the module target triple with thumbv7k-apple-watchos3.2.0 [-Woverride-module]	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: 1 warning generated.	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: warning: overriding the module target triple with thumbv7k-apple-watchos3.2.0 [-Woverride-module]	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: warning: overriding the module target triple with thumbv7k-apple-watchos3.2.0 [-Woverride-module]	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: 1 warning generated.	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: warning: overriding the module target triple with thumbv7k-apple-watchos3.2.0 [-Woverride-module]	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: 1 warning generated.	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747	
Warning		Native linking warning: 1 warning generated.	Dash.Watch.WatchOSExtension	C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets	747
Comment 1 brandon.rader 2017-05-12 18:42:39 UTC
Using XCode 8.3.2, VS for Mac 7.0, VS 2017 Pro 15.2, Xamarin.iOS 10.10.0.30
Comment 2 brandon.rader 2017-05-12 21:27:59 UTC
Created attachment 22148 [details]
Watch App and Extension Build Output

Attached the build output for the WatchApp and WatchExtension only, should be verbose...

Build Settings: 
ARMv7k
Use LLVM
Use Thumb-2
Bitcode has been enabled because this version of Xamarin.iOS does not support building watchOS projects using LLVM without enabling bitcode.
Optimize PNG Images
Comment 3 Sebastien Pouliot 2017-05-16 13:23:12 UTC
Please include the symbolicated crash report from the watch device, that will give us some information about what went wrong.

note: Enabling/disabling the Thumb-2 option does not matter for the watchOS platform
Comment 4 brandon.rader 2017-05-17 17:43:18 UTC
Created attachment 22238 [details]
Watch App Install messages from device log

Where is the crash report? I can't find anything in macOS Console when looking at my phone/watch logs. I've tried searching for my app id, "launchd", "crash"... Nothing. I can only find the install messages. I attached them just in case there is anything unusual in it (I think it also includes me deleting the app and re-installing it).
Comment 5 Rolf Bjarne Kvinge [MSFT] 2017-05-18 11:35:13 UTC
WatchOS crash reports are copied to the iPhone, and listed together with the iOS crash reports in Xcode (see https://developer.apple.com/library/content/qa/qa1747/_index.html).
Comment 6 brandon.rader 2017-05-18 17:08:31 UTC
Created attachment 22278 [details]
Symbolicated Crash Log

Thanks for the direction on finding the crash log. I guess it never occurred to me that it wasn't in Console, you can see I'm new at this...

I symbolicated it with XCode, but for some reason had to symbolicate my own code line by line using the `atos` command. I'm sure there is a better way.

It seems like it failed in my IEnumerable<T> static extension methods (I don't reference System.Core to save space, so these are LINQ replacements). Here is the code for those:

public static int Count<T>(this IEnumerable<T> source)
{
	if (source == null)
	{
		throw new ArgumentNullException(nameof(source));
	}

	int count = 0;

	foreach (var element in source)
	{
		count += 1;
	}

	return count;
}

public static T[] ToArray<T>(this IEnumerable<T> source)
{

	int count = source.Count();
	T[] array = new T[count];

	int i = 0;
	foreach (var element in source)
	{
		array[i] = element;
		i += 1;
	}

	return array;
}
Comment 7 Rolf Bjarne Kvinge [MSFT] 2017-05-18 17:46:33 UTC
So it looks like we abort here:

7   Dash.Watch.WatchOSExtension   	0x02fad7e0 0x8000 + 49960928 resolve_vcall (in Dash.Watch.WatchOSExtension) (jit-icalls.c:1644)

which is here: https://github.com/mono/mono/blob/1aa58e9a46325a94beb873bfb500f6b943021248/mono/mini/jit-icalls.c#L1644

@Brandon, we'll need a project we can use to reproduce this, could you give us access to your project? Or alternatively create a simpler test project we can use?
Comment 8 brandon.rader 2017-05-24 17:51:51 UTC
My apologies if this would've helped to fix any bugs for you but my employer would like me not to submit the code and I was unable to reproduce it in test projects (although I could very reliably reproduce it in the original project - weird). I did end up finding a work around. In some places, I used IEnumerator.MoveNext() instead of LINQ methods, and in others I used my own LINQ-like methods. I have no idea why this works (because they all worked in debug mode w/ linking enabled, just not with LLVM enabled).
Comment 9 Rolf Bjarne Kvinge [MSFT] 2017-05-24 17:55:02 UTC
@Zoltan, do you have any idea what might be causing this crash from the crash report we've got? If not, I think we can close this as not reproducible for now.
Comment 10 Zoltan Varga 2017-05-24 18:08:08 UTC
This seems fixable if we could get a testcase, without it, there are a lot of possible causes. Also, mono_error_assert_ok () is supposed to print the error message somewhere like on the ios console. So the console might have more information.
Comment 11 Manuel de la Peña [MSFT] 2017-06-27 10:18:07 UTC
As @rolf mentioned, I'm going to close the bug as not reproducible until we get a test case, once we get the test case the bug can be reopened.
Comment 12 Pauli Jokela 2017-07-29 08:06:10 UTC
Unfortunately I'm also seeing the same issue and can confirm that disabling LLVM and Bitcode for both watchOS projects seems like a feasible fix/workaround, except that Apple requires Bitcode to be enabled for watchOS apps, meaning this does need to be fixed.

In my case I've been unable to symbolicate anything useful from my crashes, apart from these few lines:

System_Core_System_Collections_Generic_LargeArrayBuilder_1_T_REF_AddRange_System_Collections_Generic_IEnumerable_1_T_REF (in Tyomaarain.watchOS.Extension) + 570
System_Core_System_Collections_Generic_EnumerableHelpers_ToArray_T_REF_System_Collections_Generic_IEnumerable_1_T_REF (in Tyomaarain.watchOS.Extension) + 330
System_Core_System_Linq_Enumerable_ToArray_TSource_REF_System_Collections_Generic_IEnumerable_1_TSource_REF (in Tyomaarain.watchOS.Extension) + 292
Newtonsoft_Json_Newtonsoft_Json_Utilities_ReflectionUtils_GetAttributes_T_REF_object_bool (in Tyomaarain.watchOS.Extension) + 302
Newtonsoft_Json_Newtonsoft_Json_Utilities_ReflectionUtils_GetAttribute_T_REF_object_bool (in Tyomaarain.watchOS.Extension) + 156
Newtonsoft_Json_Newtonsoft_Json_Serialization_JsonTypeReflector_GetAttribute_T_REF_System_Type (in Tyomaarain.watchOS.Extension) + 238
Newtonsoft_Json_Newtonsoft_Json_Serialization_JsonTypeReflector_GetAttribute_T_REF_object (in Tyomaarain.watchOS.Extension) + 222

I'll attempt to create a sample project to reproduce this, although it'll be tricky to test as it needs to run on a real watch and be a release build, meaning it'll take quite a while to deploy and install. I'll post an update here once I have an easily crashable sample project ready.
Comment 13 Rolf Bjarne Kvinge [MSFT] 2017-07-31 13:54:59 UTC
@Pauli, please open a new bug report (and mention it looks similar to this one) when you have the sample project. This makes it less confusing if the original reporter of this bug also provides a sample project one day, and the issues end up being different.
Comment 14 Pauli Jokela 2017-08-02 08:42:57 UTC
@Rolf I've successfully reproduced the issue with a minimal sample project and created a new issue here: https://bugzilla.xamarin.com/show_bug.cgi?id=58538