Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchOS extensions crash at launch with 'Failed to load AOT module 'mscorlib' while running in aot-only mode: not compiled with safepoints.' #11765

Closed
rolfbjarne opened this issue Nov 23, 2018 · 11 comments

Comments

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Nov 23, 2018

Steps to Reproduce

  1. Build & install the mono-2018-08 branch of xamarin-macios.
  2. Create new iOS app and add a watchOS App + Extension
  3. Run on a watch device.

Current Behavior

Crashes at launch with:

Failed to load AOT module 'mscorlib' while running in aot-only mode: not compiled with safepoints.

Expected Behavior

No crash

Version Used:

xamarin/xamarin-macios@74b966e

Stacktrace

(lldb) bt
* thread #1, name = 'tid_303', queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x1c6eda1c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x1c75e55a libsystem_pthread.dylib`pthread_kill + 278
    frame #2: 0x1c661dca libsystem_c.dylib`abort + 106
    frame #3: 0x0128c22e link all`mono_log_write_asl(log_domain=<unavailable>, level=<unavailable>, hdr=<unavailable>, message=<unavailable>) at mono-log-darwin.c:41 [opt]
    frame #4: 0x0129b870 link all`monoeg_g_log [inlined] monoeg_g_logstr(log_domain=0x00000000, log_level=G_LOG_LEVEL_ERROR, msg=<unavailable>) at goutput.c:117 [opt]
    frame #5: 0x0129b84c link all`monoeg_g_log [inlined] monoeg_g_logv_nofree(log_domain=0x00000000, log_level=G_LOG_LEVEL_ERROR, format=<unavailable>, args=<unavailable>) at goutput.c:128 [opt]
    frame #6: 0x0129b83a link all`monoeg_g_log [inlined] monoeg_g_logv(log_domain=0x00000000, log_level=G_LOG_LEVEL_ERROR, format=<unavailable>, args=<unavailable>) at goutput.c:135 [opt]
    frame #7: 0x0129b83a link all`monoeg_g_log(log_domain=<unavailable>, log_level=<unavailable>, format=<unavailable>) at goutput.c:144 [opt]
    frame #8: 0x01162ec0 link all`load_aot_module(assembly=<unavailable>, user_data=<unavailable>) at aot-runtime.c:2179 [opt]
    frame #9: 0x011ae14e link all`mono_assembly_load_from_predicate [inlined] mono_assembly_invoke_load_hook(ass=<unavailable>) at assembly.c:1717 [opt]
    frame #10: 0x011ae138 link all`mono_assembly_load_from_predicate(image=<unavailable>, fname=<unavailable>, asmctx=<unavailable>, predicate=0x00000000, user_data=0x00000000, status=0x029d27bc) at assembly.c:2848 [opt]
    frame #11: 0x011addf4 link all`mono_assembly_open_predicate(filename=<unavailable>, asmctx=<unavailable>, predicate=<unavailable>, user_data=<unavailable>, requesting_assembly=0x00000000, status=0x029d27bc) at assembly.c:2341 [opt]
    frame #12: 0x011af740 link all`mono_assembly_open(filename=<unavailable>, status=<unavailable>) at assembly.c:2672 [opt]
    frame #13: 0x012afd66 link all`assembly_preload_hook(aname=0x15d0e970, assemblies_path=0x15d0db70, user_data=0x00000000) at monotouch-main.m:137
    frame #14: 0x011b0660 link all`mono_assembly_load_corlib [inlined] invoke_assembly_preload_hook(aname=0x15d0e970, assemblies_path=0x15d0db70) at assembly.c:1885 [opt]
    frame #15: 0x011b0650 link all`mono_assembly_load_corlib(runtime=0x013a839c, status=0x029d30e0) at assembly.c:4046 [opt]
    frame #16: 0x011c8e40 link all`mono_init_internal(filename="MonoTouch", exe_filename=<unavailable>, runtime_version=<unavailable>) at domain.c:571 [opt]
    frame #17: 0x011883b2 link all`mini_init(filename=<unavailable>, runtime_version=<unavailable>) at mini-runtime.c:4412 [opt]
    frame #18: 0x012af93e link all`::xamarin_main(argc=1, argv=0x029d3b6c, launch_mode=XamarinLaunchModeExtension) at monotouch-main.m:420
    frame #19: 0x00306480 link all`::xamarin_watchextension_main(argc=1, argv=0x029d3b6c) at main.m:70
    frame #20: 0x1c5d3a12 libdyld.dylib`start + 2
@vargaz

This comment has been minimized.

Copy link
Member

@vargaz vargaz commented Nov 23, 2018

This usually happens when the cross compiler is not configured using the
--enable-cooperative-suspend flag.
However, the watch cross compiler seems to use this flag both on master and on 2018-08:
https://github.com/mono/mono/blob/master/sdks/builds/ios.mk#L339

@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Nov 23, 2018

@luhenry @lambdageek could that be due to disabled hybrid suspend by default?

lewurm added a commit to lewurm/mono that referenced this issue Nov 23, 2018
The crosscompiler template also picks up the flags from the device
runtime, that is:

```
ios-targetwatch_CONFIGURE_FLAGS = [...]
```

will be passed to the crosscompiler runtime as well. Therefore we had
something like this:

```console
./configure [...] --disable-cooperative-suspend --disable-hybrid-suspend --disable-crash-reporting --enable-cooperative-suspend [...]
```

with this PR it looks like this:

```console
./configure [...] --disable-crash-reporting --enable-cooperative-suspend [...]
```

Should fix: mono#11765
@spouliot

This comment has been minimized.

Copy link
Member

@spouliot spouliot commented Nov 26, 2018

@marek-safar can we get @lewurm fix into 2018-08 ?

@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Nov 26, 2018

It apparently didn't fix the issue. I am waiting on @luhenry @lambdageek to confirm what settings combination should go there

@lambdageek

This comment has been minimized.

Copy link
Member

@lambdageek lambdageek commented Nov 26, 2018

Is it possible that when we AOT mscorlib for the watch that the MONO_THREADS_SUSPEND environment variable is set (to preemptive)? That would override the cross-compiler's configure flags

@lambdageek

This comment has been minimized.

Copy link
Member

@lambdageek lambdageek commented Nov 26, 2018

Trying some things out locally, but I think this is because VSMac sets MONO_THREADS_SUSPEND=preemptive in their stub launcher - mono/monodevelop#6327

@rolfbjarne does building from the terminal create something usable?

long term - the AOT compiler has host/target confusion about safepoints, I think. But in the short term, maybe XI could override MONO_THREADS_SUSPEND when invoking the AOT compiler for watchOS?

@lambdageek

This comment has been minimized.

Copy link
Member

@lambdageek lambdageek commented Nov 26, 2018

@rolfbjarne Here's a gross hack. I'm not sure how to only do this for watchOS.
https://gist.github.com/lambdageek/c7a15fd4c0b9eb3e3619c4811ce5ea6b

I'm going to work on a --aot=safepoints=[yes|no|host] flag that will cause the AOT compiler to emit safepoints for the target either always, or never, or matching the current host behavior (the default - coinciding with today's behavior).

@vargaz

This comment has been minimized.

Copy link
Member

@vargaz vargaz commented Nov 27, 2018

We can also unset the env var or just ignore it in the aot compiler.

@rolfbjarne

This comment has been minimized.

Copy link
Member Author

@rolfbjarne rolfbjarne commented Nov 27, 2018

@rolfbjarne does building from the terminal create something usable?

Yes, building from the command-line works. I'll work around this in mtouch for now.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Nov 27, 2018
…alling the AOT compiler. Works around mono/mono#11765.

Visual Studio for Mac may set MONO_THREADS_SUSPEND, and this ends up confusing
the AOT compiler when compiling for watchOS.

So unset the environment variable before calling the AOT compiler.

Works around mono/mono#11765.
rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Nov 27, 2018
…alling the AOT compiler. Works around mono/mono#11765.

Visual Studio for Mac may set MONO_THREADS_SUSPEND, and this ends up confusing
the AOT compiler when compiling for watchOS.

So unset the environment variable before calling the AOT compiler.

Works around mono/mono#11765.
lambdageek added a commit to lambdageek/mono that referenced this issue Nov 27, 2018
Even if we're cross-compiling and the host doesn't use safepoints.

This should address
mono#11765 which, due to
mono/monodevelop#6327, was not emitting safepoints in
the watchOS cross-compiler since the host had `MONO_THREADS_SUSPEND=preemptive` set.
lambdageek added a commit to lambdageek/mono that referenced this issue Nov 28, 2018
Even if the host uses another suspend policy

This should address
mono#11765 which, due to
mono/monodevelop#6327, was not emitting safepoints in
the watchOS cross-compiler since the host had `MONO_THREADS_SUSPEND=preemptive` set.
lambdageek added a commit to lambdageek/mono that referenced this issue Nov 28, 2018
Even if the host uses another suspend policy

This should address
mono#11765 which, due to
mono/monodevelop#6327, was not emitting safepoints in
the watchOS cross-compiler since the host had `MONO_THREADS_SUSPEND=preemptive` set.
spouliot added a commit to xamarin/xamarin-macios that referenced this issue Dec 6, 2018
* Bump to mono:2018-06

* Bump mono

* Updates compression to work with the public span

* Bump mono

* Fixes pointer check logic in Deflater

* Bump mono

* Fixes pointer check logic in Deflater

* Bump mono

* Bump Mono

* [runtime] always use `mono_jit_set_aot_mode` (#4491)

`mono_jit_set_aot_only` is deprecated and accidentally broke with
mono/mono#7887

This should fix device tests with `mono-2018-06`

* Testing with Zoltan's patch

* Include libmono-system-native on Xamarin.Mac

* Bump Mono

Commit list for mono/mono:

* mono/mono@7bcda19 Bump llvm to release_60/fc854b8ec5873d294b80afa3e6cf6a88c5c48886. (#9786). (#9804)
* mono/mono@23e95ec Apply F# portable pdb debug fix for pinvokes & bump (#9797)
* mono/mono@295f6d3 [2018-06] [MacOS] On Mac, use the copyfile API to copy files (#9696)

Diff: mono/mono@7d5f4b6...7bcda19

* Revert 4bacab3, it doesn't fix the ios aot problems.

* Bump mono

* [tests] Adjust the MT0137 test for mcs change in behavior.

Starting with mono 5.16 mcs will now add assembly references when the assembly
is only used in attributes (this was already the case for csc in both 5.14 and
5.16, so it seems to be a compatibility change).

Adjust the MT0137 test accordingly.

* [msbuild] Fix parsing of json parser errors to handle trailing periods in the error message.

Fixes this test:

    1) Test Failure : Xamarin.iOS.Tasks.Bug60536.TestACToolTaskCatchesJsonException
         ColumnNumber
      Expected: 2
      But was:  0

* Bump mono

* [builds] Install the old llvm binaries into the LLVM36 directory and make the 32 bit builds use that.

* Bump mono

* Bump to mono:2018-08

* Initialize Dependency Injector.

* Fix typo

* Fix llvm build

* Reflect latest X509CertificateImpl changes

* Use same compile flags also for link

Linking can fail if the minimum versions are different

* Bump mono

* Bump mono

* Assembly.LoadFile accepts only absolute path

* Bump mono

* [jenkins] Don't give VSTS a fake branch. (#4667)

Something in VSTS changed, and now fake branch names don't work anymore.

So instead use real branch names (and for pull requests I've created a
'pull-request' branch we can use).

* Assembly.LoadFile accepts only absolute path

* [linker] Add new Facade (System.Threading.Tasks.Extensions).

Fixes these MTouch test failures:

    1. Xamarin.Linker.SdkTest.iOS_Unified :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

    2. Xamarin.Linker.SdkTest.tvOS :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

    3. Xamarin.Linker.SdkTest.watchOS :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

* [linker] Add new Facade (System.Threading.Tasks.Extensions).

Fixes these MTouch test failures:

    1. Xamarin.Linker.SdkTest.iOS_Unified :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

    2. Xamarin.Linker.SdkTest.tvOS :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

    3. Xamarin.Linker.SdkTest.watchOS :   Facades
      Expected:
      But was:  < "System.Threading.Tasks.Extensions" >

* [tests] Reference GuiUnit_Net_4_5 using a project reference.

This makes sure GuiUnit is built when the main project is built.

* [mono-sdks] Necessary changes to unify the LLVM provisioning for both iOS and Android. (#4732)

* Bump Mono

* [mtouch] add mixed-mode support (#4751)

* [mtouch] add --interp-mixed option

When enabling this option, mtouch will AOT compile `mscorlib.dll`.  At
runtime that means every method that wasn't AOT'd will be executed by
the runtime interpreter.

* [mtouch] Add support to --interpreter to list the assemblies to (not) interpret.

* [msbuild] Simplify interpreter code to use a single variable.

* Fix whitespace.

* [mtouch] Move mtouch-specific code to mtouch-specific file.

* [msbuild] An empty string is a valid value for 'Interpreter', so make it a non-required property.

* [mtouch] Add sanity check for aot-compiling interpreted assemblies.

* Bump Mono

* [linker] Updates SDKs facades list

* Bump mono

* [msbuild] Adds facades which might override default nuget version to framework list

The collision resolver task reads them from here https://github.com/dotnet/sdk/blob/master/src/Tasks/Common/ConflictResolution/FrameworkListReader.cs

* Bump mono to pick up hybrid suspend fixes

Pick up the 2018-08 backport (mono/mono#10551)
of mono/mono#10545

This should fix GC hangs when managed code runs on a GCD threadpool worker
thread.

* [builds] Fix target name in llvm36 provisioning

package-llvm-llvm36-32 isn't defined in external/mono/sdks/builds/llvm.mk,
but package-llvm36-llvm32 is.

* Revert "[builds] Fix target name in llvm36 provisioning"

This reverts commit b233837.

* Revert "Fix llvm build"

This reverts commit f668561.

* [mono-sdks] Necessary changes to unify the LLVM provisioning for both iOS and Android. (#4732)

* Bump mono

* Bump mono

* Revert "Use same compile flags also for link"

This reverts commit cf20539.

* Bump mono to pick up mono/mono@1a309a7

* [mmptest] System.Core doesn't depend on Mono.Posix in 2018-08

System.Core doesn't depend on Mono.Posix anymore since it's using the corefx
implementation of pipes now mono/mono@0f0e318

* Bump mono and minimum system mono

* [security]: Make `SecCertificate` work with the latest runtime code.

* Fix the `NATIVE_APPLE_CERTIFICATE` logic; it should only be defined when
  using `XAMARIN_APPLETLS` and not on watch.

* It is no longer allowed to construct `X509Certificate` from a native pointer,
  the `X509Certificate(IntPtr)` and `X509Certificate2(IntPtr)` constructors now
  throw an exception.  Use `X509CertificateImplAppl` directly instead.

* Bump mono

* Bump VSmac min version to 7.7.0.1373

To pick up the fix for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/658916/
Should fix the XM classic build failures

* Revert "Bump VSmac min version to 7.7.0.1373"

This reverts commit b2686bb.

* Bump to a VSfM version that can build XM Classic projects.

* Bump mono system dependency

* Bump mono

Pick up mono/mono@1644a1a - fix for mono/mono#10743

* Bump mono

* Bump mono

* [monotouch-test] Disable X509Certificate(byte[]) tests on watchOS (#4942)

* [monotouch-test] Disable X509Certificate(byte[]) tests on watchOS

* [tests] Add TestRuntime.AssertNotWatchOS()

* fixup WatchOS build

* Bump mono

* Bump mono

* [tests] Disable link-preserve-calendar-1 until we can upgrade it to be a Unified test.

See #4596 (comment)
for reference: mono's desktop API changed, the linker behavior the test is
verifying is only expected when using XM's Mobile profile.

* Bump mono

* Revert "[monotouch-test] Disable X509Certificate(byte[]) tests on watchOS (#4942)"

This reverts commit d003a9b.

* Bump Mono.

* [security]: `NATIVE_APPLE_CERTIFICATE` should now be defined on watchOS as well.

* Mono 2018-08 requires macOS 10.9+, so Xamarin.Mac must as well.

* Bump min mono version for XM system apps.

Using a system mono < 5.18 results in a TypeLoadException:

    Could not resolve type with token 01000032 from typeref (expected class 'Mono.ISystemDependencyProvider' in assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

* Bump guiunit to get updated min macOS version.

Commit list for mono/guiunit:

* mono/guiunit@9f67042 Bump min macOS version to 10.9.
* mono/guiunit@0c3159a [Harness] Fix exit code of 0 being reported in case of exceptions in the harness
* mono/guiunit@9b7497c Merge pull request #15 from mono/fix-more-warnings
* mono/guiunit@a264470 Fix more warnings
* mono/guiunit@dd094e7 Merge pull request #14 from mono/fix-warnings
* mono/guiunit@b3afede Fix build warnings

Diff: mono/guiunit@1306b0d...9f67042

* [tests] More min macOS version setting to 10.9.

* Remove 10.7 & 10.8 availability attributes, since they're redundant now.

* Bump mono

* [2018-08][watchos] Use mono_dangerous_add_raw_internal_call for watchOS icalls (#5030)

* Add optional mono_dangerous_add_raw_internal_call to exports.t4

* Use mono_dangerous_add_raw_internal_call on watchOS for icall registration

Internal calls added with mono_dangerous_add_raw_internal_call run in GC Unsafe
mode under cooperative and hybrid suspend, whereas internal calls added with
mono_add_internal_call run in GC Safe mode since
mono/mono@5756ba4 in order for hybrid suspend
to be a transparent replacement for preemptive suspend (the old default).  The
icalls in GC Unsafe mode have a responsibility not to block indefinitely
without manually performing a thread state transition to GC Safe mode, and in
return they avoid a thread state transition when the icall is invoked from a
managed method.

* [mmptest] Less hardcoding.

* Bump minimum mono one that has 'mono_dangerous_add_raw_internal_call'.

* Bump mono

* Bump system mono dependency

* Fixes building mono tests

* [ImageCaptureCore] Remove redundant availability attribute.

* [mtouch] Clear the MONO_THREADS_SUSPEND environment variable before calling the AOT compiler. Works around mono/mono#11765.

Visual Studio for Mac may set MONO_THREADS_SUSPEND, and this ends up confusing
the AOT compiler when compiling for watchOS.

So unset the environment variable before calling the AOT compiler.

Works around mono/mono#11765.
lambdageek added a commit to lambdageek/mono that referenced this issue Dec 18, 2018
lambdageek added a commit to lambdageek/mono that referenced this issue Dec 19, 2018
lambdageek added a commit that referenced this issue Dec 27, 2018
This addresses #11765
@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Jan 3, 2019

@lambdageek can this be closed?

@lambdageek

This comment has been minimized.

Copy link
Member

@lambdageek lambdageek commented Jan 3, 2019

Yes. xamarin-macios has a workaround xamarin/xamarin-macios@428310c and mono master was changed (d1a5fa3) to always emit safepoints.

@lambdageek lambdageek closed this Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.